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?
答案 0 :(得分: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;
然后,您的线将更新为您提供的笔的颜色。
答案 1 :(得分: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);
}
关键是不要添加任何折线图。