Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
XamPieChart Slice Colors
posted

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.

Parents
No Data
Reply
  • 34850
    Offline posted

    Hello 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.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XamPieChartBrushesDemo.zip
Children