使用动态数据显示绘制折线图?

draw Broken line graph using dynamic data display?

我可以使用动态数据显示绘制折线图吗?

在我的应用程序中,我需要绘制实时 voltage/time graph.My requirement 是,只有当电压不是 0 时,我才应该绘制图形线。

我怎样才能做到这一点?

我尝试了以下方法:

public partial class MainWindow : Window
    {
        public ObservableDataSource<Point> source1 = null;
        public ObservableDataSource<Point> source2 = null;
        public ObservableDataSource<Point> source3 = null;
        public ObservableDataSource<Point> source4 = null;
        public ObservableDataSource<Point> source5 = null;
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {        
            source1 = new ObservableDataSource<Point>();
            source2 = new ObservableDataSource<Point>();
            source3 = new ObservableDataSource<Point>();
            source4 = new ObservableDataSource<Point>();
            source5 = new ObservableDataSource<Point>();
            source1.SetXYMapping(p => p);

            testchart.AddLineGraph(source1, 1, "Data row");
            testchart.AddLineGraph(source2, Color.FromRgb(7, 10, 67), 1, "Data row");
            testchart.AddLineGraph(source3, Color.FromRgb(6, 5, 5), 1, "Data row");
            testchart.AddLineGraph(source4, Color.FromRgb(10, 6, 7), 1, "Data row");
            testchart.AddLineGraph(source5, Color.FromRgb(20, 8, 9), 1, "Data row");
            testchart.Viewport.FitToView();
            Thread simThread = new Thread(new ThreadStart(Simulation));
            simThread.IsBackground = true;
            simThread.Start();
        }

        private void Simulation()
        {
            int i = 0;
            while (true)
            {
                Point p1 = new Point(i * 10, i*10);
                if (i % 2 == 0)//here i tried to break first line in the graph
                {
                    source1.AppendAsync(Dispatcher, p1);
                }
                else
                {
                    Point p5 = new Point(Math.Sign(i*10),i*10);
                    source5.AppendAsync(Dispatcher, p5);
                }

                Point p2 = new Point(i *50, i*10);
                source2.AppendAsync(Dispatcher, p2);
                Point p3 = new Point(i * 1000, i);
                source3.AppendAsync(Dispatcher, p3);
                Point p4 = new Point(i * 1500, i);
                source4.AppendAsync(Dispatcher, p4);
                i++;
                Thread.Sleep(1000);

            }
        }

你需要的是一个 class 发射新的 ObservableDataSources(或者你可以停止发射新点的适配器)只要最后一个数据点的 Y > 0。每当电压为 0 时,您需要让 UI 停止收听该数据源。当电压 >0 并且你在那里时,你发出一个事件并向图表添加另一个线图..