excel - 如何通过 VBA 更改 Excel 图表中点的颜色
问题描述
由于我正在自动创建图表以比较测量数据和模拟数据,因此我希望每次有人使用脚本时数据看起来完全相同。
为此,我希望线条具有相同的颜色,例如蓝色始终是测量数据,绿色始终是模拟数据。我希望线上的所有内容都是相同的颜色,所以线以及数据都指向自己。此外,数据点有一个框架,我需要控制它的颜色或完全摆脱它。
现在,我使用以下代码:
'create first series (measurement)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = measurement_legend_title
ActiveChart.FullSeriesCollection(1).XValues = "=Peak_Torque_Values!$A$3:$A$30"
ActiveChart.FullSeriesCollection(1).Values = "=Peak_Torque_Values!$B$3:$B$30"
ActiveChart.FullSeriesCollection(1).Select
Selection.MarkerStyle = 1
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 240)
.Solid
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 240)
.Transparency = 0
End With
结果如下所示:
谁能告诉我如何更改现在为深蓝色的标记的颜色?另外,有人能告诉我如何摆脱标记周围的框架吗?Excel 中的宏记录确实对我没有帮助。
感谢你们!!
解决方案
这段代码会循环遍历数据点标记并将数据点标记更改为红色(可以通过更改代码中的 RBG() 函数来更改具体颜色。注意此代码引用了第一个系列。
Dim x As Integer
For x = 1 To ActiveChart.FullSeriesCollection(1).Points.Count
ActiveChart.FullSeriesCollection(1).Points(x).Select
Selection.MarkerStyle = 2 'Sets the style/look of the marker
With Selection.Format.Fill
.ForeColor.RGB = RGB(255, 0, 0) 'determines the color of the marker
End With
Next x
推荐阅读
- image - 如何获取下载按钮后面的图像 URL
- python - 生成具有特定限制大小的随机数
- javascript - UnhandledPromiseRejectionWarning: ReferenceError: fetch is not defined
- html - 使 facebook 评论插件响应的问题
- python - 使用 IF、ELSE 条件遍历 pandas 数据帧,然后从满足设置条件的地方获取和使用数据
- xml - 将元素转换为属性
- flutter - 未定义名称“FirebaseAuth”
- mitmproxy - 我可以为 Mitmweb 设置主题或更改标题或外观吗?
- reactjs - 如何在 Next.js 中使用带有顺风 css 的 React Suite?
- r - 扩展 `str_to...` 以包含缩写