我对react-chartjs-2和chartjs-plugin-streaming有问题,我的目标是创建一个带有流的实时图表,但它最终出错了,我不太知道为什么。无论如何,我的进口是这样的:
import { Chart, Bubble } from 'react-chartjs-2';
import ChartStream from 'chartjs-plugin-streaming';
Run Code Online (Sandbox Code Playgroud)
那么下面就是这部分:
Chart.pluginService.register(ChartStream);
Run Code Online (Sandbox Code Playgroud)
然后组件渲染中有这部分
<Bubble
data={{
labels: ['demo'],
datasets: [{
backgroundColor: 'rgba(75,192,192,1)',
data: []
}]
}}
options={{
plugins: {
streaming: {
onRefresh: function(chart) {
chart.data.datasets[0].data.push({
x: Date.now(),
y: Math.random() * 100,
r: 5
});
},
delay: 500,
refresh: 1000,
frameRate: 30,
duration: 3600000 // 3600000 = 1hour
}
},
scales: {
xAxes: [{
type: 'realtime',
id: 'x-axis-0'
}]
}
}}
/>
Run Code Online (Sandbox Code Playgroud)
导航时发生的第一个错误是:
未捕获的类型错误:无法在 core.controller.js:51 在 Array.forEach () at n …