你怎样用行来代替系列?

我正在做一个VBA的Excel代码来绘制某些数据,但是即使在指定按行来绘图的时候,225个数据系列的限制也会一直显示出来,这个问题怎么解决呢?

Y=1197 Set DChart = Charts.Add With DChart .ChartType = xlXYScatterSmoothNoMarkers .SetSourceData Source:=Sheets("Sheet1").Range("A2:" & "B" & Y), PlotBy:=xlRows End With 

问题是你正在绘制这个PlotBy:=xlRows ,你应该使用PlotBy:=xlColumns

因为使用PlotBy:=xlRows ,你会有1196系列 ,即使它工作,它也不会有任何关系。 使用PlotBy:=xlColumns ,你将只有1个系列的所有数据点。

我通常把这作为一个基地,我调整了你的第一个块其余的是有信息:

 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