我试图用图表JS绘制一个图表,它有大约300000个数据点。它运行得非常慢,所以我试图通过使用数据抽取插件来提高它的性能。然而,这些数据根本没有被毁灭。
我的代码示例:
const dataset = {
datasets: {[,
data : [{
x : timetag,
y : data,
}],
id : 'id',
label: 'label',
indexAxis: 'x'
,]}
const config = {
type: 'line',
data: dataset,
options: {
// parsing: false,
animation: false,
scales : {
x: {
type: 'time',
title: {
display: true,
text: 'Time Of Day'},
},
y:{
min : 0,
},
}}};
const myChart = new Chart(
document.getElementById("Chart"),
config
);
function decimateData(myChart) {
myChart.options.plugins.decimation.algorithm = 'lttb';
myChart.options.plugins.decimation.enabled = true;
myChart.options.plugins.decimation.samples = 50;
myChart.update()
}
sample of the data structure
[
{
"x": "2022-02-24 00:00:26",
"y": "11"
},
{
"x": "2022-02-24 00:00:27",
"y": "7"
},
{
"x": "2022-02-24 00:00:28",
"y": "8"
}
]我相信1,2,3已经实现了。4、打开解析:配置中的false完全阻止了我的绘图。
我的数据结构有什么不正确,不允许图表js读取它。
任何指导都是非常感谢的
更新
下面是用于在config块中创建数据选项的函数:
function genDatasets() {
base = {
datasets: [],
parsing: false,,
fill: false};
for (var i = 0; i < sources.length; i++){
set =[{
data : [{
x : timetags,
y : data,
}],
id : sources[i].slice(0,-4),
label: sources[i].slice(0,-4),
borderColor: colours[i],
indexAxis: 'x'
,}]
base['datasets'].push(set[0]) ;
}
return base;
};发布于 2022-03-25 03:12:57
查看有关parsing:https://www.chartjs.org/docs/latest/api/interfaces/ParsingOptions.html#parsing的文档
How to parse the dataset. The parsing can be disabled by specifying parsing: false at chart options or dataset. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.解决方案:您的x轴数据(时间标记)需要“从时代开始的毫秒”,这是时间值的内部表示图表。当前,x轴数据是一个日期字符串,这就是它不能工作的原因。
https://stackoverflow.com/questions/71254033
复制相似问题