系列VBA散点图之间的不同颜色

我有下面的macros,它绘制了三列的散点图。 一列(AL13,向下)在x轴上。 我怎样才能把它的另外两列(AK和AM)绘制到相同的分散? 也以不同的颜色相互对待? 谢谢

Sub Graphing() Set rng4 = ActiveSheet.Range(Range("AP13"), Range("AV33")) With ActiveSheet.ChartObjects.Add(Left:=rng4.Left, Width:=rng4.Width, Top:=rng4.Top, Height:=rng4.Height) .Chart.ChartType = xlXYScatter .Chart.HasLegend = False .Chart.Axes(xlCategory).TickLabels.Font.Size = 18 .Chart.Axes(xlValue).TickLabels.Font.Size = 18 Set srs = .Chart.SeriesCollection.NewSeries srs.Values = Range(Range("AK13"), Range("AK13").End(xlDown)) srs.XValues = Range(Range("AL13"), Range("AL13").End(xlDown)) srs.Values = Range(Range("AM13"), Range("AM13").End(xlDown)) End With End Sub 

我会重新发布我修改过的代码,谢谢你的信任:)

 Sub Graphing() 'Declare all the variables to be used:' Dim rng4 as Range Dim srs as Series Dim cht as Chart Dim xVals as Range Dim srsVals as Range 'Set the chart's data range:' Set rng4 = ActiveSheet.Range(Range("AP13"), Range("AV33")) 'Set the range variable to contain the series values' ' You can later modify this to include any number of columns, and the ' ' loop structure below will add each column as a series to the chart.' Set srsVals = ActiveSheet.Range(Range("AL13"),Range("AM13").End(xlDown)) 'Set the cht variable:' Set cht= ActiveSheet.ChartObjects.Add(Left:=rng4.Left, Width:=rng4.Width, Top:=rng4.Top, Height:=rng4.Height).Chart 'Set the Range variable for xValues: Set xVals = Range(Range("AK13"),Range("AK13").End(xlDown)) 'Format the chart and add series to the chart by iterating over the columns in srsVals:' With cht .ChartType = xlXYScatter .HasLegend = False .Axes(xlCategory).TickLabels.Font.Size = 18 .Axes(xlValue).TickLabels.Font.Size = 18 'Create the series in a loop For c = 1 to srsVal.Columns.Count Set srs = .SeriesCollection.NewSeries With srs .Values = xVals .XValues = Range(srsVals.Columns(c).Address) .Name = "Series " & c '<-- Modify as needed.' End With Next End With End Sub 

我发现,如果我将这个系列设置为两个独立的系列,那么它将会同时绘制两个系列并给它们不同的颜色。 不知道这是否是最有效的方式,但它的工作原理。

  Sub Graphing() 'Declare all the variables to be used:' Dim rng4 as Range Dim srs as Series Dim cht as Chart Dim xVals as Range Dim srsVals as Range 'Set the chart's data range:' Set rng4 = ActiveSheet.Range(Range("AP13"), Range("AV33")) 'Set the range variable to contain the series values' ' You can later modify this to include any number of columns, and the ' ' loop structure below will add each column as a series to the chart.' Set srsVals = ActiveSheet.Range(Range("AL13"),Range("AM13").End(xlDown)) 'Set the cht variable:' Set cht= ActiveSheet.ChartObjects.Add(Left:=rng4.Left, Width:=rng4.Width, Top:=rng4.Top, Height:=rng4.Height).Chart 'Set the Range variable for xValues: Set xVals = Range(Range("AK13"),Range("AK13").End(xlDown)) 'Format the chart and add series to the chart by iterating over the columns in srsVals:' With cht .ChartType = xlXYScatter .HasLegend = False .Axes(xlCategory).TickLabels.Font.Size = 18 .Axes(xlValue).TickLabels.Font.Size = 18 'Create the series in a loop For c = 1 to srsVal.Columns.Count Set srs = .SeriesCollection.NewSeries With srs .Values = xVals .XValues = Range(srsVals.Columns(c).Address) .Name = "Series " & c '<-- Modify as needed.' End With Next End With End Sub