【问题标题】:Change color of data series in excel xyscatter chart更改excel xy散点图中数据系列的颜色
【发布时间】:2015-04-17 01:58:16
【问题描述】:

我正在尝试更改 Excel 图表中数据点的颜色,但我尝试的一切都不成功。

这是我尝试的一种方法,但点仍然显示为蓝色:

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

这是我尝试的另一种方法,但数据点仍然显示为蓝色:

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)

这只是我的代码的一部分,如果需要,我可以提供其他区域。任何帮助将不胜感激。

【问题讨论】:

  • 将第一个示例中的最后一个 With 选择块替换为这一行 .SeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) 它适用于我创建的一个简单示例。
  • 非常感谢!这行得通!我仍然很好奇为什么我使用的东西是不可接受的。如果你知道,我很乐意听到,但如果没有,请不要担心。

标签: vba excel graph


【解决方案1】:

我认为问题在于嵌套的 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

这里是 Microsoft's documentation link 讨论完全限定的嵌套 With 块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-05
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多