Chartjs-I want to make a stacked bar graph which has target of 60 using chart js

0👍

Yes you can simply calculate this before sending it to chart.js to chart it:

(function() {
  const ctx = document.getElementById("mychart");

  const datas = {
    labels: ['Passed', 'Failed', 'In Progress'],
    datasets: [{
      label: 'Data',
      data: [10, 5, 80],
      backgroundColor: [
        "green",
        "red",
        "yellow"
      ],
    }, ]
  };

  const newData = datas.datasets[0].data.map(e => (e >= 60 ? 0 : 60 - e))

  datas.datasets.push({
    label: 'extra',
    backgroundColor: 'red',
    data: newData
  })

  const chr = new Chart(ctx, {
    data: datas,
    type: 'bar'
  });
})();

<div style="width: 500px;height: 300px">
  <canvas id="mychart"></canvas>
</div>

Leave a comment