highcharts 柱形图,动态数据列对齐关闭

发布于 2025-01-05 03:48:47 字数 1473 浏览 0 评论 0原文

我希望这个快速描述和图像能够给遇到类似问题的人敲响警钟,从而提出建议/修复。

我有一个柱形图,我正在动态添加数据(通过 jQuery 解析 XML 文件)。

由于某种原因,添加数据后,不同系列的对齐方式会有些偏差。在我通过可见/不可见(通过单击图例中的系列)切换其中一个系列后,问题自行解决。

当我通过对数字进行硬编码来添加数据时,只是为了确保它有效,它效果很好。

这是图像: 在此处输入图像描述

黄色系列是最后添加到图表中的系列,切换后红色和紫色系列可以正常排列5系列之一的知名度。

任何帮助将不胜感激!

更新数据信息:

  • 我有 5 个数据系列和 10 个 x 轴类别,
  • 当我解析 XML 文件时,我正在构建一个多维数据数组,
  • 数组长度为 5,其中每个数据5 个索引包含一个长度为 10 的数组,
  • 这是数组填充数据后的样子:

index#: 0 value: 0,0,0,0,0,0,0,0,0,0

index# : 1值:180,210,0,0,0,0,0,0,180,210

索引号:2 值:22,4,0,0,0,0,0,0,22,4

索引号:3 值:0,0, 0,0,0,0,0,0,0,0

索引#: 4 值: 200,30,0,0,0,0,0,0,4,0

我是使用以下JS代码将数据添加到图表中:

for (var c_ary_bs = 0; c_ary_bs < ary_bs_schedule_orig.length; c_ary_bs++) {
        chart.series[c_ary_bs].setData(ary_bs_schedule_orig[c_ary_bs]);
    }

希望对您有所帮助,谢谢!

更新2,更多信息

我已经对添加到数组的数据进行了硬编码,以帮助查明问题:

    chart.series[0].setData([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
    chart.series[1].setData([180, 210, 0, 0, 0, 0, 0, 0, 180, 210]);
    chart.series[2].setData([22, 4, 0, 0, 0, 0, 0, 0, 22, 4]);
    chart.series[3].setData([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
    chart.series[4].setData([200, 30, 0, 0, 0, 0, 0, 0, 4, 0]);
    alert('done')

当警报触发时,在单击“确定”后,图表列会正确对齐要消除警报,就会发生对齐问题,如上图所示。

i'm hoping that this quick description and image will ring a bell with someone who has had a similar issue and therefore a suggestion/fix.

i have a column graph that i am adding data to dynamically (via jQuery parsing an XML file).

for some reason, after the data is added, the alignment of the different series gets a little off. the issue fixes itself after i toggle one of the series by being visible/invisible (by clicking the series in the legend).

when i add the data via hardcoding the numbers, just to ensure it works, it works great.

here is the image:
enter image description here

the yellow series is the last series added to the chart, the red and purple series line up ok after toggling the visibility of one of the 5 series.

any help would be greatly appreciated!

UPDATE with info on the data:

  • i have 5 series of data and 10 x-axis categories
  • i am building a multidimensional array of data as i parse the XML file
  • the array length is 5, with each of those 5 index's containing an array of length 10
  • this is what the array looks like after it has been populated with data:

index#: 0 value: 0,0,0,0,0,0,0,0,0,0

index#: 1 value: 180,210,0,0,0,0,0,0,180,210

index#: 2 value: 22,4,0,0,0,0,0,0,22,4

index#: 3 value: 0,0,0,0,0,0,0,0,0,0

index#: 4 value: 200,30,0,0,0,0,0,0,4,0

i am adding the data to the chart with the following JS code:

for (var c_ary_bs = 0; c_ary_bs < ary_bs_schedule_orig.length; c_ary_bs++) {
        chart.series[c_ary_bs].setData(ary_bs_schedule_orig[c_ary_bs]);
    }

hopefully that will help, thank you!

UPDATE 2, some more info

i've hard coded the data being added to the array, to help pinpoint the issue:

    chart.series[0].setData([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
    chart.series[1].setData([180, 210, 0, 0, 0, 0, 0, 0, 180, 210]);
    chart.series[2].setData([22, 4, 0, 0, 0, 0, 0, 0, 22, 4]);
    chart.series[3].setData([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
    chart.series[4].setData([200, 30, 0, 0, 0, 0, 0, 0, 4, 0]);
    alert('done')

when the alert fires, the graph columns are aligned properly, after I click "ok" to dismiss the alert, the alignment issue happens, as the previous image depicts.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我最亲爱的 2025-01-12 03:48:47

我发现了一个不完美的修复:

- 将图表的 marginLeft 设置为 70 可以缓解列未对齐的问题

- 由于某种原因,y 轴标题文本显示在 y 轴刻度上,因此我使用以下方法来制作它可见:(

 yAxis: {
        title: {
            x:-20,
            text: 'Schedule Days'
        }
    }

注意x:-20)

奇怪的是,当我切换其中一个系列(通过在图例中单击它)时,yAxis标题文本恢复到它应该在的位置(现在偏离了20px,因为上述修复)。

完美的修复方法是将 yAxis 文本放置在我切换系列之一之后的位置,但至少这样,无论用户是否切换系列,它现在都是可见的。

I found an imperfect fix:

-setting the marginLeft of the chart to 70 alleviates the issue with the columns not aligning

-for some reason the y-axis title text is displaying over the y-axis ticks, so i am using the following to make it visible:

 yAxis: {
        title: {
            x:-20,
            text: 'Schedule Days'
        }
    }

(note the x: -20)

Whats's odd is that when I toggle one of the series (by clicking it in the legend) the yAxis title text reverts to where it should be (which is now 20px off because of the above fix).

The perfect fix would put the yAxis text where it is after I toggle one of the series, but at least this way it is now visible regardless of whether or not the user toggles the series.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文