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
2085
XamDoughnutChart Series Slice Color
posted

I am trying to color specific XamDoughnutChart RingSeries slices a specific color.  Think of a finance dashboard where the ring represents all funds, Available funds are shown with a GREEN slice, and Used funds are shown with a RED slice.


Currently, I have a BrushCollection with 2 colors, GREEN and RED.  I assumed that I'd only have positive values for Available funds, but just recently we got a negative value for Available funds, so the XamDoughnutChart won't graph the negative value (It only shows slices with value > 0).  This means that when the Used funds are shown, they get colored GREEN, as green is in BrushCollection[0].  One solution I found is to test the collection before I add my Colors to the BrushCollection, and only add RED if the Available funds value is 0.  This seems like a hack to me, and I am looking for a way to specifically set the color value for a slice, that way if a value higher in my list is zero or less than zero, I don't get a shifted color palette for graphing the rest of my values.

  • 34810
    Verified Answer
    Offline posted

    Hello Gary,

    The best way to assign your RingSeries slices a specific color is to use the Brushes collection, as you are currently doing. The way that the XamDoughnutChart works with this BrushCollection is that the index of the Slice will receive the brush at the index of the assigned BrushCollection. For example, the slice at index 0 will receive the BrushCollection[0] brush. Testing your collection does not seem like a hack to me in this case, as you are essentially ensuring that a slice will exist for a particular data item in this case.

    If you are looking for a way to truly set the colors directly on the Slice, you will need to walk through the visual tree of the XamDoughnutChart. The Infragistics.Windows.Utilities class can help with this. Essentially, this class has a couple of "GetDescendantFrom..." methods that can get you an element of a certain type or by name. Using this with your RingSeries, this can get you down to the Canvas that holds your Slices, at which point, you can set the Background property on them. The code to get to this slice canvas would look like the following:

    RingSeries series = doughnut.Series.First() as RingSeries;
               
    Arc arc = Utilities.GetDescendantFromType(series, typeof(Arc), false) as Arc;           

    ContentPresenter presenter = Utilities.GetDescendantFromName(arc, "ContentPresenter") as ContentPresenter;

    Canvas canvas = presenter.Content as Canvas;
    Canvas sliceCanvas = canvas.Children[0] as Canvas;

    The Children of sliceCanvas will be Slice elements, which you can set the Background of. It is worth noting though, that this is a bit more of a "hack" solution, and when the XamDoughnutChart changes or resizes, it will redraw each of the slices based upon the BrushCollection of the underlying RingSeries, and so this would require a bit more maintenance than usage of the BrushCollection.

    If you would like to see a way to directly set the brush on a particular slice in the XamDoughnutChart, I would recommend suggesting a new product idea for this feature at http://ideas.infragistics.com. This product ideas site will place you in direct communication with our product management team who plans and prioritizes upcoming features and development based on community and user feedback.

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

    Sincerely,
    Andrew
    Associate Developer