Auto-scroll/pan for real-time data

Feb 10, 2014 at 8:11 PM
Edited Feb 10, 2014 at 8:24 PM
Hi before I ask the question I just want to say that I really like OxyPlot! Well done and keep up the great work!

Now down to businessI 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.

Thanks,

Armen
Feb 11, 2014 at 5:06 PM
Edited Feb 11, 2014 at 5:07 PM
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.
Feb 12, 2014 at 12:31 PM
Thanks decatf, this works perfectly.
Armen
Mar 17, 2014 at 4:14 PM
Hi,

I am also currently using Oxyplot to display real time data too.. The plot data are coming from serial port per 100 ms.

The auto-pan method suggested above does work but I'm not able to sync panning and plotting speed.

Plotted line appear to accelerate (or the perhaps it's the panning speed that decelerate) and eventually the line end point will be gone from the plot screen. (i.e Panning speed lags behind)

Any pointer?

Thanks in advance.
Aug 26, 2015 at 1:31 PM
Here's how I did it - this code is used when a new datapoint is added:
const int DefaultChartSpanInSeconds = 5;
var xAxis = _plotModel.Axes.First();
var currentMax = xAxis.DataMaximum;
var now = DateTime.Now;
var nowAsDouble = DateTimeAxis.ToDouble(now);

if (!_plottingStarted)
{
    xAxis.Maximum = DateTimeAxis.ToDouble(now.Add(TimeSpan.FromSeconds(DefaultChartSpanInSeconds)));
    _plottingStarted = true;
}

var pan = (nowAsDouble > xAxis.Maximum)
points.Add(new DataPoint(nowAsDouble, value));

if (pan)
{
    var step = (nowAsDouble - currentMax) * xAxis.Scale;
    xAxis.Pan(-step );
}

_plotModel.InvalidatePlot(true);