unable to erase chartplotter data on C# WPF

May 22, 2013 at 6:15 AM
Edited May 22, 2013 at 6:29 AM
Hi,
I am using d3 for the first time and I find it very useful. I am taking a dynamic integer value coming in at frequent intervals and plotting it as a linegraph ('line1') onto a chartplotter named 'plotter'. What I want is to have a way to erase all the data from the chartplotter when I uncheck the checkbox and start plotting again once i check it back. I thought I might be able to accomplish it with plotter.Children.Remove(line1), but it does not erase the old data. Instead it plots over the old data again and I have double data lines. Here is the code example (includes some pseudo codes) that I have so far.
ObservableDataSource<System.Windows.Point> source1=new ObservableDataSource<System.Windows.Point>();
LineGraph line1=new LineGraph(source1);
line1.Name = "Data1";
int i=0;
start a timer to CaptureData...
CaptureData(....,...)
{
  if a CheckBox is checked...()
 {
    if (i == 0)
    {
    plotter.Children.Add(line1);
    }
    double graph_x = Convert.ToDouble(i);
    double graph_y = Convert.ToDouble(datapoint that I have);
    System.Windows.Point p1 = new System.Windows.Point(graph_x, graph_y);
    source1.AppendAsync(Dispatcher, p1);
    i++;
    }
 }
 Once the checkBox is unchecked
 {
    if (i != 0)
      {
         i=0;
         plotter.Children.Remove(line1);
      }
 }
}
This code is able to take out the data plot once the box is unchecked, but it plots over the old data once I check it again. any way that I can avoid this? Any pointer to solve this are welcome...
May 24, 2013 at 2:20 AM
Hi... ANyone with any hint??? Please let me know if the question is not clear to you!!!
May 24, 2013 at 9:14 AM
Hi,

After unchecking do something like this
foreach(var child in plotter.Children)
{
       if(child.GetType() == typeof(LineGraph )
       {
               if(child.tag = line1.tag) // Some name comparison
               {
                       plotter.Children.Remove(child);
                       //Reset this.
               }
       }
}
Regards
Ravi
May 24, 2013 at 10:18 AM
Hi Ravi,
Many thanks for your reply. From looking at this code, isn't it just removing all the children from the graph without actually blanking out the data from the graph, similar to what I already have? With the code that I mentioned in my first post, I am able to clear out the graph from the plotter, but when I plot again using the same linegraph child, the old points are still there. Here is an image of what I get using my current code to get a better understanding.
Image

I tried to use the code you provided in my program. It throws error at the foreach line "Collection was modified; enumeration operation may not execute"
And in my program I can't find the child.TAG object. so I omitted that comparison checking. Please let me know if you need the complete code that I have.