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
Bar series with different style chunks

Is there an easy way to use different brush color along a bar series? I have many different bar series on the same chart. For each series I want to set a different color for some chunks.
For example:
I series
from x-value = 5000 to x-value = 5100 set BrushColor="green";
from x-value = 5200 to x-value = 6000 set BrushColor="red";

II series
from x-value = 4000 to x-value = 4150 set BrushColor="yellow";

If it's possible, I would like to see an example.

Thank you for your support.

  • 28750
    Offline posted

    Hello Giuseppe,

    In order to achieve your requirement, I would recommend utilizing the AssigningCategoryStyle event of the BarSeries. In order to do this, you must first opt-in to handling this event by setting the IsCustomCategoryStyleAllowed property of the BarSeries to true.

    This event will fire for each "bar" that is drawn, and the event arguments of this event carry some index information so that you can get the underlying data item to each one by utilizing the GetItems.Invoke() method along with the StartIndex and EndIndex properties of these arguments. From here, you can check the value path of your underlying data item and assign the Fill property of the event arguments accordingly to color the bars differently. Below is a code-snippet of this event's usage, where "SampleData" is a data item class:

            private void BarSeries_AssigningCategoryStyle(object sender, AssigningCategoryStyleEventArgs args)
                var x = args.GetItems.Invoke(args.StartIndex, args.EndIndex);
                if(x.Length > 0)
                    SampleData data = x[0] as SampleData;
                    if(data.Value > 5000)
                        args.Fill = new SolidColorBrush(Color.Green);
                        args.Fill = new SolidColorBrush(Color.Red);

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

    Associate Developer

Reply Children