nagix / chartjs-plugin-streaming

Chart.js plugin for live streaming data
MIT License
515 stars 130 forks source link

Problem with types #169

Open antonioGabrielGomes opened 1 year ago

antonioGabrielGomes commented 1 year ago

Hello, I'm using react with typescript. I load the dataset by useState. and I also have the options in a useState, but they will be dynamic with the call in the api.

The error:

TS2322: Type '{ x: number; y: number; }' is not assignable to type 'never[]'. Object literal may only specify known properties, and 'x' does not exist in type 'never[]'. chartCpuData.datasets.forEach(dataset => { dataset.data.push({ data: { x: Date.now(), y: Math.random() }, ^^^^^^^^^^^^^ }); }); },

have tree datasets { datasets: [ { data: [ { label: 'Dataset 1', backgroundColor: 'rgba(255, 99, 132, 0.5)', borderColor: 'rgb(255, 99, 132)', borderDash: [8, 4], fill: true, data: [], }, ], }, { data: [ { label: 'Dataset 2', backgroundColor: 'rgba(54, 162, 235, 0.5)', borderColor: 'rgb(54, 162, 235)', cubicInterpolationMode: 'monotone', fill: true, data: [], }, ], }, { data: [ { label: 'Dataset 3', backgroundColor: 'rgba(54, 162, 235, 0.5)', borderColor: 'rgb(54, 162, 235)', cubicInterpolationMode: 'monotone', fill: true, data: [], }, ], }, ], }

the options:

{ scales: { x: { type: 'realtime', realtime: { delay: 2000, onRefresh: () => { chartCpuData.datasets.forEach(dataset => { dataset.data.push({ data: { x: Date.now(), y: Math.random() }, }); }); }, }, }, }, }