[Chartjs]-How to make dynamic chart js using JSON in Codeigniter?

1👍

You should build your label from your json data.
Check this:

var json = [
 // your data json listed here
]

var label = []
var data = []
json.forEach(function (element) {
    label.push(element.tahun)
  data.push(element.e_nilai)
})

console.log(label, data)

Then you can use your data and label into the Chart.js.

Here the fiddle

Update:

if you use ajax, call this into the on success.

$.ajax({
  method: 'GET',
  url: 'your_url',
  dataType: 'json',
  success: function (response) {
    var label = []
    var data = []
    response.forEach(function (element) {
      label.push(element.tahun)
      data.push(element.e_nilai)
    })
    // your chart goes here
  }
})

Leave a comment