VBA Изменить цвет линии Sourcedata - PullRequest
0 голосов
/ 03 марта 2020

Попытка изменить строку моих полных серий sourcedata rangey3.

Я пытался использовать:

.Format.Line.ForeColor.RGB = RGB(56, 182, 75)
.MarkerBackgroundColor = RGB(56, 182, 75)

безрезультатно, но это работает для прогнозируемых значений.

Мой код:

ActiveSheet.Shapes.AddChart2(332, xlLineMarkers).Select
With ActiveChart
.SetSourceData Source:=rangey3
' Must have this as we will be using different series inside of this chart from here on out
.FullSeriesCollection(1).Name = "Demand"
' This is the first series of the full series collection
.SeriesCollection(1).XValues = rangex
.SeriesCollection.NewSeries
' Creates legend at the bottom of the chart
.SetElement (msoElementLegendBottom)
' Deletes the chart title as per the illustration in Assignment 2's illustration screenshot
.ChartTitle.Delete

' Creates the line Demand (Forecast)
With .SeriesCollection(2)
    .Name = "Demand (Forecast)"
    .Values = rangey2
    .Format.Line.Visible = msoTrue
    ' Makes the forecast line distinguishable by dotting it
    .Format.Line.DashStyle = msoLineSysDot
    .Format.Line.ForeColor.RGB = RGB(56, 182, 75)
    .MarkerBackgroundColor = RGB(56, 182, 75)
End With

1 Ответ

1 голос
/ 03 марта 2020

Использовать для каждого оператора.

Dim Srs As Series

ActiveSheet.Shapes.AddChart2(332, xlLineMarkers).Select
With ActiveChart
    .SetSourceData Source:=rangey3
    ' Must have this as we will be using different series inside of this chart from here on out
    .FullSeriesCollection(1).Name = "Demand"
    ' This is the first series of the full series collection
    .SeriesCollection(1).XValues = rangex
    .SeriesCollection.NewSeries
    ' Creates legend at the bottom of the chart
    .SetElement (msoElementLegendBottom)
    ' Deletes the chart title as per the illustration in Assignment 2's illustration screenshot
    .ChartTitle.Delete

    ' Creates the line Demand (Forecast)
    With .SeriesCollection(2)
        .Name = "Demand (Forecast)"
        .Values = rangey2
        .Format.Line.Visible = msoTrue
    End With
    ' Makes the forecast line distinguishable by dotting it
    For Each Srs In .SeriesCollection
        With Srs
            .Format.Line.DashStyle = msoLineSysDot
            .Format.Line.ForeColor.RGB = RGB(56, 182, 75)
            .MarkerBackgroundColor = RGB(56, 182, 75)
        End With
    Next Srs
End With
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...