问题是你正在绘制这个PlotBy:=xlRows,而你应该使用PlotBy:=xlColumns。
因为使用 PlotBy:=xlRows,您将拥有 1196 系列,即使它有效,也不会与任何事情相关。使用 PlotBy:=xlColumns,您将只有 1 个 Serie 包含所有数据点。
我一般以此为基础,我为你调整了第一个块,其余的都在那里供参考:
Sub Graph()
Dim Gr As Chart, _
Sr As Series, _
Src_Name As String
Src_Name = "Sheet1"
Set Gr = ActiveWorkbook.Charts.Add
With Gr
'----Source Data Definition
.SetSourceData Source:=Range(Sheets(Src_Name).Cells(2, 1), Sheets(Src_Name).Cells(1197, 2)), PlotBy:=xlColumns
'----Graph Type
.ChartType = xlXYScatterSmoothNoMarkers
'----Location/Placement
.Location Where:=xlLocationAsNewSheet, Name:="NewSheetName"
'----Title
.HasTitle = True
.ChartTitle.Characters.Text = "Chart Title"
'----Data Series 1
Set Sr = .SeriesCollection.NewSeries
With Sr
.Values = Range(Sheets(Src_Name).Cells(2, 2), Sheets(Src_Name).Cells(20, 5))
.XValues = Range(Sheets(Src_Name).Cells(2, 1), Sheets(Src_Name).Cells(20, 1))
.AxisGroup = 1
.Name = "MTTF"
End With
'----Data Series 2
Set Sr = .SeriesCollection.NewSeries
With Sr
.Values = Range(Sheets(Src_Name).Cells(2, 2), Sheets(Src_Name).Cells(20, 5))
.XValues = Range(Sheets(Src_Name).Cells(2, 1), Sheets(Src_Name).Cells(20, 1))
.Name = "MTTR"
'----Placing a Serie on Second axis
.AxisGroup = 2
End With
'----Series' formats
'.SeriesCollection(i).Delete
'----For a line type chart
'.SeriesCollection(i).Format.Line.Weight = 1
'.SeriesCollection(i).Format.Line.ForeColor.RGB = RGB(int1 as integer, int1 as integer, int3 as integer)
'----For an area type chart
'.SeriesCollection(i).Format.Fill.ForeColor.RGB = RGB(int1 as integer, int1 as integer, int3 as integer)
'----Axis parameters
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Age"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Hours"
.PlotArea.Interior.ColorIndex = 2
.Axes(xlValue).MajorGridlines.Border.LineStyle = xlDot
.ChartArea.Font.Size = 14
.Deselect
'----Legend positioning
With .Legend
.Left = 350
.Top = 75
End With
'----Drawing area positiong
With .PlotArea
.Width = 550
.Height = 350
End With
End With
'----Free memory
Set Gr = Nothing
Set Sr = Nothing
End Sub