2👍
This is because you pass null
to the Line component.
You either need to init the data with empty state or conditionally render the Line.
Initial state:
const [chartData, setChartData] = useState({
labels: [],
datasets: [{
data: []
}]
});
Conditionally render:
{chartData !== null && <Line data={chartData}/>}
- Chartjs-How to update JS variable in value field of charts.js?
- Chartjs-How to reduce spaces between grids for graph in chart.js
1👍
Not familiar with that chart library, but my guess is that it’s erroring out before your async data is returned from the API call. I would try creating valid uninitialized data to feed to the Line component on the initial render, or simply prevent the chart from loading until the data is returned. You can check if that’s your issue with something like:
{chartData && <Line
data = {chartData}
/>
}
- Chartjs-Angular – change objects to array and make it listen to on change
- Chartjs-Reduce nested object based on attribute javascript
Source:stackexchange.com