This project is read-only.

Remove one linegraph from ChartPlotter

Jan 21, 2009 at 9:07 AM
Edited Jan 21, 2009 at 9:10 AM
Hi, how do i remove one of the linegraphs that I have added through AddLineGraph?

How I do it now is by calling RemoveUserElements and then add back the other LineGraphs that i want to keep. Is there a simpler way that I have missed?

Jan 21, 2009 at 6:32 PM

Extension method Plotter2D.AddLineGraph returns an added instance of LineGraph. You can use it later to remove it from Plotter by calling Plotter.Children.Remove(lineGraph) method.

Jan 28, 2009 at 3:13 PM
Thanks, just missed the wpf way of calling it children
Sep 1, 2009 at 10:54 PM

Hi Century,

This isnt working for me.


Calling  Plotter.Children.Remove(lineGraph) will work if I do it right after adding the line graph. However, if I try to remove it later on it isnt working. Is there any action that would cause the linegraph to be cloned and change the reference?

When I debug I can see that my plotter contains a child linegraph with the same description, but after calling plotter.remove that linegraph still appears in the list of children.


By the way, thanks for all the hard work. D3 is working really great for me!


Sep 3, 2009 at 7:09 PM

Hi Kelly,

can you please send me a reproduction of this case? My e-mail is



Oct 19, 2009 at 5:21 PM

Hello All,

Having the same problem - can't clear ChartPlotter at runtime. Is there any solution?

<d3:ChartPlotter Name="plotter" Grid.Row="1" />
private LineGraph SourceTotalNetworkEnergyLine;

private void buttonSimulate_Click(object sender, RoutedEventArgs e)
            // Create first source
            SourceTotalNetworkEnergy = new ObservableDataSource<Point>();
            // Set identity mapping of point in collection to point on plot
            SourceTotalNetworkEnergy.SetXYMapping(p => p);

            // Add all three graphs. Colors are not specified and chosen random
            SourceTotalNetworkEnergyLine = plotter.AddLineGraph(SourceTotalNetworkEnergy, System.Windows.Media.Colors.Red, 5, "Total Network Energy");

            // Start computation process in second thread
            var simThread = new Thread(Simulation) {IsBackground = true};


Thank you.


Oct 19, 2009 at 5:44 PM

Hi Misha,


   I worked around this problem by cycling through the plotters children and removing the line graph with matching properties. Using LINQ:

var lineToRemove = MainChart.Children.OfType<LineGraph>().Where(x => x.Description == "Total Network Energy").Single();

Not ideal, but it works for now.

Oct 20, 2009 at 9:26 AM


thanks for suggestion, but it still works not as expected. Maybe I'm missing something?

I need to restart simulation and show new chart. For this purpose I'm trying to clear chart and fill it again with new data.


has the same effect as

var lineToRemove = plotter.Children.OfType().Where(x => (x.Description.Brief == "Total Network Energy")).Single();

It really clears the chart.  But when I run the simulation again - there is no chart displayed.

Could you please provide some full example similar to "Simulation" example given in "DynamicDataDisplay v0.3 Binaries & Samples\Samples\v0.3\" but with simulation restarting?

Thank you

Oct 20, 2009 at 6:02 PM

Sorry Misha,

The code I posted was not complet, this code only gets a reference to the lineGraph that you want to remove. Next you need to remove it. The following should do the trick:

var lineToRemove = plotter.Children.OfType<LineGraph>().Where(x => x.Description == "Total Network Energy").Single();