highcharts - 自动绘制累积数据
问题描述
我正在绘制一个图表,系列数据如下所示,其中时间间隔为一小时,与每个时间戳关联的数字是网站的访问次数。
[
[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 点,等等。
有谁知道是否有任何设置可以实现这一目标?
解决方案
此功能应该很快在 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/
推荐阅读
- bash - 如何使用相同的文件列表将目录“同步”到多个目标目录?
- python-3.x - 使用循环删除字符串中的多余空格
- amazon-s3 - 如何以相同的文件名但不同的路径在本地保存 S3 文件
- nginx - 重写 url 删除前缀和代理通行证
- migration - 如何将 Bitbucket 迁移到 DMZ 服务器
- javascript - SubtleCrypto 带有 rsa/ecb/oaepwithsha-256andmgf1padding
- swiftui - 屏幕外元素中的 SwiftUI 列表问题
- node.js - 使用 Angular/node 修改 Excel
- python - 如何从元组列表创建列表
- node.js - heroku 上的 nodejs 部署失败