.NET Framework Bookmark and Share   
 index > Chart Controls for .NET Framework > Reading Y values at cursor position
 

Reading Y values at cursor position

My application has a fastline chart with three data series which have common X axis point values.

I want to use a cursor which the user will move around the chart and then display (in textboxes) the Y values from the 3 data series at the cursor position.

I can setup the cursor as per the code in the chart samples application and from the CursorPositionChanged event I can then read the X-axis value showing where the cursor is.

However, to lookup the Y values I really want to know the data point index of the cursor - is there a way to obtain this directly?

If not the only way I can see to achieve what I want is to work through the whole data set looking for the x value which matches the cursor X position.
Astrospider

If you know mouse cursor location in pixels you can use chart.HitTest(x,y) method to find chart element directly under this coordinate. You can also use Axis.PixelPositionToValue method to convert pixels to axis scale value. As soon as you know axis scale value you can find chart element closet to the position.

Alex.


http://blogs.msdn.com/alexgor
Alex Gorev

If you know mouse cursor location in pixels you can use chart.HitTest(x,y) method to find chart element directly under this coordinate. You can also use Axis.PixelPositionToValue method to convert pixels to axis scale value. As soon as you know axis scale value you can find chart element closet to the position.

Alex.


http://blogs.msdn.com/alexgor
Alex Gorev

Hi! Astrospider.

I can write English just little.

Because I am Korean.

I have a same problem. so I solved this.

You rememberthis keyword "FindByValue".

You havesome question, send me mail... anysolution@korea.com

My Source is under ...

Good Luck.

안녕�...

private void Chart1_CursorPositionChanged(object sender, CursorEventArgs e)
{
SetPosition(e.Axis, e.NewPosition);
}

private void Chart1_CursorPositionChanging(object sender, CursorEventArgs e)
{
SetPosition(e.Axis, e.NewPosition);
}

private DataPoint dataPoint = null;

// Set Cursor Position to Edit control.
private void SetPosition(Axis axis, double position)
{
if (double.IsNaN(position))
return;

if (axis.AxisName == AxisName.X)
{
// Convert Double to DateTime.
DateTime dateTimeX = DateTime.FromOADate(position);

// Set X cursor position to edit Control
CursorX.Text = dateTimeX.ToString("yyyy-MM-dd HH:mm");

DateTime dateTimeX1 = new DateTime(dateTimeX.Year, dateTimeX.Month, dateTimeX.Day, dateTimeX.Hour, dateTimeX.Minute, 0);

dataPoint = Chart1.Series["Series1"].Points.FindByValue(dateTimeX1.ToOADate(), "X");

if (dataPoint != null)
{
CursorY.Text = dataPoint.YValues[0].ToString("0.0");
}
else
{
CursorY.Text = "0.0";
}
}
}

terius

You can use google to search for other answers

Custom Search

More Threads

• Chart Controls Can't Display in iframe tag (different Domain)
• why Chart control not showing all points labels on x-axis
• Printing
• Can you anchor the background image for zooming
• How do I use the Chart Control Samples With Visua Basic Express
• ImageLocation - Networkshare
• Stacked bar label text?
• outlook warning
• Integers grouping
• Hyperlink (ImageMap?) for Legend items