图表js和json,图表未显示

丹尼尔

我正在尝试从我的PHP文件中获取数据,然后将其放入chart.js

我有php工作和js工作(没有错误),但由于某种原因,图表未显示...

这是我的js

var ctx = $("#salesChart").get(0).getContext("2d");

    var data = {
        labels: [],
        datasets: [
            {
                label: "My First dataset",
                fillColor: "rgba(220,220,220,0.2)",
                strokeColor: "rgba(220,220,220,1)",
                pointColor: "rgba(220,220,220,1)",
                pointStrokeColor: "#fff",
                pointHighlightFill: "#fff",
                pointHighlightStroke: "rgba(220,220,220,1)",
                data: []
            }
        ]
    };

    $.getJSON('ajax/sales_chart.php', {id:$('#salesChart').data('storeid')}, function(result){
        $.each(result, function(i, field){
            data.labels.push(field['month']); 
            data.datasets[0].data.push(field['sales']);
        });
    });


    var myBarChart = new Chart(ctx).Bar(data);
酷乐

Bar(data)更新数据后,您需要使用来构建图表然后,图表会刷新。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章