2013-01-03 74 views
1

plotter是一個DynamicDataDisplay.ChatterPlot變量。它增加了一對夫婦線,如下列:DynamicDataDisplay D3 LineGraph顏色變化

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

沒有人給出一些指針?任何想法是讚賞。 –

回答

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

這一點是不添加任何折線圖。

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; 

你的行會更新到你給它的筆的顏色。

+0

我不想每次都添加線條圖,因爲這會消耗資源,儘管是的,它應該在理論上工作。 –