0👍
✅
According to Chart.js documentation:
For a pie chart, datasets need to contain an array of data points. The data points should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each.
You also need to specify an array of labels so that tooltips appear correctly.
Please have a look at your amended code below that works fine now.
new Chart(document.getElementById('LossProfit'), {
type: 'pie',
data: {
labels: ['AAA', 'BBB'],
datasets: [{
data: [20, 40],
backgroundColor: ["#1a5279", "#f78159"]
}],
},
options: {
responsive: true
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="LossProfit" height="100"></canvas>
Source:stackexchange.com