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
370
XamDataChart ColumnSeries set color on individual column
posted

I am creating a column series in XamDataChart and the items I am binding to have a value property and a brush property. How can I bind the brush property to the color of the column, so that each column in the series get the color defined in my brush property? 

Regards,

Hilma Maria

Parents
  • 2640
    Offline posted

    Hello Hilma Maria,

    I have been looking into your question and after investigation found this forum thread where a similar question about customizing the ColumnSeries column colors in the XamDataChart  has been discussed. I have also created a small sample application that demonstrates the suggested approach there and sets column fill colors based on their items’ brush property.

    To sum up, in order to set the column color based on some item’s property, you need to first set the IsCustomCategoryStyleAllowed property on the ColumnSeries to "True" and handle the AssigningCategoryStyle event on the same series. This event is fired for every column and the corresponding item can be retrieved from the event arguments by calling the GetItems method. The column color can be set by assigning the item’s brush property to the event arguments’ Fill property:

    private void ColumnSeries_AssigningCategoryStyle(object sender, Infragistics.Controls.Charts.AssigningCategoryStyleEventArgs args)
         {
                SampleData currentColumn = args.GetItems(args.StartIndex, args.EndIndex)[0] as SampleData;
                Console.WriteLine(currentColumn.Value.ToString() + " " + currentColumn.ColumnBrush.ToString());
                args.Fill =currentColumn.ColumnBrush;
            }

    You can find the sample attached below. Please, test it on your side and let me know if I may be of any further assistance.

    Sincerely,

    Bozhidara Pachilova

    Associate Software Developer

    1030.XDCColumnSeriesColorBinding.zip

Reply Children