Excel VBA图表XVALUES AREN' t正确对齐

发布于 2025-02-13 22:50:40 字数 2271 浏览 0 评论 0原文

我有大量的数据正在尝试通过动态制作图表。每个列值都与特定的时间值对齐。有一个称为“类型”的列,可以容纳一个空单元格,“ log”,“ log+”,“ srst”,“ arst”或“ wrst”,我希望与其他用户一起绘制在图表上定义的列在指定的时间范围内。

到现在为止“ 价值。

这是我现在所拥有的,我不确定为什么它不将它们与适当的值保持一致:

' This entire section is in a With block for the chart in another sub with the sub check in it's own sub
' I just felt like it's extra unnecessary stuff to add
Dim c4X As Range
Dim c5X As Range
Dim c6X As Range
Dim c7X As Range
Dim c8X As Range

' yFollow is the column that the events (c4-8X) are plotted on the Y axis with
' sh is the worksheet
For Each c In sh.Range(evChar & sIndex & ":" & evChar & eIndex)
    If c.Value = "Log " Then
        Call check(c.Row, yFollow, sh, c4X)
    ElseIf c.Value = "Log+" Then
        Call check(c.Row, yFollow, sh, c5X)
    ElseIf c.Value = "SRst" Then
        Call check(c.Row, yFollow, sh, c6X)
    ElseIf c.Value = "ARst" Then
        Call check(c.Row, yFollow, sh, c7X)
    ElseIf c.Value = "WRst" Then
        Call check(c.Row, yFollow, sh, c8X)
    End If
Next c

' I'm aware this is a poor way, just make a function. I will change it after I figure this out
If Not c4X Is Nothing Then
    .SeriesCollection(i).XValues = c4X
End If
If Not c5X Is Nothing Then
    .SeriesCollection(i + 1).XValues = c5X
End If
If Not c6X Is Nothing Then
    .SeriesCollection(i + 2).XValues = c6X
End If
If Not c7X Is Nothing Then
    .SeriesCollection(i + 3).XValues = c7X
End If
If Not c8X Is Nothing Then
    .SeriesCollection(i + 4).XValues = c8X
End If

Sub check(ByVal c As Long, ByVal col As String, ByVal sh As Worksheet, ByRef xRng As Range)
    If xRng Is Nothing Then
        Set xRng = sh.Range("A" & c)
    Else
        Set xRng = Union(xRng, sh.Range("A" & c))
    End If
End Sub

您可以在Excel中看到值是由于某种原因在这里。 悬停在点时,在这里您可以看到应该是的实际时间值。 该图总体看起来像 this 。图上的art点是从12:40:00开始的。悬停时,它显示值为12:40:21。右键单击图并选择数据时,它显示值为12:40:00-12:40:02。

我真的不确定为什么在设置值正确的值时,悬停在点上,而不是实际绘制的值。

I've got a large set of data that I'm trying to go through to dynamically make a chart out of. Each column value is aligned with a specific time value. There is a column called "Type" that hold either an empty cell, "Log ", "Log+", "SRst", "ARst", or "WRst" that I'm looking to plot onto the chart along with other user-defined columns in a specified time range.

So far I can get the chart to plot properly, but no matter the X time value, it always shows up at the first index time value, then the second, then third and so on up until the n'th appearance of that "Type" value.

Here is what I have right now and I'm not sure why it isn't aligning them to the appropriate values:

' This entire section is in a With block for the chart in another sub with the sub check in it's own sub
' I just felt like it's extra unnecessary stuff to add
Dim c4X As Range
Dim c5X As Range
Dim c6X As Range
Dim c7X As Range
Dim c8X As Range

' yFollow is the column that the events (c4-8X) are plotted on the Y axis with
' sh is the worksheet
For Each c In sh.Range(evChar & sIndex & ":" & evChar & eIndex)
    If c.Value = "Log " Then
        Call check(c.Row, yFollow, sh, c4X)
    ElseIf c.Value = "Log+" Then
        Call check(c.Row, yFollow, sh, c5X)
    ElseIf c.Value = "SRst" Then
        Call check(c.Row, yFollow, sh, c6X)
    ElseIf c.Value = "ARst" Then
        Call check(c.Row, yFollow, sh, c7X)
    ElseIf c.Value = "WRst" Then
        Call check(c.Row, yFollow, sh, c8X)
    End If
Next c

' I'm aware this is a poor way, just make a function. I will change it after I figure this out
If Not c4X Is Nothing Then
    .SeriesCollection(i).XValues = c4X
End If
If Not c5X Is Nothing Then
    .SeriesCollection(i + 1).XValues = c5X
End If
If Not c6X Is Nothing Then
    .SeriesCollection(i + 2).XValues = c6X
End If
If Not c7X Is Nothing Then
    .SeriesCollection(i + 3).XValues = c7X
End If
If Not c8X Is Nothing Then
    .SeriesCollection(i + 4).XValues = c8X
End If

Sub check(ByVal c As Long, ByVal col As String, ByVal sh As Worksheet, ByRef xRng As Range)
    If xRng Is Nothing Then
        Set xRng = sh.Range("A" & c)
    Else
        Set xRng = Union(xRng, sh.Range("A" & c))
    End If
End Sub

You can see in excel the values are the starting time for some reason here.
When hovering a point, here you can see the actual time value it should be.
The graph as a whole looks like this. The ARst point on the graph is starting at 12:40:00. When hovering, it shows the value is 12:40:21. When right clicking the graph and selecting data, it shows the values to be 12:40:00-12:40:02.

I'm really unsure why when I'm setting the values that it's correct on point hovers, but not when it's actually plotted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文