c# - finding the value of the points in a chart -


i have made chart on form.

i want user see value, x_value , y_value of each part in balloon clicking on part.

the ballon shoud disappear when user moves mouse.

how can that?

you this:

    tooltip tooltip = new tooltip();     point? clickposition = null;      void chart1_mousemove(object sender, mouseeventargs e)     {         if (clickposition.hasvalue && e.location != clickposition)         {             tooltip.removeall();             clickposition = null;         }     }      void chart1_mouseclick(object sender, mouseeventargs e)     {         var pos = e.location;         clickposition = pos;         var results = chart1.hittest(pos.x, pos.y, false,                                      chartelementtype.plottingarea);         foreach (var result in results)         {             if (result.chartelementtype == chartelementtype.plottingarea)             {                 var xval = result.chartarea.axisx.pixelpositiontovalue(pos.x);                 var yval = result.chartarea.axisy.pixelpositiontovalue(pos.y);                  tooltip.show("x=" + xval + ", y=" + yval,                               this.chart1, e.location.x,e.location.y - 15);             }         }     } 

result:

enter image description here

edit :

to show tooltip whenever mouse move, can use following code:

point? prevposition = null; tooltip tooltip = new tooltip();  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 results)     {         if (result.chartelementtype == chartelementtype.plottingarea)         {             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);         }     } } 

note shows tooltip on position of chart. if want show when mouse near series point, can use mschart functionality e.g. :

yourseries.tooltip = "x=#valx, y=#valy"; 

(further examples here)


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -