Hi,
How to set Color to each Slice in XamPieChart.
Suppose I have <SomeEnum, double> as ItemsSource of XamPieChart where SomeEnum is enum SomeEnum{ A, B, C }. I Want A Slice always be Red , B slice Blue and C Green. When I set to XamPieChart.Brushes some colors they randomly used to fill Slices, and if I have several similar slices, they colorized differently. Is there any way to solve the issue.
Thanks.
Hello Xetish,
The behavior you are seeing there is expected, as the brushes in the Brush collection for the XamPieChart will only be used if the slice is actually drawn. To work around this, I would recommend that you wrap the code you use to populate the Brush collection in an if-statement that checks the data of the particular object in your Dictionary. If its property that is used for the ValueMemberPath of the XamPieChart is zero, then pass by the population of the Brush collection for that particular item.
I have modified the original sample project I had sent you to include a KeyValuePair that has its value set to 0. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hello Andrew,
Thanks for response.
But in case when one of date in ItemsSource has zero value it will not be drawn and the color that corresponds to that data will fill slice of next data. Is there any solution for that.
Thanks Xetish.
Thank you for your post!
The best way to color your slices in the XamPieChart is to use the XamPieChart.Brushes collection, but the usage of the brushes in this collection is not random. Instead, it is based on the ordering of the collection you are using for the XamPieChart.ItemsSource. The indexes of the item for each slice and each brush in the brushes collection will match.
In other words, if your Brushes collection was {Brushes.Red, Brushes.Yellow, Brushes.Blue}, then the slice that represents your ItemsSource at index 0 would be Red (Brushes[0]), the slice at ItemsSource[1] would be Yellow (Brushes[1]), and the slice at ItemsSource[2] would be Blue (Brushes[2]). So, if you align your XamPieChart.Brushes collection with the entries in your ItemsSource, you can color the slices to your liking.
I have attached a sample project to demonstrate the above.