dqkelut8423
dqkelut8423
2015-02-20 17:05

图表js和json,图表没有显示

I am trying to get the data from my php file then into the chart.js

I have the php working and js working (no errors) but for some reason the chart is not showing...

here is my 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);
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doubao12345 doubao12345 6年前

    You need to invoke the building of the chart with Bar(data) after you updated the data. Then the charts gets refreshed.

    点赞 评论 复制链接分享

为你推荐