MSGraph Colors -- The Periodic Table of the Graph
Automating color in MSGraph can be quite confusing at first. And then again later, too.
The object model allows you to set any RGB color you like, but when you do this, the results are unpredictable. Sometimes it appears that it's worked as you expect, other times not.
What is MSGraph doing to me?
It's quite simple, once you understand the basic rule:
No matter what the object model says, you cannot select any color but those on the MSGraph color palette.
MSGraph allows you to request any RGB value, but maps it to the closest available color on the built-in palette. If you ask for a color that happens to be on the palette or one that's close, it it appears to work, but it really hasn't.
For predictable results, you must request RGB colors that are already on the palette or, more predictable, use ColorIndex to set colors to the palette "chip" you want.
What's the ColorIndex of the chip?
Working out what ColorIndex matches each chip is tricky. The chips are not numbered in any apparent logical order.
Rather than banging your head on that particular wall, you can use our "Periodic Table of the Graph" ... a PowerPoint file with a table that lists the index and RGB color (in several formats) of each "chip" on the MSGraph color palette.
Rightclick this link and choose Save target (or your browser's equivalent command) to download The Periodic Table of the Graph.
See also this code to modify Excel chart palette colors by PowerPoint MVP (and Excel expert) Brian Reilly and Access MVP (and Excel expert) Naresh Nachani.
But I can manually adjust the palette colors to get the values I want
Yes, but this is a section of the PowerPoint FAQ devoted to automating MSGraph, and for reasons dark and mysterious, or at least unknown to me, MSGraph doesn't make this particular feature available through the object model. In short, you can do it manually but not under program control.
For the curious, the feature works like this ... manually:
- Activate a chart on a PowerPoint slide.
- From the main menu bar, choose Tools, Options to open the Graph Options dialog box.
- In the Graph Options dialog box, click the "Color" tab.
- Click the color chip you want to change.
- Click "Modify" to open the Colors dialog box.
- Choose the new color you want and click OK to dismiss the Colors dialog box.
- Repeat until done modifying colors then click OK.
Now you can use your new color in the current chart.
Unfortunately, you'll have to repeat this same drill for each chart you want to edit, or copy the first chart onto a new slide and modify it. There's no way to save these modified palettes, not even as user-defined charts.
So what am I supposed to do?
As you'll see from the Periodic Table of the Graph, the first six colors on row six of the MSGraph palette actually do change; MSGraph picks them up from the color scheme of the PowerPoint slide the chart is on. And you can change the color scheme under program control.
This is far from ideal, as changing the color scheme will often change the colors of other shapes on the same slide, but if you need one or two special colors in your charts, this is often a workable solution.
You can also control which of the scheme colors get applied to charts and which don't. Click a chart to select it, then click "Recolor Chart" on the Picture toolbar. Then you can set the chart to follow:
- All of the scheme colors
- Only the text and background colors from the scheme
- None of the scheme colors
Other miscellaneous bits
You'll note that MSGraph also has an Automatic setting for some of its colors.
In the case of data series (ie, the colors of bars, pie slices, etc.) Automatic means "follow the first four colors on row six of the color palette for the first four series; after that, use your defaults."
For text, Automatic means "follow the Text and Lines color from the PowerPoint slide's color scheme".
For chart and plot areas and other "background" features, Automatic means "follow the Background color from the slide's color sheme".