SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

0
0

Hi,
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?
Thanks,
Dewey

Version
3.1
  • Dewey Brooks
    Update: I have more than one moving average plotted and I’m trying to get the pixel coordinates for each MA. This seems to be returning the same coordinates for each different MA. I think I’m missing something here.private void UpdateMaPixelCoordinate(IXyDataSeries ChartSeriesMovAvg, MovingAverage movingAverage) { //get pixel coordinate values var xCalc = ChartSeriesMovAvg.ParentSurface.XAxis.GetCurrentCoordinateCalculator(); var yCalc = ChartSeriesMovAvg.ParentSurface.YAxis.GetCurrentCoordinateCalculator();movingAverage.xPixelCoordinate = xCalc.GetCoordinate(ChartSeriesMovAvg.XValues[ChartSeriesMovAvg.XValues.Count]); movingAverage.yPixelCoordinate = yCalc.GetCoordinate(ChartSeriesMovAvg.YValues[ChartSeriesMovAvg.YValues.Count]); }
  • Dewey Brooks
    update: I’m using SciStockChart and here is what I’m seeing.this seems to be working correctly for the y axis. var yCalc = ChartSeriesMovAvg.ParentSurface.YAxis.GetCurrentCoordinateCalculator(); var y = yCalc.GetCoordinate(ChartSeriesMovAvg.YValues.Last()); movingAverage.yPixelCoordinate.Add(y);this is not working for the x axis var xCalc = ChartSeriesMovAvg.ParentSurface.XAxis.GetCurrentCoordinateCalculator(); var x = xCalc.GetCoordinate(ChartSeriesMovAvg.XValues.Last()); movingAverage.xPixelCoordinate.Add(x);the ChartSeriesMovAvg.ParentSurface.XAxis.GetCurrentCoordinateCalculator() is returning a coordinatecalculater of type Abt.Controls.SciChart.Numerics.CoordinateCalculators.FlippedDoubleCoordinateCalculator even thoughI’m using SciStockChart and my x axis is a DateTime type.any ideas?thanks, Dewey
  • You must to post comments
0
0

Hi Dewey,

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

For CategoryDateTimeAxis

// 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!

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.