1

plotter是一个DynamicDataDisplay.ChatterPlot变量。它添加了如下几行:

 LineGraph lgChA = plotter.AddLineGraph(dsChA, Colors.Red, 1, "Data");
 LineGraph lgChB = plotter.AddLineGraph(dsChB, Colors.Green, 1, "Data");

图表是实时更新的,所以我只更新数据源,如下所示:

if (_dataXChA != null && _dataXChA.Length > 1)
        {
            EnumerableDataSource<double> xChA = new EnumerableDataSource<double>(_dataXChA);
            xChA.SetXMapping(xVal => xVal);

            if (_dataYChA != null && _dataYChA.Length == _dataXChA.Length)
            {
                EnumerableDataSource<double> yChA = new EnumerableDataSource<double>(_dataYChA);
                yChA.SetYMapping(yVal => yVal);
                CompositeDataSource dsChA = new CompositeDataSource(xChA, yChA);
                //((LineGraph)plotter.brus = dsChA; 
                ((LineGraph)plotter.Children.ElementAt(startIndex)).DataSource = dsChA;                    
                plotter.FitToView();
            }
        }

        if (_dataXChB != null && _dataXChB.Length > 1)
        {
            EnumerableDataSource<double> xChB = new EnumerableDataSource<double>(_dataXChB);
            xChB.SetXMapping(xVal => xVal);

            if (_dataYChB != null && _dataYChB.Length == _dataXChB.Length)
            {
                EnumerableDataSource<double> yChB = new EnumerableDataSource<double>(_dataYChB);
                yChB.SetYMapping(yVal => yVal);                    
                CompositeDataSource dsChB = new CompositeDataSource(xChB, yChB);
                ((LineGraph)plotter.Children.ElementAt(startIndex + 1)).DataSource = dsChB; 
                plotter.FitToView();
            }
        }

但我想知道,除了更新数据点之外,我是否也可以更改LineGraph变量的画笔颜色?我想应该在像 plotter.XXX.color 这样的地方?

4

2 回答 2

2

您可以像这样更改线条的颜色:

LineGraph lgChA = plotter.AddLineGraph(dsChA, Colors.Red, 1, "Data");
Pen newColour = new Pen(Brushes.Red, 1.0);
//or whatever colour you want to change it to, second parameter is line thickness
lgChA.LinePen = newColour;

然后,您的线条将更新为您给它的笔的颜色。

于 2013-01-04T07:37:37.590 回答
1

所以基本上,我通过在每次重新分配颜色之前将颜色设置为透明来解决这个问题。像这样的东西:

for (int i = 0; i < LiveImage.MAX_CHANNELS; i++)    // color reset
                {
                    ((LineGraph)plotter.Children.ElementAt(startIndex + i)).LinePen = new Pen(new SolidColorBrush(Colors.Transparent), 1);
            }

关键是不要添加任何折线图。

于 2013-02-12T16:53:21.810 回答