【问题标题】:DynamicDataDisplay ChartPlotter scroll horizontal axisDynamicDataDisplay ChartPlotter 滚动横轴
【发布时间】:2012-11-24 22:02:59
【问题描述】:

由于缺乏文档,我对这个库仍然很粗糙。

我有一个 ChartPlotter 对象,它通过从设备捕获数据来实时显示数据。 每次我有来自设备的新数据时,都会调用以下事件:

    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]);
                }));
    }

使用 ChartPlotter 的标准设置,图表将自动适应窗口。 我想让水平轴自动向左滚动,仅显示最后 10 秒(例如)的捕获。有没有办法做到这一点?

谢谢

【问题讨论】:

    标签: wpf charts dynamic-data-display


    【解决方案1】:

    为此,您必须修改 plotter.ViewPort.Visible 属性。此属性采用您使用值构造的 DataRect 对象以形成一个矩形。每次您收到一条新数据时,您都必须重新计算此矩形,以便您的图表可以滚动查看。

    这里是一个构造 DataRect 的例子:

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

    您的最小值和最大值将取决于轴上的数据类型。

    【讨论】:

      猜你喜欢
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      相关资源
      最近更新 更多