Chartjs-Pass array variable to chart.js options

0👍

You have use your report variable in a wrong way. data:[report] must be data:report. Here it is the solution.

var salesChartCanvas = $('#salesChart').get(0).getContext('2d');
var salesChart       = new Chart(salesChartCanvas);
alert(report);
var salesChartData = {labels  : ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
datasets: [
  {
    label               : 'Digital Goods',
    fillColor           : 'rgba(60,141,188,0.9)',
    strokeColor         : 'rgba(60,141,188,0.8)',
    pointColor          : '#3b8bba',
    pointStrokeColor    : 'rgba(60,141,188,1)',
    pointHighlightFill  : '#fff',
    pointHighlightStroke: 'rgba(60,141,188,1)',
    data                :  report
  }
]
};

0👍

Thanks for all the response,
I have got my result by putting all variables in separate variables, insert them in javascript variable and finally call them in the chart.js code like this

 data  :  [g1, g2, g3, g4, g5, g6, g7] 

Leave a comment