Chart - potatoscript/csharp GitHub Wiki

home

Basic
■ Balloon Tooltip tooltip.IsBalloon = true;
Get Series Name on mouse move
Get Y-Axis Value
Reset AxisX ScaleView Position
Show x and y coordinate on chart

home

Basic

   using System.Windows.Forms.DataVisualization.Charting;
   public partial class MyGraph
   {
      public List<double> ymax { get; set;}
      public MyGraph(string parent)
      {
         Index _ = (Index)Application.OpenForms[parent];
         GraphModel d = new GraphModel(_.id,_.date,_.name); //database model class

         _.Chart1.Series.Clear();
         _.Chart1.Series.Add("mySeries1");
         _.Chart1.Series["mySeries1"].IsValueShowAsLabel = true;
         _.Chart1.Series["mySeries1"].Color = Color.PaleTurquoise;

         Series S1 = _.Chart1.Series[0];
         S1.IsValueShownAsLabel = true;
         S1.Color = Color.PaleTurquoise;
         S1.Font = new Font("Arial", 12, FontStyle.Bold);
         S1.LabelFormat = "#,###";
         S1.SmartLabelStyle.Enabled = false; //to make the LabelAngle changable
         S1.LabelAngle = -90;
         
         ChartArea CA = _.Chart1.ChartAreas[0];
         CA.AxisX.LabelStyle.Font = new Font("Arial", 12);
         CA.AxisY.LabelStyle.FOnt = new FOnt("Arial", 12);
 
         ymax = new List<double>();
         var k=0;
         foreach(string s in d.inputqty)
         {
            if(s.Trim()!="")
            {
               ymax.Add(double.Parse(d.inputqty[k]));
               S1.Points.AddXY( d.inputdate[k] , d.inputqty[k] );
               S1.Points[k].ToolTip = S1.Points[k].YValues[0].ToString("#,###");
               var a = S1.Points[K].YValues[0];
               if(a>10000)
               {
                 S1.Points[k].Color=Color.Chartreuse;
               }
               k++;
            }
         }

         CA.AxisY.LabelStyle.Format = "{0:0,}K";
         CA.AxisX.LabelStyle.Angle = -90;

         try
         {
             CA.AxisY.Maximum = ymax.Max()*1.1;
         }
         catch(Exception){}

      }
   }

home

Series-Name

  • Get the series name on mouse move
   private void Chart1_MouseMove(object sender, MouseEventArgs e)
   {
       HitTestResult result = Chart1.HitTest(e.X, e.Y);
       if(result.ChartElementType == ChartElementType.DataPoint)
       {
          //// something wrong????
          result.Series.Name = Chart1.Series[0].Points[result.PointIndex].AxisLabel;
       }
   }

home

Y-Axis-Value

   private void Chart1_MouseDown(object sender, MouseEventArgs e)
   {
       HitTestResult result = Chart1.HitTest(e.X, e.Y);
       if(result.ChartElementType == ChartElementType.DataPoint)
       {
          var selectedValue = Chart1.Series[0].Points[result.PointIndex].YValues[0];
       }
   }

home

AxisX-ScaleView-Position

   c.chartarea.AxisX.ScaleView.Zoom(0,db.data[0].Count);
   if(db.data[0].Count > 20)
   {
      c.chartarea.AxisX.ScaleView.Zoom(0,20);
   }
   c.chartarea.AxisX.ScaleView.Position = c.chartarea.AxisX.Minimum;

home

Show-xy-coordinate

ToolTip tooltip = new ToolTip();
Point? prevPosition = null;
private void chart1.MouseMove(object sender, mouseEventArgs e)
{
   var pos = e.Location;
   if(prevPosition.HasValue && pos == prevPosition.value)
   {
      return;
   }
   tooltip.RemoveAll();
   prevPosition = pos;
   var results = chart1.HitTest(pos.X, pos.Y, false, chartElementType.PlottingArea);
   foreach(var result in resuls)
   {
      if(result.ChartElementType==ChartElementType.PlotingArea)
      {
         var xVal = result.ChartArea.AxisX.PixelPositionToValue(pos.X);
         var yVal = result.ChartArea.AxisY.PixelPositionToValue(pos.Y);
         tooltip.Show("X = "+xVal+", Y = "+yVal, this.chart1, pos.X, pos.Y-15);
      }
   }
}
⚠️ **GitHub.com Fallback** ⚠️