Welcome to MSDN Blogs Sign in | Join | Help

Setting Microsoft Chart Series Colors

Microsoft Chart control provides different ways to set color of the series and data points:

Palettes

Selecting one of the predefined palettes is the easiest way to change chart series colors. There are 12 built-in palettes with about 10 unique colors each.

ChartPalettes

Chart types like column and line, will assign a unique color from the palette to each of the series. If chart runs out of the palette colors then it will start reusing them again. 

// Set chart series palette
Chart.Palette = ChartColorPalette.Pastel;

Chart type like Pie, assigns unique colors to each individual data point. You can still use Chart.Palette property or you can define different palettes for different series using Series.Palette property. Note that setting Series.Palette property will force all chart types including Column to use unique colors for each data point.

Important! To determine the color assigned to the series or data point from the palette you can call chart1.ApplyPaletteColors() method and then check Series or DataPoint.Color property.

Custom Palettes

If none of the predefined palettes fits your needs, you can always create custom palette with as many colors as you need:

// Set chart custom palette
Chart.Palette = ChartColorPalette.None; 
Chart.PaletteCustomColors = new Color[] { Color.Red, Color.Blue, Color.Yellow};

Empty points

Not all series data points are equal… When you data bind your chart to the DBNull values the data points will be automatically marked as ‘empty’. You can also mark data points as empty by setting DataPoint.IsEmpty property. Each empty data point uses the visual attributes defined in Series.EmptyPointStyle property.

// Hide all series empty data point by making them transparent
Chart.Series[0].EmptyPointStyle.Color = Color.Transparent; 

Color Property

If all of the above methods does not work for you, then you can always set Color property for the series or individual data point.

// Set color for the whole series
Chart.Series[0].Color = Color.Green;

// Set color of a single data point
Chart.Series[0].Points[5].Color = Color.Red;

You can always switch back to using the palette colors by setting both Series and DataPoint Color properties to Color.Empty. 

Alex.

Published Tuesday, October 06, 2009 8:33 AM by alexgor

Comments

Friday, November 13, 2009 9:05 AM by kyletinsley

# re: Setting Microsoft Chart Series Colors

Hi Alex,

Is there any way to set the corner radius of the chart border?  The BorderSkinStyle.Emboss radius is far too rounded to fit the style of our site and we would like to set it to 7px or something less than what is defaulted.  Ideally, we would be able to have a 7px corner radius without any embossing.  Here is an example of what we are looking for:

The following chart was done with the Telerik chart.  We would like to replace it with the MS chart, but need to replicate its corner style:

http://www.buybusiness.com/Businesses/10001

This question was also posted here:

http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/24a4488b-1ccf-4346-9d59-16ccf5c371b0/

Thank you.

Anonymous comments are disabled
 
Page view tracker