[Chartjs]-Build dynamic array for charts.js

3👍

I think datasetValue.push = { is overriding the Array.push function for datasetValue. Try datasetValue.push( { to append.

Also, it’s likely that only the very last value will be added to datasetValue since you’re resetting it on every iteration:

for(var option in options){
      var datasetValue = [];

2👍

Your datasetValue contains only last item because you instantiate it in for loop. Every time you go in a for loop, datasetValue will be recreated (set to empty array), therefore you only log the ‘last’ item. You should instantiate it outside the for loop.

var datasetValue = [];
for(var option in options){

  datasetValue.push = {
      value: parseInt(options[option]),
      color: "#F7464A",
      highlight: "#FF5A5E",
      label: option
  }
}

Leave a comment