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.

Comments (10)

  1. kyletinsley says:

    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.

  2. Anonymous says:

    Hi Alex,

    i have question about handling emptydatapointstyle, if i have palette applied to my chart it is overriding the emptypointstyle behavior and is not drawing line color for emptydatapoint style.

    can you please help on this?

  3. Anonymous says:

    Hi,

    how can i desible all elements of the chart control and set the Series transparent

    can you please help on this?

  4. Anonymous says:

    hi…how can i set a palette to a chart through code?

    i have used a combo box for selecting palette name

    please help

  5. Anonymous says:

    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.


    mamata

    <a href=“www.yahoo.com” rel=“dofollow”>Colors</a>

  6. Anonymous says:

    hi,

       I am using  VC9(visual Studio 2008) for VC++ project . In my project for Graph I am using Microsoft chart Control 6.0(SP4)(OLEDB).Actually I wanted to use Range bar chart  and Scatter plot chart types, but MSchart is not supporting for these charttype.I have a mschart.h file ,in that they declaring enum for 27 different types of charts and also I used these enum for customization ,then for First 9 charttypes it worked fine ,but for remaining charttypes its showing an pop up message like "Invalid property value".Please help me that How to use Range bar chart and Scatter plot charts in mschart.

  7. Anonymous says:

    I am adding/removing series from a chart by using checkbox as trigger. But if a series is removed then the color for the existing series changes. Is there any way to fix the colors for a series by using existing palletes. Or is there any way to 'Get' the color that gets assigned to a series by existing pallete?

    Thanks.

  8. Anonymous says:

    Alex, I understand this is a really old post, but perhaps you could provide the answer: Do you have list of color codes (or named colors) for each predefined palette in MS Chart?

    Thanks!

  9. Anonymous says:

    thanks so much for the info.  Searched for a while before I found .ApplyPaleteColors

  10. Anonymous says:

    Hello. Are there a way to get the default color when a pie chart is create? I only give the points value, and the pie chart came with default colors. But i can't get those color from the chart! See the example in the link: gyazo.com/3142acd51db4ed8860ff3386fdf6a42c