Welcome Guest, Not a member yet? Register   Sign In
Charts.js month++
#1

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>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB