Chartjs-How to update JS variable in value field of charts.js?

1👍

Try giving doughnutData its new configuration data before you create the new chart.

function updateBreakdown() {

            // create the graph from scratch
            doughnutChart.destroy();
            var doughnutData = [
               {
                  value: something,
                  label: 'My something Label',
                  color: '#811BD6'
               },
               {
                  value: other,
                  label: 'My other label',
                  color: '#D18177'
               }
            ];
            doughnutChart = new Chart(ctx).Doughnut(doughnutData, {
                percentageInnerCutout: 55
            });

 }

And make this changes:

if ($('#something').is(':checked')) {
          //var something = 25;//replace these
            something = 25;//with these
      } else {
          //var something = 0;
            something = 0;
      }

       if ($('#other').is(':checked')) {
          //var other= 5;
            other= 5;
      } else {
          //var other= 0;
            other= 0;
      }

Leave a comment