SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components
We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!
I’m calculating a moving average and adding it to my chart as a data series. I would like to capture the x and y pixel coordinates of the plot when the moving average is updated so I can store this for later use. My moving average data series is an IXyDataSeries<DateTime, double>; Can you show an example of how to capture the X and Y pixel coordinate for each plotted Y value both on creation and on update?
To do this, you need to use the APi described in the article Axis APIs – Convert Pixel to Data Coordinates
In your case, the Date is converted to X-Pixel as follows
// Get coordinate from CategoryDateTimeAxis CategoryDateTimeAxis catAxis = new CategoryDateTimeAxis(); ICategoryCoordinateCalculator coordCalc = catAxis.GetCurrentCoordinateCalculator() as ICategoryCoordinateCalculator; int index = coordCalc.TransformDataToIndex(new DateTime(2015, 01, 01)); double pixelCoord = coordCalc.GetCoordinate(index);
And the Y-value is converted to Y-pixel as follows:
// Get coordinate from a NumericAxis NumericAxis numericAxis = new NumericAxis(); var coordCalc = numericAxis.GetCurrentCoordinateCalculator(); // GetCoordinate expects a double value. You can cast to double if your data is integer double pixelCoord = coordCalc.GetCoordinate(1.23d);
Note that pixel coords are calculated based on the current drawn chart, so if you update data, but convert to pixels before the chart updates then the values can be out of date.
Always force a redraw by calling sciChartSurface.InvalidateElement() and wait for the sciChartSurface.Rendered event to fire before performing these calculations after updating data.
Let me know if this helps!
Please login first to submit.