C # chart, showing nodes and data when moving the mouse over a series (pending update)

Source: Internet
Author: User

First, effect and thinking

Effect:

Solutions 1

With the chart MouseMove time, real-time tracking the position of the nearest x axis of the mouse, and then set the Cursorx to that position, let the user know I was the value of the selected X, while using the ToolTip to display all the Y values on the x axis, the knot paste thank you.

As for how to show the data node of the series that the mouse moves to, it can be judged by a hit test when Mousmove.

Reference code, hit the test to get the index of the point-of-base:

if (E.hittestresult.chartelementtype = = chartelementtype.datapoint) {    int i = E.hittestresult.pointindex;    Datapoint DP = e.hittestresult.series.points[i];    E.text = string. Format ("{1:F3}", DP. XValue, DP. Yvalues[0]);}

Solutions 2

The VS chart control is used. My chart on the page is written in this way to show the ToolTip (Chart1 is the name of my chart)
Chart1. GetToolTipText + = new eventhandler<tooltipeventargs> (chart_gettooltiptext);
void Chart_gettooltiptext (object sender, Tooltipeventargs e)
{
if (E.hittestresult.chartelementtype = = Chartelementtype.datapoint)
{
int i = E.hittestresult.pointindex;
Datapoint DP = e.hittestresult.series.points[i];
E.text = string. Format ("{1:F3}", DP. XValue, DP. Yvalues[0]);
}
}
But this mouse hover judgment range is also good narrow good narrow good narrow, choose a point to choose a half day, the mouse to shake to go can not appear tooltip, this is no way to use. Ask the Master there is no good way to let the graphics can tolerate a certain deviation, that is, even if not selected to this point, to this point near how many areas can also appear tooltip
Ideas:
1, remember that there is a software, when your mouse to move to the near you need guidance, it will be "magnetic" to where to go, you can also, pick the recent suction past.
2, if you develop the analysis software, and the precision requirements are high, it is recommended to use a bold amplification method, click on the "punctuation" and then shrink back.

Reference

#VALX//x Axis Data
#VALY//y Axis Data
#PERCENT//Percentage
#AVG//Average
#INDEX//Index value
#MAX//Maximum value
#MIN//Minimum value
#TOTAL//Total
#LEGENDTEXT//Display the text of the legend
#SER//Show series name

Ii. examples of references

The Chartcontrol.runtimehittesting property must be set to true.

The visible of the line Series markers must be true. Calchitinfo's seriespoint has been null, and finally ran to DevExpress Support Center to ask. My dev version is 13.1.5, and the way to set properties is series->view->markervisibility. Some versions may be Visible in series---linemarkeroptions.

I'm taking the graph spline as an example, here's the code.

1. Mouse click Point Pop-up MessageBox

    private void Chartcontrol4_mouseclick (object sender, MouseEventArgs e)      {          Charthitinfo hitinfo = Chartcontrol4.calchitinfo (e.location);          if (hitinfo.seriespoint! = null)          {              MessageBox.Show (hitinfo.seriespoint.values[0]. ToString ());          }      }  



2. Mouse movement with Tooltipcontroller display value

Outside definition

Tooltipcontroller Tooltipcontroller = new Tooltipcontroller ();

The following is the dev Source:

    Private voidChartcontrol4_mousemove (Objectsender, MouseEventArgs e) {Charthitinfo Hitinfo=Chartcontrol4.calchitinfo (e.location); StringBuilder Builder=NewStringBuilder (); if(Hitinfo.indiagram) builder. Appendline ("In diagram"); if(Hitinfo.innondefaultpane) builder. Appendline ("In non-default pane:"+hitInfo.NonDefaultPane.Name); if(Hitinfo.inaxis) {Builder. Appendline ("In axis:"+hitInfo.Axis.Name); if(Hitinfo.axislabelitem! =NULL) Builder. Appendline ("Label Item:"+hitInfo.AxisLabelItem.Text); if(Hitinfo.axistitle! =NULL) Builder. Appendline ("Axis Title:"+hitInfo.AxisTitle.Text); }          if(hitinfo.incharttitle) builder. Appendline ("In Chart title:"+hitInfo.ChartTitle.Text); if(hitinfo.inlegend) builder. Appendline ("In legend"); if(hitinfo.inseries) builder. Appendline ("In series:"+(Series) hitinfo.series).          Name); if(Hitinfo.inserieslabel) {Builder. Appendline ("In series label"); Builder. Appendline ("Series:"+(Series) hitinfo.series).          Name); }          if(Hitinfo.seriespoint! =NULL) {Builder. Appendline ("Argument:"+hitInfo.SeriesPoint.Argument); if(!hitInfo.SeriesPoint.IsEmpty) Builder. Appendline ("Value:"+ hitinfo.seriespoint.values[0]); }          if(Builder. Length >0) Tooltipcontroller.showhint ("hit-testing results:\n"+Builder.          ToString (), Chartcontrol4.pointtoscreen (e.location)); ElseTooltipcontroller.hidehint (); }  
View Code

MouseLeave event code

    private void Chartcontrol4_mouseleave (object sender, EventArgs e)      {          tooltipcontroller.hidehint ();      }  



3. Another way of moving the mouse to display information, using the Customdrawcrosshair event, learn from others. This can also display pictures.

    private void Chartcontrol4_customdrawcrosshair (object sender, Customdrawcrosshaireventargs e)      {                foreach ( crosshairelement element in e.crosshairelements)          {              Seriespoint point = element. Seriespoint;              Element. Labelelement.markerimage = Image.FromFile (@ "F:\Resources\Add.png");//Set Picture path              element. Labelelement.markerimagesizemode = Chartimagesizemode.stretch;              Element. Labelelement.markersize = new Size (100, 100); Size              element. Labelelement.text = point. Values[0]. ToString ();//Display the text to display          }      }  


Here are the Demohow to:show a Tooltip with a Series of point ' s data using the Customdrawcrosshair event to display the DevExpress information

Reference

1.hustaiyaya, WinForm The chart control displays the Y value on the mouse hover .

2. Huangdaxian son, c#-devexpress Chartcontrol Mouse click on the point event on chart, mouse movement display value, 2014-3.

3. A small hint that appears on the data point of the C # chart mouse.

C # chart, showing nodes and data when moving the mouse over a series (pending update)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.