How do you change the Bar color of a Bar chart through C# code?
How do you change the Bar color of a Bar chart through C# code?
Hello Jerin,
Please take a look at the XY / BarStyles QuickStart in the samples. If you have your XYChart.SeriesStyleSelector property set to a SeriesPaletteStyleSelector instance, you can set properties like BarBrushCustom to indicate a specific brush for all bars.
Or alternatively the BarSeries class has BarStyle and BarTemplate properties. The BarStyle property can be set to a Style targeting Border that has Background and BorderBrush properties set. That can be set up in code.
If you want to have total control over what each individual bar looks like, you can inherit SeriesPaletteStyleSelector and override its SelectBarStyle method to return an appropriate Style.
It worked.
Thanks for the support.
Even though the bar color changed but the Legend color didn't change.
How do we fix that?
See the below link to see the screenshot.
https://drive.google.com/open?id=1OdVxY7sEUCq8sVtzZO3aBFCO0xDduvwO
Hi Jerin,
The legend swatch is generated from the SeriesStyleSelector.SelectLegendMarkerStyle method. If you are using SeriesPaletteStyleSelector, it will base the legend swatch on the palette color that is selected for that particular series. Using a custom Palette with a SeriesPaletteStyleSelector is another way that also will affect the bars and the legend together. You can define a set of base colors (one per series) in the Palette and have the SeriesPaletteStyleSelector use it.
Please log in to a validated account to post comments.