散点图和散点图线与获得的结果不匹配

Scatter and Scatter lines dont match obtained results

我有以下代码

Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("Graphs")
Dim chrt As Chart
Set chrt = sh.Shapes.AddChart.Chart
Set s1 = chrt.SeriesCollection.NewSeries
Set s2 = chrt.SeriesCollection.NewSeries
Set s3 = chrt.SeriesCollection.NewSeries
Set s4 = chrt.SeriesCollection.NewSeries
Set s5 = chrt.SeriesCollection.NewSeries

With s1
    .ChartType = xlXYScatterLines
    'Change to what your series should be called
    .Name = "ConcreteCS"
    .XValues = "=Graphs!$E:$E"
    .Values = "=Graphs!$F:$F"
End With

With s2
    .ChartType = xlXYScatter
    .Name = "Asl_base_corner"
    .XValues = "=Graphs!$K:$K"
    .Values = "=Graphs!$L:$L"
End With

With s3
    .ChartType = xlXYScatter
    .Name = "Asl_base_mid"
    .XValues = "=Graphs!$K:$k0"
    .Values = "=Graphs!$L:$L0"
End With

With s4
    .ChartType = xlXYScatter
    .Name = "Asl_add_corner"
    .XValues = "=Graphs!$Q:$Q"
    .Values = "=Graphs!$R:$R"
End With

With s5
    .ChartType = xlXYScatter
    .Name = "Asl_add_mid"
    .XValues = "=Graphs!$Q:$Q0"
    .Values = "=Graphs!$R:$R0"
End With

With chrt
    .ChartArea.Left = 100
    .ChartArea.Top = 750
    .ChartArea.Height = 200
    .ChartArea.Width = 200
    .Axes(xlValue).MajorGridlines.Delete
    .HasAxis(xlCategory, xlPrimary) = False
    .HasAxis(xlCategory, xlSecondary) = False
    .HasAxis(xlValue, xlPrimary) = False
    .HasAxis(xlValue, xlSecondary) = False
    .Axes(xlCategory).MinimumScale = -b / 2
    .Axes(xlCategory).MaximumScale = b + b / 2
    .Axes(xlValue).MinimumScale = -h / 2
    .Axes(xlValue).MaximumScale = h + h / 2

    For ii = 1 To chrt.Legend.LegendEntries.Count Step 1
        .Legend.LegendEntries(ii).Delete
    Next

End With

但结果是散布了 s1、s2 和 s3 的线以及散布了 s4 和 s5 的线。 奇怪的是,我只为 s1 定义了带线的散点图。 此外,当我尝试删除所有系列的图例时,从索引 4 到 5 给我错误,尽管索引存在 (chrt.Legend.LegendEntries.Count = 5).

请帮帮我!!! :)

非常感谢

我认为你应该以这种方式删除 Legend :

For ii = chrt.Legend.LegendEntries.Count To 1 Step -1
        .Legend.LegendEntries(ii).Delete
    Next

But the result is scatter with lines for s1, s2 and s3 and scatter for s4 and >s5.

您确定系列 s2、s3 中的点与 s1 不在同一直线上吗? 这只是看起来像线? 要么 点很大,看起来像连接?

在我的计算机上,您的代码可以正常运行。 它很奇怪