vba 更改excel xyscatter图表中数据系列的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28543429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change color of data series in excel xyscatter chart
提问by Dimitri M
I'm trying to change the color of the data points in an excel chart but everything im trying unsuccessful.
我正在尝试更改 excel 图表中数据点的颜色,但我尝试的一切都不成功。
This is one method I tried, yet the points still appear blue:
这是我尝试过的一种方法,但点仍然显示为蓝色:
With Chrt
.ChartType = xlXYScatter
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "=""Top Platen"""
.SeriesCollection(1).Values = yaxis
.SeriesCollection(1).XValues = xaxis
ActiveChart.SeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
Here's another method I tried and still the data points appear blue:
这是我尝试过的另一种方法,但数据点仍然显示为蓝色:
With Chrt
.ChartType = xlXYScatter
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "=""Top Platen"""
.SeriesCollection(1).Values = yaxis
.SeriesCollection(1).XValues = xaxis
.SeriesCollection(1).Interior.Color = RGB(255,0,0)
This is only one segment of my code, I can supply additional areas if necessary. Any help would be greatly appreciated.
这只是我的代码的一部分,如有必要,我可以提供其他区域。任何帮助将不胜感激。
回答by Portland Runner
I believe the problem is with the nested Withblocks getting confused. Here is one way to solve it and still use nested Withblock:
我相信问题在于嵌套With块变得混乱。这是解决它并仍然使用嵌套With块的一种方法:
With Chrt
.ChartType = xlXYScatter
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.Name = "=""Top Platen"""
.Values = yaxis
.XValues = xaxis
.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
End With
Here is Microsoft's documentation linkthat talks about fully qualified nested Withblocks.
这是Microsoft 的文档链接,它讨论了完全限定的嵌套With块。

