Use array as X axis and not having it show up as “Series 1”

十年热恋 提交于 2021-02-11 14:21:14

问题


I'm creating a line graph and I use a 2d array with three arrays in it. The first one contain dates and it's supposed to be the X axis, the next two is the data that should be shown as lines on the graph. Everything works as it should, except for one thing. On the side of the graph you see the names of three series, "Series1" (the dates), "Delivery speed" and "Delivery Average". I only want to show the names of the last two series not the first one.

Is it possible to only use the first array as the X axis only and not have it show up as a label?

Here's the code:

Set myChart = Graf.Shapes.AddChart(Left:=20, Top:=53, Width:=1000, Height:=400)
    With myChart.Chart
        For i = 1 To UBound(AllDataLists, 2)
            If i = 1 Then
                ReDim actualdate(1 To UBound(AllDataLists, 1)) As Date
                For j = 1 To UBound(AllDataLists, 1)
                    actualdate(j) = AllDataLists(j, i)
                Next j
            Else
                ReDim actualdata(1 To UBound(AllDataLists, 1)) As Integer
                For j = 1 To UBound(AllDataLists, 1)
                    actualdata(j) = AllDataLists(j, i)
                Next j
            End If

                .SeriesCollection.NewSeries
            If i = 1 Then
                .SeriesCollection(i).XValues = actualdate
            Else
                
                .SeriesCollection(i).Values = actualdata
                .SeriesCollection(i).ChartType = xlLine
                .SeriesCollection(i).Name = NewDataLabel(i - 1)
            End If
            
            
            .SeriesCollection(i).AxisGroup = 1
            
            
        Next i
    End With

actualdate is the array with the dates. actualdata is the array with the data. NewDataLabel is an array containing the strings "Delivery Speed" and "Delivery Average". AllDataLists is the 2d array that contains all the data.


回答1:


You don't need the "NewSeries" command for the x-Axis (i=1)!

Sub AddChart2()

    Dim myChart
    Set myChart = ActiveSheet.Shapes.AddChart(Left:=20, Top:=53, Width:=1000, Height:=400)
    
    With myChart.Chart

        .SeriesCollection.NewSeries
        .ChartType = xlColumnClustered
        .SeriesCollection(1).XValues = "{43831,43862,43891,43922,43952}"
        .SeriesCollection(1).Values = "{-10,10,30,50,70}"
        .Axes(xlCategory).TickLabels.NumberFormat = "DD.MM.YYYY"
    
        .SeriesCollection.NewSeries
        .SeriesCollection(2).XValues = "{43831,43862,43891,43922,43952}"
        .SeriesCollection(2).Values = "{-20,20,60,100,140}"
    End With
End Sub



来源:https://stackoverflow.com/questions/63104763/use-array-as-x-axis-and-not-having-it-show-up-as-series-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!