X轴标签未显示在散线图中

时间:2019-06-14 17:17:08

标签: excel vba

我正在使用来自多个工作表的一些数据制作散线图。每个工作表中的数据都存储在一个集合中,而该集合则存储在一个集合数组中。然后循环遍历集合数组,以用数据填充图形。

我很确定我具有更改x轴标签的语法权利,但是由于某种原因,它显示为数字。但是,当我将鼠标悬停在图形中的数据点上时,会出现正确的标签。有什么想法吗?

更新:将图形类型更改为xlLine并得到了我的标签。散线图一定是一些奇怪的格式。

Private Sub CommandButton2_Click()

Dim currentWorksheet As Worksheet
WS_Count = ActiveWorkbook.Worksheets.Count

Dim rows As Integer
rows = WS_Count - 3
Dim itemsFoundList() As String
Dim itemsSold() As Integer
Dim numItems As String
Dim counter As Integer
Dim chart As chart

Dim masterArray() As Collection
ReDim masterArray(0 To WS_Count - 1)

Dim itemList As Collection

Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets.Add(After:= _
         ActiveWorkbook.Sheets(ThisWorkbook.Sheets.Count))
ws.Name = "Chart"

counter = 1

     For i = 3 To WS_Count - 1 'Loops through all sheets and grabs data from tables'

        Set currentWorksheet = ActiveWorkbook.Worksheets(i)
        Set itemList = New Collection

        numItems = numberOfItems(currentWorksheet, "Drink", "I2", "I18")

        ReDim itemsFoundList(0 To CInt(numItems) - 1)
        ReDim itemsSold(0 To CInt(numItems) - 1)


        itemsFoundList = itemsFound(currentWorksheet, "Drink", "I2", "I18", CInt(numItems), "A")
        itemsSold = itemsSoldFound(currentWorksheet, "Drink", "I2", "I18", CInt(numItems), "E")

        itemList.Add itemsFoundList          'Adds arrays of data to Collection'
        itemList.Add itemsSold
        itemList.Add currentWorksheet.Name

        Set masterArray(counter) = itemList 'Adds collection to array and iterates'

        counter = counter + 1

     Next i

     Set chart = ws.Shapes.AddChart.chart
         With chart
        .ChartType = xlXYScatterLines
     End With

     counter = 1 'Collection iterator'

     For i = 1 To 7
         With chart
        .SeriesCollection.NewSeries
        .SeriesCollection(i).Name = masterArray(counter)(3)
        .SeriesCollection(i).XValues = masterArray(counter)(1)
        .SeriesCollection(i).Values = masterArray(counter)(2)

     End With

     counter = counter + 1
     Next i


End Sub

0 个答案:

没有答案