I am making a dashboard with react, I want to have doughnut charts that display some information. I am following this tutorial that uses chartjs
and I have ran into an unexpected problem.
When I run my app, the dashboard does not display the doughnut chart, however if I add a Line graph or bar chart, they display as expected
This is the dashboard when trying to rendering a doughnut chart, I have circled what I think is the canvas for the chart
This is the code
import React from 'react';
import {Pie, Doughnut} from 'react-chartjs-2';
const state = {
labels: ['January', 'February', 'March',
'April', 'May'],
datasets: [
{
label: 'Rainfall',
backgroundColor: [
'#B21F00',
'#C9DE00',
'#2FDE00',
'#00A6B4',
'#6800B4'
],
hoverBackgroundColor: [
'#501800',
'#4B5000',
'#175000',
'#003350',
'#35014F'
],
data: [65, 59, 80, 81, 56]
}
]
}
export default class App extends React.Component {
render() {
return (
<div>
<Doughnut
data={state}
options={{
width:"400",
height:"400",
responsive: true,
maintainAspectRatio: true,
title:{
display:true,
text:'Average Rainfall per month',
fontSize:20
},
legend:{
display:true,
position:'right'
}
}}
/>
</div>
);
}
}
I have looked at the following solution found on the following question, but it is still not working. Note that the pie chart is also not displaying correctly, only bar and line charts display correctly
Can't resize react-chartjs-2 doughnut chart
TL;DR: Chart-js in react not showing doughnut chart but other charts work.