How to display data from database into line graph using php and mysql?

πŸ‘:1

Assuming that you want a single dataset, you need a single array (not two). So change to :

foreach ($result as $row) {
    $revenue_value[] = [
        'x' => $row["month"],
        'y' => $row["revenue"]
    ];
}

Then in your javascript β€˜data’ variable, remove the square brackets :

            const data = {
                datasets: [{
                    label: 'Revenue value:',
                    backgroundColor: '#20e0307a',
                    borderColor: '#04aa1a',
                    data: <?= json_encode($revenue_value) ?>,
                    borderWidth: 1,
                }]
            };

Leave a comment