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
变量的画笔颜色吗?我猜应该在某个地方,比如plot . xxx .color ?
你可以像这样改变你的线条的颜色:
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;
你的线条将更新为你给它的笔的颜色。
所以基本上,我通过在每次重新分配颜色之前将颜色设置为透明来解决这个问题。像这样:
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);
}
关键是不要添加任何线形图