This was the solution. I needed to set the colors based on a sorted list of values, and the colors had to match a specific "category" in my dataset (a
List
). I think they succeeded in making this as obscure as possible. There is no way to set the color of a pie slice directly - it MUST be done via the
Chart.Palette
property. If you want to use something other than the standard you must CREATE and populate your own object. Since I didn't know ahead of time the order in which a given category was going to be added to the chart, I had to write a method that would determine the order and add colors accordingly.
private System.Collections.ObjectModel.Collection<ResourceDictionary> MakePalette(List<RepItem> list)
{
System.Collections.ObjectModel.Collection<ResourceDictionary> palette = new System.Collections.ObjectModel.Collection<ResourceDictionary>();
foreach (RepItem item in list)
{
ResourceDictionary rd = new ResourceDictionary();
Style style = new Style(typeof(Control));
SolidColorBrush brush = null;
switch (item.Category)
{
case RepCategory.Author : brush = new SolidColorBrush(Colors.DarkRed); break;
case RepCategory.Authority : brush = new SolidColorBrush(Colors.DarkGreen); break;
case RepCategory.Debator : brush = new SolidColorBrush(Colors.Magenta); break;
case RepCategory.Editor : brush = new SolidColorBrush(Colors.Goldenrod); break;
case RepCategory.Enquirer : brush = new SolidColorBrush(Colors.Purple); break;
case RepCategory.Organiser : brush = new SolidColorBrush(Colors.Olive); break;
case RepCategory.Participant : brush = new SolidColorBrush(Colors.LightSteelBlue); break;
}
style.Setters.Add(new Setter() { Property = Control.BackgroundProperty, Value = brush });
rd.Add("DataPointStyle", style);
palette.Add(rd);
}
return palette;
}