jQuery条形图无法正确加载

时间:2018-10-23 13:09:07

标签: jquery chart.js

我正在使用条形图将我的mysql数据加载到仪表板上。问题是当我添加qc_point = 100时,它是直接从100开始并且未显示同一用户的图。它应该以0开头。

仪表板:-

enter image description here

数据库:-

enter image description here

Data.php:-

//query to get data from the table
$query = sprintf("SELECT qc_user, sum(qc_point) as qc_point FROM qc group by qc_user ORDER BY qc_user");


//execute query
$result = $mysqli->query($query);

//loop through the returned data
$data = array();
foreach ($result as $row) {
    $data[] = $row;
}

app.js:-

method: "GET",
        success: function(data) {
            console.log(data);
            var qc_user = [];
            var qc_point = [];

            for(var i in data) {
                qc_user.push(data[i].qc_user);
                qc_point.push(data[i].qc_point);
            }



            var chartdata = {
                labels: qc_user,
                datasets : [
                    {
                        label: 'Technical',
                        backgroundColor: 'rgba(200, 200, 200, 0.75)',
                        borderColor: 'rgba(200, 200, 200, 0.75)',
                        hoverBackgroundColor: 'rgba(200, 200, 200, 1)',
                        hoverBorderColor: 'rgba(200, 200, 200, 1)',
                        data: qc_point
                    }
                ]
            };

            var ctx = $("#mycanvas");

            var barGraph = new Chart(ctx, {
                type: 'bar',
                data: chartdata
            });
        },
        error: function(data) {
            console.log(data);
        }
    });
});

1 个答案:

答案 0 :(得分:0)

添加到您的chartjs选项:

options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
    }