1
votes

I have successfully implemented a number of series on a multiple chart areas which all scroll together quite nicely when zoomed in.

When the data is first presented the min and max X values (date/time) are determined by the data I have extracted from SQL. The user though has the option of zooming into the graph, at which point the horizontal scroll bar appears. So far so good.

What I would like to achieve though is to have two text controls somewhere on my WinForm which would display the Min and Max X value currently being viewed, as the user moves the horizontal scroll bar left or right, these values should automatically update.

Which properties and methods should I be looking at?

Thanks, KH

1

1 Answers

0
votes

You could use the AxisViewChanged event and check the series points that are inside the visible range. Here's an example of what I mean:

void chart1_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e)
{
    var left = e.ChartArea.CursorX.SelectionStart;
    var right = e.ChartArea.CursorX.SelectionEnd;
    var top = e.ChartArea.CursorY.SelectionStart;
    var bottom = e.ChartArea.CursorY.SelectionEnd;

    foreach (var series in this.chart1.Series)
    {
        if (series.ChartArea == e.ChartArea.Name)
        {
            var pointsInRange = series.Points.Where(p => p.XValue <= right && p.XValue >= left &&
                                                            p.YValues[0] <= top && p.YValues[0] >= bottom);
            if (pointsInRange.Any())
            {
                var minY = pointsInRange.Min(p => p.YValues[0]);
                var maxY = pointsInRange.Max(p => p.YValues[0]);

                // print the points in your textbox
                textBox1.AppendText("Series: " + series.Name + " min visible Y=" + minY + " max visibleY=" + maxY + Environment.NewLine);
            }
        }
    }
}