Chartjs-Bind first property value of an array of object into chart.js

1👍

You can set the labels using .map() method on myData array like:

data: {
   labels: myData.map(d => d.Region),
   ....
},

EDIT:

You can create a new function and add all chart init code into it like:

function CreateChart() {
   new Chart(document.getElementById("chart"), {
      type: 'horizontalBar',
      data: {
         labels: myData.map(d => d.Region),
         ... you code here
      },
      ...
   });
}

CreateChart();

and then on gridview click, again call this CreateChart function in the end like:

$("#gridview").click(function() {
   // all your code logic here
   console.log(myData);
   CreateChart();
});

Leave a comment