如何使Chart.js可用于我自己的数据

时间:2016-04-15 09:20:20

标签: javascript php mysql chart.js dynamic-data

我有以下Chart.js JavaScript代码:

var barChartTickets =
{
    labels: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ],
    datasets: [{
        fillColor: "rgba(220,220,220,0.5)",
        strokeColor: "rgba(220,220,220,0.8)",
        highlightFill: "rgba(220,220,220,0.75)",
        highlightStroke: "rgba(220,220,220,1)",
        data: [ '1', '0', '1', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' ]             
    }]      
}

这个功能:

window.onload = function() {        
    if ($('#reportTickets').length) {
        var ctx = document.getElementById("reportTickets").getContext("2d");
        window.myBar = new Chart(ctx).Bar(barChartTickets, {
            responsive: true
        });     
    }
}

我有一个包含client_dateclient_id的数据库表。

如何动态使用数据?

0 个答案:

没有答案