How can I control the color of individual pie chart segments in Excel?
I would like to be able to control the color of the sections in a pie chart programmically. Ideally my chart would be based on a 3-column table with the columns being: The Data Value, The Label, and the Pie Chart Color Value. The color values would be that same numbers one sees in Access form properties.
Thanks,
Steve
Sub a()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Points.Item(1).Interior.ColorIndex = 7
End Sub
您可以使用我在This Other Answer中发布的技巧来学习ColorIndex所代表的颜色
Perhaps something on these lines?
Dim ws As Worksheet
Dim sh As Shape
Set ws = Sheet2
Set sh = ws.Shapes.AddChart '.Select
With sh.Chart
.ChartType = xlPie
.SetSourceData Source:=Range("Sheet1!$A$1:$B$3")
For i = 1 To .SeriesCollection(1).Points.Count
With .SeriesCollection(1).Points(i).Format.Fill
.ForeColor.RGB = Range("C" & i).Interior.Color
.Solid
End With
Next
End With
This will allow you to add a colour to a cell using the fill button and have it used for a segment.
First off, I know it can be done. BeGraphic have a freebie Excel add-in with a feature to set the chart element colours in the spreadhseet. See:
This use an add-in. I must say the results are impressive. For myself I needed something more Excel-native, many others there will find this option top-shelf.
While the VB option from Remou and begraphic's add-in do the deed. For me, or the current project at least, I need an Excel based solution (as much as is practical and is possible). In the meantime, you fine people and myself can find work-arounds via VB, VBA, .Net and/or macros. Visit Jon P's site for available options.
If I discover 'more' -- I'll pass it back on this query.
aloha,
Will
上一篇: Visual Studio 2010能否对F#模块进行代码覆盖率分析?
下一篇: 如何控制Excel中各个饼图段的颜色?