【发布时间】:2020-03-12 09:36:39
【问题描述】:
我正在拼命尝试通过 VBA 格式化旭日形图。根据点数,我希望列使用我的一种颜色,从绿色到红色。
图表所依据的数据是在另一张表上指定的,所以一旦图表表被激活,我就会格式化图表。
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'Only when correct sheet is opened
If Not Sh.Name = "Radar Chart" Then Exit Sub
'Do things to find out which data point number is at the core of each column -> coloring this point colors the whole column
...
'Color the sunburst
Dim chtObj As ChartObject, pts As Points
Set chtObj = Sh.ChartObjects(1)
With chtObj.Chart
' .ClearToMatchColorStyle -> Runtime error
' .ClearToMatchStyle -> Runtime error
' .ChartArea.ClearFormats -> Runtime error
Set pts = .SeriesCollection(1).Points
End With
'pts(1).ApplyDataLabels (xlDataLabelsShowNone) -> Runtime error
'pts(2).ClearFormats -> Runtime error
For i = LBound(arrData, 1) To UBound(arrData, 1)
'arrPairings contains the number of points in column i
'arrZuordnungErsterPoint contains information on which point column i starts
Select Case arrpairings(i, 2)
Case "5":
pts(arrZuordnungNameErsterPoint(i, 2)).Format.Fill.BackColor.RGB = RGB(68, 154, 54) 'dunkelgrün
Case "4":
pts(arrZuordnungNameErsterPoint(i, 2)).Format.Fill.BackColor.RGB = RGB(111, 200, 96) 'hellgrün
Case "3":
pts(arrZuordnungNameErsterPoint(i, 2)).Format.Fill.BackColor.RGB = RGB(255, 255, 0) 'gelb
Case "2":
pts(arrZuordnungNameErsterPoint(i, 2)).Format.Fill.BackColor.RGB = RGB(255, 127, 80) 'orange
Case "1":
pts(arrZuordnungNameErsterPoint(i, 2)).Format.Fill.BackColor.RGB = RGB(255, 0, 0) 'rot
End Select
pts(arrZuordnungNameErsterPoint(i, 2)).Format.Fill.Solid
chtObj.Chart.Refresh 'useless
Next i
End Sub
我现在的问题:一切都像魅力一样,但只有当我之前手动将图表重置为其模板设置时。否则它将更新列的高度(就像图表本身一样),但不会改变颜色。看起来像这样:
如何将图表重置为其模板(例如右键单击并手动执行此操作)?我尝试的所有操作都会导致运行时错误“不支持此”..
我还有其他更有希望的活动吗?也许图表只有在 SheetActive 事件触发后才会更新?我通过按钮单击工作表本身进行了尝试,但没有任何改进。
我真的对这种图表的行为感到困惑。宏记录器几乎没有用。我也发现很少有关于旭日的文档,所以你是我最后的希望。 任何帮助表示赞赏!
【问题讨论】:
标签: vba sunburst-diagram