0

运行时:

<script>
jQuery(document).ready(function($){ 

function PopulateProductSales(chart1) { 
        var items = '<?php echo $json ?>';
        chart1.setDataSource(items);
 }
});  
</script>

控制台返回:

TypeError: b is not an object

...null;if("string"==typeof b)return c==e?b:null;for(var d=Object.getPrototypeOf(b)... jchartfx.system.js

在控制台中。但是,如果我运行:

<script>

jQuery(document).ready(function($){ 

function PopulateProductSales(chart1) {

       var items = [{
            "Month": "Jan 2014",
            "Posts": 12,
        }, {
            "Month": "Feb 2013",
            "Posts": 10,
        }, {
            "Month": "Mar 2013",
            "Posts": 16,
        }, {
            "Month": "Apr 2013",
            "Posts": 7,
        }, {
            "Month": "May 2012",
            "Posts": 1,
        }];

        chart1.setDataSource(items);
}

});
</script>

我的图表/图表加载正常。此外,动态数据是有效的 json,因为在控制台和http://jsonlint.com/中观察结果。

<script>
 var items = '<?php echo $json ?>';
 console.log(items);
</script>

输出:

[{"month":"May 2013","posts":2},{"month":"March 2013","posts":1}...]

到控制台。动态数据与静态数据一模一样!所有 jchartfx 库都已正确加载,DOM 解析正常 - 那么为什么该软件不能处理我的动态数据呢?

4

2 回答 2

1

您的 JSON 已损坏,或者 API 正在等待实际Object{}.

尝试使用http://jsonlint.com

于 2014-02-03T13:44:58.383 回答
0

代替

<script>
 var items = '<?php echo $json ?>';
</script>

利用:

<script>
 var items = <?php echo $json ?>;
</script>

所以,“分隔符”给我带来了问题。

于 2014-02-04T08:11:02.430 回答