如何在VBA中格式化日暴图?
我正在拼命尝试通过VBA格式化一张太阳暴流图。根据点数,我希望列使用我的一种颜色,从绿色到红色 图表所基于的数据在另一个工作表中指定,因此,一旦图表工作表被激活,我将格式化图表如何在VBA中格式化日暴图?,vba,sunburst-diagram,Vba,Sunburst Diagram,我正在拼命尝试通过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 thi
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事件后图表才会更新?我试着通过按钮点击表单本身,但没有改善
我真的被这种图表的行为弄糊涂了。宏记录器几乎没有用。我也发现很少有关于太阳风暴的文档,所以你是我最后的希望。
感谢您的帮助 我很偶然地找到了解决办法 出于我无法理解的原因,命令
pts(arrzuordnugnameersterpoint(i,2)).Format.Fill.Solid
阻止VBA正确更改颜色。使用模式而不是。Solid
可以完成此任务
For i = LBound(arrData, 1) To UBound(arrData, 1)
pts(arrZuordnungNameErsterPoint(i, 2)).Format.Fill.Patterned msoPattern5Percent
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
Next i