I’m working with the Silverlight 4 toolkit and using the Charting control, specifically the Line Series. I’m also using one of the Microsoft Silverlight themes, which comes with some default styling for the Chart.
I know that in the ToolkitStyles.xaml there’s a whole host of colour brushes that get used by the charting toolkit – ChartBrush1, ChartBrush2 etc. etc.. What I don’t understand is how they get used by the chart itself.
The reason I’m asking this is because I’m trying to change the DataPointStyle for the LineSeries – I’ve successfully pulled out a copy of the data point style in Blend and made the changes I wanted i.e. make the size of the data point smaller. But as soon as I do this, all the line series in the graph have the same colour (Orange) and ignore the ChartBrush resources (detailed above).
What’s driving the colour selection of the line series? How does it happen? Why do I lose it if I take a copy of the template?
Thanks!
The toolkit
Chartcontrol has a propertyPalettethat is a resource dictionary of styles.You can find the default Chart style in “Controls.DataVisualization.Toolkit\Charting\Chart\Chart.xaml”.
In there you can see that
Paletteis aResourceDictionaryCollectionand eachResourceDictionaryin the collection defines aDataPointStyle. EachDataPointStylesets theBackgroundproperty differently and this is how each line in the chart becomes a different colour.From here it is clear to see why lines in a line series that have a
DataPointStyleset explicitly in xaml will always have the same colour – the defaultDataPointStylethat defines the colour has been replaced.The solution to this is to modify the palette used by the chart. Here I have created a base style that sets the desired
DataPointStyleproperties and then for everyDataPointStylein the dictionary collection, specifyBasedOn="{StaticResource DataPointStyleWithNoPoints}".The you simply specify the palette on the chart: