首页 > 解决方案 > 自动绘制累积数据

问题描述

我正在绘制一个图表,系列数据如下所示,其中时间间隔为一小时,与每个时间戳关联的数字是网站的访问次数。

[
[1631138400000, 8], // 2am today
[1631142000000, 3], // 3am today
[1631145600000, 2], // 4am today
[1631149200000, 4], // 5am today
[1631152800000, 5], // 6am today
[1631156400000, 6], // 7am today
[1631160000000, 7], // 8am today
... ...
]

我想知道,在 Highcharts 中,是否有选项或 API 可以从上面的数据中自动绘制“累积”数据的图表。我想在图中绘制的是凌晨 2 点 8 点,凌晨 3 点 11 点,凌晨 4 点 13 点,凌晨 5 点 17 点,等等。

有谁知道是否有任何设置可以实现这一目标?

标签: highcharts

解决方案


此功能应该很快在 Highstock 中可用。有关更多信息,请查看此问题:https ://github.com/highcharts/highcharts/issues/15361

现在,您可以对数据进行预处理。例子:

const getCumulativeData = (data) => {
    const cumulativeData = [];

    data.forEach((dataEl, index) => {
        if (cumulativeData[index - 1]) {
            cumulativeData.push([dataEl[0], dataEl[1] + cumulativeData[index - 1][1]]);
        } else {
            cumulativeData.push(dataEl);
        }
    });

    return cumulativeData;
};

现场演示:http: //jsfiddle.net/BlackLabel/846cgxhL/


推荐阅读