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.