我正在使用轻量级图表,试图将数据分配到 testing.json
测试.json:
{"mydata":[{"time":"2020-10-27","value":"7.070"},{"time":"2020-10-28","value":"7.070"},{"time":"2020-10-30","value":"7.000"},{"time":"2020-11-02","value":"7.010"},{"time":"2020-11-05","value":"8.160"}]}
当使用这种方式读入轻量级图表时,它可以工作
$(document).ready(function () {
$.getJSON("testing.json",
function (jsondata) {
console.log(jsondata.mydata);
areaSeries.setData( jsondata.mydata );
});
});
当使用这种方式直接声明而不读取json文件时,它也可以
var data = [
{"time":"2020-10-27","value":"7.070"},
{"time":"2020-10-28","value":"7.070"},
{"time":"2020-10-30","value":"7.000"},
{"time":"2020-11-02","value":"7.010"},
{"time":"2020-11-05","value":"8.160"}
];
areaSeries.setData(data);
但是当单独分配给变量然后读入setData时,它失败了......
var data = [];
$(document).ready(function () {
$.getJSON("testing.json",
function (jsondata) {
console.log(jsondata.mydata);
data= jsondata.mydata;
});
});
areaSeries.setData(data);