chartjs-plugin-streaming icon indicating copy to clipboard operation
chartjs-plugin-streaming copied to clipboard

Problem with types

Open evergreen165 opened this issue 3 years ago • 0 comments

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() }, }); }); }, }, }, }, }

evergreen165 avatar Jul 23 '22 15:07 evergreen165