Scale on LinearAxes is always 0 for WPF

Jul 24, 2012 at 2:33 AM

Hi,

I have an image and an OxyPlot chart which are inside a canvas.  I want to set the position of the image based on the two variables I have, XAxisHostValue and YAxisHostValue.  I noticed the Scale property on the linear axes, however no matter what they are always zero.  Is there another way to convert the coordinates in my canvas (which is the same size as the chart) to plot coordinates?  Thanks

 

double xScale = PlotModel.Axes[0].Scale;
double yScale = PlotModel.Axes[1].Scale;

mDragCG.SetValue( Canvas.LeftProperty, xScale * XAxisHostValue);
mDragCG.SetValue( Canvas.TopProperty, yScale * YAxisHostValue);

Jul 26, 2012 at 3:07 PM

The scale is only set after the element is loaded, so if you set these variables in your constructor it won't work.

Fortunately you can use the InverseTransform function of an axis to convert from a datapoint to a screenpoint. The Transform function does the opposite.

Coordinator
Aug 8, 2012 at 11:08 PM

Yes, the scale is not set before the plot has been rendered (it depends on the size of the control, and the contents of the plot model).

Use the Transform functions to transform from 'data' points to 'screen' points.