Chartjs-Show statistics in my diagram (php mysqli)

1👍

The problem is that you are creating chart javascript code for each individual row in your database. You should loop through the database results and build an array, then echo your javascript code:

$data = [];
$labels = [];
while($rows = mysqli_fetch_assoc($sql_sel)){
    $data[] = $rows['count'];
    $labels[] = '"'.$rows['st_date'].'"';
}
echo '
<script>
var lineChartData = {
labels : ['.implode(',',$labels).'],
datasets : [
        {
        fillColor : "rgba(252, 130, 19, 0.74)",
        strokeColor : "#FC8213",
        pointColor : "#FC8213",
        pointStrokeColor : "#fff",
        data : ['.implode(',',$data).']
        },
    ]
};
new Chart(document.getElementById("line").getContext("2d")).Line(lineChartData);
</script>';

Leave a comment