i have some problem to fetch data into my chart using Canvas js. So, i have result json_encode() like this :
[{"jumlah_berita":2,"nama_kategori":"Music"},{"jumlah_berita":1,"nama_kategori":"Sport"},{"jumlah_berita":1,"nama_kategori":"Agama"},{"jumlah_berita":0,"nama_kategori":"Teknologi"},{"jumlah_berita":1,"nama_kategori":"Pendidikan"},{"jumlah_berita":0,"nama_kategori":"Cinta"},{"jumlah_berita":0,"nama_kategori":"coba test"}]
I want implement my chart Like this, how can i make this ?

It's my Code to create CHART
<script>
window.onload = function() {
var jumlahBerita = new CanvasJS.Chart("chartContainer2", {
animationEnabled: true,
theme: "light2", // "light1", "light2", "dark1", "dark2"
title: {
text: "Jumlah Berita(per Kategori)"
},
data: [{
type: "column",
dataPoints: [{
y: 3,
label: "< 30 Tahun"
},
{
y: 25,
label: "30-40 Tahun"
},
{
y: 5,
label: "> 40 Tahun"
}
]
}]
});
jumlahBerita.render();
}
</script>
The problem is when i'm place data
json_encode()indataPointslike this:
dataPoints:<?= $tampil_kategori ?>
My chart just render blank white
Can you help me with this ?
Thank's
If you need my Controller and Model to fetch
json_encode()Controller
$data['tampil_kategori'] = json_encode($this->home->getAllKategori(), JSON_NUMERIC_CHECK);
Model
public function getAllKategori()
{
$this->db->select('jumlah_berita,nama_kategori');
return $this->db->get('tb_kategori')->result();
}
Oh i forgot , can i'm modified the result
json_encode()from :
[{"jumlah_berita":2,"nama_kategori":"Music"},{"jumlah_berita":1,"nama_kategori":"Sport"},{"jumlah_berita":1,"nama_kategori":"Agama"},{"jumlah_berita":0,"nama_kategori":"Teknologi"},{"jumlah_berita":1,"nama_kategori":"Pendidikan"},{"jumlah_berita":0,"nama_kategori":"Cinta"},{"jumlah_berita":0,"nama_kategori":"coba test"}]
To this ?
[
{1,"Pendidikan,}
{2,"Sport"},
{3,"Agama"},
]
