![]() |
Charts.js month++ - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Charts.js month++ (/showthread.php?tid=80393) |
Charts.js month++ - Lipe Shtogu - 10-27-2021 Hello CI enthusiasts, i have one issue regarding chartJS. Displays only one month even if i have data for 12 months On Controller i pass the data $data['test'] = $this->test_model->get_test_chart(); On Model public function get_test_chart(){ $res = $this->db->query("SELECT MONTHNAME(article.created_at) AS month, Month(article.created_at) as num_month, count(*) AS total FROM article GROUP BY month ORDER BY num_month ASC"); return $res->result_array(); } <script type="text/javascript"> $(document).ready(function(){ <?php foreach ($test as $key => $row): ?> //bar chart var ctx = document.getElementById("barChart"); var myChart = new Chart(ctx, { type: 'bar', data: { labels: ["<?php echo $row['month'];?>"], datasets: [ { label: "Test chart", data: [<?php echo $row['total'];?>], borderColor: "rgba(55, 160, 0, 0.9)", borderWidth: "0", backgroundColor: "rgba(55, 160, 0, 0.5)" }, ] }, options: { scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } }); <?php endforeach;?> }); </script> |