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
1415
Color coding XamPieChart
posted

How can I assign colors to slices in the XamPieChart?

We are trying to use:
 

<ig:XamPieChart.Brushes>
    <ig:BrushCollection>
        <SolidColorBrush Color="Red"/>
        <SolidColorBrush Color="Green"/>
    </ig:BrushCollection>
</ig:XamPieChart.Brushes>

Red representing # of things going out, Green for # of things coming in.

Each time we update the ItemSource, the Brushes flip-flop (Green becomes assigned to things going out, etc...)

How can we prevent the XamPieChart from randomly assigning the colors to the ItemSource values?  The ItemSource order does not change, but updates to the ItemSource switches these slice brushes to either incorrect or correct color.

  • 34830
    Offline posted

    Hello PMac,

    I have been investigating into the behavior you are seeing, although I am a bit unsure what you are doing to get the brushes of the XamPieChart to “swap” in this case. The brush elements within the Brushes collection of the XamPieChart will correspond to the index of the underlying data item in this case, and so in the case of the collection that you have provided, “Red” will be assigned to the slice representing your data at index 0, and “Green” will be assigned to index “1.” This will alternate proportionately if there are more than 2 items in your collection.

    At the moment, I cannot seem to reproduce the behavior that the brushes are swapping on the slices, and so if you could please provide some additional information on how you are getting this to happen, that would be very helpful. With that said, the Brushes collection is the only “built-in” way to assign brushes to the XamPieChart, but there is another, although rather hacky way to do this as well by using the LayoutUpdated event of the chart. This is documented on another forum thread, here, and if you would like to follow this route, I would recommend taking a look. Note, the other forum thread is for Silverlight, but the XamPieChart was a shared code-base between Silverlight and WPF when Silverlight was more relevant, and so this should work exactly the same.

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