简体   繁体   中英

Get points on a zoomed view on MS Chart

I'm using Microsoft Chart controls and allowing user selection. I want to be able to get the data points of the current zoomed (viewed) area once the user selects an area to zoom. Any ideas on how can this be done? I'm using .Net 4.5.

Here is an example that sends the currently visible DataPoints to the Console output:

// two shortcuts
ChartArea CA = chart1.ChartAreas[0];
Series S = chart1.Series[0];

// these are the X-Values of the zoomed portion:
double min = CA.AxisX.ScaleView.ViewMinimum;
double max = CA.AxisX.ScaleView.ViewMaximum;

// these are the respective DataPoints:
    DataPoint pt0 = S.Points.Select(x => x)
                     .Where(x => x.XValue >= min)
                     .DefaultIfEmpty(S.Points.First()).First();
    DataPoint pt1 = S.Points.Select(x => x)
                     .Where(x => x.XValue <= max)
                     .DefaultIfEmpty(S.Points.Last()).Last();

// test output:
for (int i = S.Points.IndexOf(pt0); i < S.Points.IndexOf(pt1); i++)
    Console.WriteLine(i + " :  " + S.Points[i]);

You can put this in the SelectionRangeChanged event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM