This is a migrated thread and some comments may be shown as answers.

Double precision on series re-insertion

1 Answer 58 Views
Chart
This is a migrated thread and some comments may be shown as answers.
PoorLeno
Top achievements
Rank 1
PoorLeno asked on 14 Dec 2010, 11:07 PM

I create my chart by inserting data points like so:

1.Chart.DefaultView.ChartArea.DataSeries.Clear();
2.var series = new DataSeries { Definition = new SplineAreaSeriesDefinition() };
3.foreach (var point in dataPoints) series.Add(point);
4.Chart.DefaultView.ChartArea.DataSeries.Add(series);

The points themselves are created thusly. I explicitly specify types for your convenience.

1.var dataPoints = /*[...]*/.Select( (x, y) => new DataPoint((int)x, (double)y).ToArray()

When I call the add method, I obtain the graph (supplied) "mychartnormal.png". I'm happy with this graph.

When I do the following manipulation of the graph, I obtain a new figure (supplied) "mychartweird.png". The number formatting of the highlighted values shows unnecessary precision. 

1.var series = OverviewChart.DefaultView.ChartArea.DataSeries.FirstOrDefault();
2.if (ColorPicker.SelectedItem != null && series != null)
3.    series.Definition.Appearance.Fill = new SolidColorBrush((Color) ColorPicker.SelectedItem);
4.OverviewChart.DefaultView.ChartArea.DataSeries.Clear();
5.OverviewChart.DefaultView.ChartArea.DataSeries.Add(series);

You may wonder at this point why I am not manipulating the Definition.Appearance.Fill property of the series that I pick out on line one directly. Well, the reason being is that I want to the drawing animation to restart, and I didn't find another way in the API do that. As such I am open to two possible solutions.

Firstly there's the obvious rewrite that solves the problem, but I find it in bad taste to have to recreate the series, since I may need to modify other properties separately, and the copying on line 3 can easily become unwieldy.

1.var series = OverviewChart.DefaultView.ChartArea.DataSeries.FirstOrDefault();
2.if (ColorPicker.SelectedItem == null || series == null) return;
3.var nseries = new DataSeries() {Definition = series.Definition};
4.nseries.AddRange( series.Select(datapoint => new DataPoint(datapoint.XValue, datapoint.YValue)));
5.nseries.Definition.Appearance.Fill = new SolidColorBrush((Color) ColorPicker.SelectedItem);
6.OverviewChart.DefaultView.ChartArea.DataSeries.Clear();
7.OverviewChart.DefaultView.ChartArea.DataSeries.Add(nseries);

Secondly all I really need is to restart the animation. I only found one relevant post, which said to use Chart.ResetTheme(), which didn't work for me.

1 Answer, 1 is accepted

Sort by
0
Evgeni "Zammy" Petrov
Telerik team
answered on 20 Dec 2010, 02:52 PM
Hi PoorLeno,

I would suggest using our binding options instead of manually creating DataPoints? Here is help link:  http://www.telerik.com/help/silverlight/radchart-populating-with-data-data-binding-with-manual-series-mapping.html.

Unfortunately to have the animation restarted you will need to put the data again.  That is why I suggest using DataBinding rather than creating DataPoints manually.

Best wishes,
Evgeni "Zammy" Petrov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
Chart
Asked by
PoorLeno
Top achievements
Rank 1
Answers by
Evgeni "Zammy" Petrov
Telerik team
Share this question
or