Search code examples
wpfcolorslinegraphdynamic-data-display

DynamicDataDisplay D3 LineGraph color change


plotter is a DynamicDataDisplay.ChatterPlot variable. It adds a couple lines like following:

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

The graph plot is updated in real time, so I am updating the data source only, like this:

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

But I am wondering, except for updating the data points, is there anyway I can change the brush color for the LineGraph variable as well? I guess that should be in somewhere like plotter.XXX.color ?


Solution

  • So basically, I solved this problem by setting the color to transparent each time before the color is re-assigned. Something like this:

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

    The point is NOT to add any line graph.