Chartjs-Problem with chart js pie chart dataset data

0πŸ‘

βœ…

To achieve the behaviour you want you only need 1 dataset and put the sum of the data in it. If you use it like shown in this config you get the desired outcome:

const config = {
      type: 'pie',
      data: {
        labels: ['Supplier Debt', 'Raw Material Cost', 'Product Cost', 'Customer Debt'],
        datasets: [{
          backgroundColor: ["#3e95cd","#8e5ea2","#3cba9f","#e8c3b9"],
          borderWidth: 10,
          label: 'Supplier Debt',
          data: [1, 5, 3,6],

        }
        ]
      },
      options: {

        maintainAspectRatio: false,

        title: {
          display: true,
          text: 'Total'
        }
      }
    };

Chart as it should be

You might want to decrease the border with since it will make your chart look a lot better.

Leave a comment