dqkelut8423 2015-02-20 17:05
浏览 45
已采纳

图表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 2015-02-20 17:51
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度