Chartjs-ChartJS changing displayed data based on dropdown selection

0👍

Try a ‘change’ event on each of the selects which loads the appropriate data for the selected option, removes the existing data from the dataset and pushes the new data onto the dataset.

        $('.team-one').change(function () {
          var sel = $(this).val();
          var newData = [];
          switch(sel) {
            case 'Person Two':
              newData = ['insert data for Person Two'];
              myChart.datasets[0].data.length = 0;
              myChart.datasets[0].data.push.apply(
                myChart.datasets[0].data, newData);
              break;
            case 'Individual Three':
//structure as above with data for Individual Three
              break;
           case 'Person Four':
//structure as above with data for Person Four
              break;
            default:
//structure as above with data for Sample One
          }
          myChart.update();
        });

Leave a comment