Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make the cursor lines to follow the mouse in charts using C#

enter image description here

The picture below shows a chart in my project. As you can see there are two dotted crossing lines. I’m asked to make it to follow the mouse, but now only if I click on the chart it moves. I tried to use CursorPositionChanging but it didn’t work. CursorEventHandler also is not shown in the command below:

 this.chart1.CursorPositionChanging += new System.Windows.Forms.DataVisualization.Charting.Chart.CursorEventHandler(this.chart1_CursorPositionChanging);

do we need to add extra lib for that? So I have two problems now: 1. Make the lines to follow the mouse 2. Missing CursorEventHandler

the project is window form application with C#

like image 749
Daniel Avatar asked Dec 09 '11 03:12

Daniel


2 Answers

private void chData_MouseMove(object sender, MouseEventArgs e)
{
    Point mousePoint = new Point(e.X, e.Y);

    Chart.ChartAreas[0].CursorX.SetCursorPixelPosition(mousePoint, true);
    Chart.ChartAreas[0].CursorY.SetCursorPixelPosition(mousePoint, true);

    // ...
}
like image 167
Raghu Avatar answered Sep 21 '22 12:09

Raghu


The chart supports a 'MouseMove' event which is fired each time the mouse is moved inside the chart. The MouseEventArgs contain the position of the mouse so u can move the dotted lines based on that data each time the event fires.

like image 30
kev Avatar answered Sep 21 '22 12:09

kev