Auto-scoll/pan in OxyPlot real-time data series plotting

rex picture rex · Feb 10, 2014 · Viewed 8.4k times · Source

I am using OxyPlot in a C# winforms app. My axese are LinearAxis type.

I am trying to plot some real-time data which i have managed to do by adding points to my series and refreshing the plot as data becomes available. However, I am having trouble figuring out how to make the plot move to the right with the time series.

Each time series data point has an X value incremented by (int) 1 and I have tried to get the auto scrolling to happen using .Pan() like so:

xAxis.Pan(-1);

Obviously this hasn't worked since I am assuming the method takes pixel inputs or something and consequently the panning is much slower than the data incrementation.

I have also tried replacing -1 with -MajorTIckSize and -MajorStepSize with no luck as these are generally too small of a move.

My question is, how can i determine the delta i need to be using to pan with the real-data? I am assuming this will depend on the zoom level and obviously it would be nice if it would continue to work as I zoomed in and out.I imagine the solution involves some sort of function that relies on the pixel width of the tick interval or something but I can't figure it out.

PS: I've asked this question on OxyPlot discussion page as well

Thanks,

Armen

Answer

rex picture rex · Feb 12, 2014

Thanks to decatf for posting an answer to my question here and said:

The Transform function in the Axis class will convert data coordinates to screen coordinates. There is an InverseTransform to do the opposite.

So you could try:

double panStep = xAxis.Transform(-1 + xAxis.Offset);
xAxis.Pan(panStep); 

There is some offset from the axis zero position (I think?) so we need to account for that in the transform to get a unit step.