Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can someone provide an example of how to change the colors of a pie chart? (The actual pie chart pieces). The pieces are referred to as Points? I'd like to choose a color using RGB for each piece. Thanks!

share|improve this question

migrated from stackoverflow.com Dec 8 '12 at 0:12

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

Personally Peltier's Chart Blog is my favorite Excel Charting source. So take a look at some of the samples he discussed there. To know more here is the MVP

I do not think it's wonderful to copy his codes here. So try the tutorials stated in above materials out and comment if you have further questions. And here is some facts I thought would be helpful in your Charting Journey to be smooth and fun.

To be very specific on RGB Colour formatting of your pie chart slices, here is the code line:

E.g.

ActiveChart.SeriesCollection(1).Points(1).Interior.Color = RGB(0, 176, 80)

You may find RGB colour numbers from MS Paint application in Windows :) Else here is an article that shows some colours and corresponding RGB numbers.

As colour spectrum is infinite, it should be good enough to colour your extra multi sliced pie chart, you may think.. HOWEVER don't forget that Excel default colour Palette has 56 colour indices. Like Excel 2003. So sometimes there are issues when using your Chart file in a different version of Excel - where you find some colours are missing and just being replaced by unappealing old looking colours ;)

E.g. A Chart created in Excel 2007 and above has rich graphical, colour experience to the user. However Excel 2003 doesn't provide so, but manageable (and extremely great in performance though.) In Excel 2007 and later, workbooks can support millions of colors, but there is still an underlying workbook palette that has 56 colors.

So when you face such issues or be read to deal with it, plesae check on this article:

share|improve this answer
    
So it needs code? Is it possible to write colors (for example as an RGB hex string) in a column on the sheet with the data and tell Excel to pick it's colors there? –  dumbledad Apr 19 '13 at 15:09
add comment

Source

Sub ColorPieCharts()    
    Dim iX As Integer
    Dim iY As Integer
    Dim bHasDataLabels As Boolean
    Dim bShowSeriesName As Boolean
    Dim bShowCategoryName As Boolean
    Dim bShowValue As Boolean
    Dim bShowPercentage As Boolean
    Dim bLegendKey As Boolean
    Dim bHasLeaderLines As Boolean

    SetWorkbookColors

    For iX = 1 To ActiveSheet.ChartObjects.Count
        ActiveSheet.ChartObjects(iX).Select

        'Determine DataLabel status
        On Error Resume Next
        bHasDataLabels = ActiveChart.SeriesCollection(1).HasDataLabels
        'bLegendKey = ActiveChart.SeriesCollection(1).LegendKey
        bHasLeaderLines = ActiveChart.SeriesCollection(1).HasLeaderLines
        bShowSeriesName = ActiveChart.SeriesCollection(1).DataLabels.ShowSeriesName
        bShowCategoryName = ActiveChart.SeriesCollection(1).DataLabels.ShowCategoryName
        bShowValue = ActiveChart.SeriesCollection(1).DataLabels.ShowValue
        bShowPercentage = ActiveChart.SeriesCollection(1).DataLabels.ShowPercentage
        On Error GoTo 0

        ActiveChart.ApplyDataLabels AutoText:=True, _
            HasLeaderLines:=True, ShowSeriesName:=False, ShowCategoryName:=True, _
            ShowValue:=False, ShowPercentage:=False, ShowBubbleSize:=False

        For iY = 1 To ActiveChart.SeriesCollection(1).Points.Count
            Select Case ActiveChart.SeriesCollection(1).Points(iY).DataLabel.Text
            Case Is = "a"
                ActiveChart.SeriesCollection(1).Points(iY).Interior.ColorIndex = 1
            Case Is = "b"
                ActiveChart.SeriesCollection(1).Points(iY).Interior.ColorIndex = 2
            Case Is = "c"
                ActiveChart.SeriesCollection(1).Points(iY).Interior.ColorIndex = 3
            Case Is = "d"
                ActiveChart.SeriesCollection(1).Points(iY).Interior.ColorIndex = 4
            Case Is = "e"
                ActiveChart.SeriesCollection(1).Points(iY).Interior.ColorIndex = 5
            Case Is = "f"
                ActiveChart.SeriesCollection(1).Points(iY).Interior.ColorIndex = 6
            Case Else
                'Other groups get no special color
            End Select
        Next
    Next

End_Sub:
    If bHasDataLabels Then
        ActiveChart.ApplyDataLabels AutoText:=True, _
            HasLeaderLines:=True, ShowSeriesName:=bShowSeriesName, ShowCategoryName:=bShowCategoryName, _
            ShowValue:=bShowValue, ShowPercentage:=bShowPercentage, ShowBubbleSize:=False
    Else
        ActiveChart.SeriesCollection(1).HasDataLabels = False
    End If

End Sub

Sub SetWorkbookColors()
    ActiveWorkbook.Colors(1) = RGB(0, 0, 0)
    ActiveWorkbook.Colors(2) = RGB(0, 0, 100)
    ActiveWorkbook.Colors(3) = RGB(0, 100, 0)
    ActiveWorkbook.Colors(4) = RGB(0, 100, 100)
    ActiveWorkbook.Colors(5) = RGB(100, 0, 0)
    ActiveWorkbook.Colors(6) = RGB(100, 0, 100)
End Sub

Sub ResetWorkbookColors()
    ActiveWorkbook.ResetColors
End Sub
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.