DynamicDataDisplay ChartPlotter deletes all charts

In my WPF application, I have a D3 ChartPlotter where I was able to build 4 LineGraphs. This is the XAML code:

<d3:ChartPlotter Name="plotter"> <d3:ChartPlotter.HorizontalAxis> <d3:HorizontalAxis Name="timeAxis" /> </d3:ChartPlotter.HorizontalAxis> <d3:ChartPlotter.VerticalAxis> <d3:VerticalAxis Name="accelerationAxis" /> </d3:ChartPlotter.VerticalAxis> </d3:ChartPlotter> 

where d3 is the namespace for DinamicDataDisplay, and this (the corresponding part) of the code is behind.

 var x = new List<int>(); var y = new List<int>(); for (var t = 0; t <= 10; t = t + 1) { x.Add(t); y.Add(Math.Pow(t,2)); } var xCoord = new EnumerableDataSource<int>(x); xCoord.SetXMapping(t => t); var yCoord = new EnumerableDataSource<int>(y); yCoord.SetYMapping(k => k); CompositeDataSource plotterPoints = new CompositeDataSource(xCoord, yCoord); plotter.AddLineGraph(plotterPoints, Brushes.Red.Color , 2, "MyPlot"); 

Now I want to delete this plot and redraw it using a different set of points. Unfortunately, I cannot find anything in this direction, either in the (poor) D3 documentation, or on the Internet.

Any suggestion on what to do or where to look?

Thanks!

+4
source share
3 answers

The best way I've found to do this is to have a property in your code that is a DataSource and bind the DataSource to this property. Paste your code for the implementation of INotifyPropertyChanged and call OnPropertyChanged every time you update or reassign your data source. This will cause the plotter to observe the snap and redraw the chart.

Example:

 EnumerableDataSource<Point> m_d3DataSource; public EnumerableDataSource<Point> D3DataSource { get { return m_d3DataSource; } set { //you can set your mapping inside the set block as well m_d3DataSource = value; OnPropertyChanged("D3DataSource"); } } protected void OnPropertyChanged(PropertyChangedEventArgs e) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, e); } } protected void OnPropertyChanged(string propertyName) { OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); } 

If you need more information, the best resource I could find was CodePlex discussions where D3 is located: Discussions

+2
source

Well, there is an easy way to do this. If your goal is to remove every plot in the plotter, simply do the following:

 plotterName.Children.RemoveAll((typeof(LineGraph)); 

I hope this is useful to you.

+1
source

I had a similar problem. There are several different types of diagrams in D3. For example, when you use ElementMarkerPoints, you should remove RemoveAll ((typeof (MarkerPointGraph)).

Find out what type of graph you are using, then you can delete all graphs.

EDIT:

Do not delete graphs from the plotter. Use ObservableDataSource and remove the values ​​when you need to clean the plotter. When I remember correctly, you risk a memory leak otherwise because the graphics do not collect garbage. The ObservableDataSource object has a property called Collection, just call the Clear method, and you're good :)

0
source

Source: https://habr.com/ru/post/1443016/


All Articles