运行时:
<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 解析正常 - 那么为什么该软件不能处理我的动态数据呢?