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
70
Individual bar colors in igx-category chart
posted

Given a data set as such

const usaMedals: any = [
{ Year: "1996", UnitedStates: 148 },
{ Year: "2000", UnitedStates: 142 },
{ Year: "2004", UnitedStates: 134 },
{ Year: "2008", UnitedStates: 131 },
{ Year: "2012", UnitedStates: 135 },
{ Year: "2016", UnitedStates: 146 }
];
this.data = [ usaMedals ];
How is ti possible to have induvidual colors for each of the bars?
Example: 1996 -> Red, 2000 -> Blue etc.
An example for the above would also be nice.
Thanks in advance
Parents
  • 34430
    Verified Answer
    Offline posted

    Hello Singu,

    I have been investigating into your requirement, and in order to do this, I would recommend using the AssigningCategoryStyle event of the series plotted in your igx-category-chart. In order to get these series, you can handle the SeriesAdded event as the event arguments of that event will net you the series and then hook the AssigningCategoryStyle event on it in Typescript. Note that in order to handle this event, you need to “opt in” to it by setting the IsCustomCategoryStyleAllowed property on your series to “true.”

    In the AssigningCategoryStyle event handler, you can use the event arguments’ GetItems method along with its StartIndex and EndIndex properties to get an any[] of the underlying data items that make up the bar that is being “styled” by this event. You can then set the different properties related to color for that bar such as Fill or Stroke on the event arguments.

    I am attaching a sample project that demonstrates the above. I hope this helps you.

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

    3817.demo.zip

Reply Children