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

Double precision on series re-insertion

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

I create my chart by inserting data points like so:

2.var series = new DataSeries { Definition = new SplineAreaSeriesDefinition() };
3.foreach (var point in dataPoints) series.Add(point);

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

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

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
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:

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
Asked by
Top achievements
Rank 1
Answers by
Evgeni "Zammy" Petrov
Telerik team
Share this question