Posted 2 years ago by Jerin Sebastian
Version: 17.2.0664
Avatar

How do you change the Bar color of a Bar chart through C# code?

Comments (4)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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.


Actipro Software Support

Posted 2 years ago by Jerin Sebastian
Avatar

It worked.

Thanks for the support.

Posted 2 years ago by Jerin Sebastian
Avatar

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

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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.


Actipro Software Support

The latest build of this product (v2019.1 build 0682) was released 30 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.