Maurizio Macagno
Maurizio Macagno

Reputation: 760

DynamicDataDisplay ChartPlotter scroll horizontal axis

I am still pretty rough on this library given the lack of documentation.

I have a ChartPlotter object which is showing data in real-time as it's captured through capture of data from a device. I have the following event that is invoked every time I have new data coming from the device:

    private void OnRawDataChanged(object sender, RawDataChangedEventArgs e)
    {
        System.Diagnostics.Debugger.Log(0, "event", "event received from data manager\n");
        System.Diagnostics.Debugger.Log(0, "event", e.NewRawDataSet.Length + " tuples of data returned\n");

        var batchSize = e.NewRawDataSet.Length;

        // Expected tuples of 2 values + 2 threshold values
        Point[][] points = new Point[4][];

        for (int i = 0; i < 4; i++)
        {
            points[i] = new Point[batchSize];
        }

        double period = 1.0 / Properties.Settings.Default.SamplingRate;

        for (int i = 0; i < batchSize; i++)
        {
            // Time is expressed in milliseconds
            double t = e.NewRawDataSet[i].Time / 1000.0;

            points[0][i] = new Point(t, e.NewRawDataSet[i].Sensors[0]);
            points[1][i] = new Point(t, e.NewRawDataSet[i].Sensors[1]);
            points[2][i] = new Point(t, parentForm.PressureHisteresysOpen);
            points[3][i] = new Point(t, parentForm.PressureHisteresysClose);
        }

        plotter.Dispatcher.Invoke(DispatcherPriority.Normal,
            new Action(() =>
                {
                    sensor0.AppendMany(points[0]);
                    sensor1.AppendMany(points[1]);
                    pressureOpen.AppendMany(points[2]);
                    pressureClose.AppendMany(points[3]);
                }));
    }

With the standard settings of the ChartPlotter, the graph will auto-fit in the window. I would like to have the horizontal axis automatically scroll left showing only the last 10 seconds (for example) of capture. Is there a way to achieve this?

Thanks

Upvotes: 1

Views: 1911

Answers (1)

Jason Higgins
Jason Higgins

Reputation: 1526

To achieve this you have to modify the plotter.ViewPort.Visible property. This property takes a DataRect object that you construct with values to form a rectangle. Everytime you recieve a new piece of data, you would have to recalculate this rectangle so that your graph will scroll to view.

Here is an example of constructing a DataRect :

        double yMin = 1;
        double yMax = 10;
        double xMin = 1;
        double xMax = 10;
        plotter.ViewPort.Visible = new DataRect(xMin, yMin, xMax - xMin, yMax - yMin); 

Your mins and maxs will be based on the type of data on your axis.

Upvotes: 2

Related Questions