图表无法解释标签值的日期

图表无法解释标签值的日期

我有一系列日期,我想将其用作图表上的标签。但是,当我尝试将其选为轴标签时,它不会被解释为日期,如下图所示:

在此处输入图片描述

有人能解释一下这是怎么回事吗?绘制的轴是文本轴,因此具有相同值的后续单元格不应该是问题。

源数据通过宏放入数据表中,大致如下:

Sub settInnIGraf(ws As Worksheet, R As Range)
  Dim C As Range
  Dim kortsone As Range, langsone As Range
  Set kortsone = R.Offset(0, 4).Resize(R.Rows.Count, 8)

  If IsEmpty(R) Then
    R.Resize(1, 21).Formula = "=na()"
  Else
    For Each C In Union(kortsone, langsone)
      If (Not IsNumeric(C)) Or Len(C) <= 0 Then
        C.Formula = "=na()"
      End If
    Next C
  End If
  With ws.ChartObjects("Kortsone" & Right(ws.CodeName, 1)).Chart
    Call settInnISerie(.SeriesCollection("Toppsuging"), R, kortsone.Columns(2))
    Call settInnISerie(.SeriesCollection("Nedsuging"), R, kortsone.Columns(4))
    Call settInnISerie(.SeriesCollection("Opptak"), R, kortsone.Columns(6))
    Call settInnISerie(.SeriesCollection("Botnsuging"), R, kortsone.Columns(8))
    .Axes(xlValue).MinimumScale = -30
    .Axes(xlValue).MaximumScale = 10
    .Axes(xlValue, xlSecondary).MinimumScale = .Axes(xlValue, xlPrimary).MinimumScale
    .Axes(xlValue, xlSecondary).MaximumScale = .Axes(xlValue, xlPrimary).MaximumScale
  End With
End Sub

Sub settInnISerie(srs As Series, xverdier As Range, yverdier As Range)
  Dim C As Range
  Dim i As Long

  srs.XValues = xverdier
  srs.Values = yverdier
  i = 1

  If srs.HasDataLabels Then
    srs.DataLabels.Delete
  End If
  srs.ApplyDataLabels
  For Each C In yverdier.Offset(0, -1).Cells
    If Not IsError(C) And i <= srs.Points.Count Then
      srs.Points(i).DataLabel.Text = "=" & Replace(C.Address(external:=True), "[" & ThisWorkbook.Name & "]", "", 1, -1, vbTextCompare)
    End If
    i = i + 1
  Next C
End Sub

相关内容