每个循环以某种特定格式创建数组的json在融合图中不起作用
如果生成从控制台复制的代码可以正常工作,那么我会在堆栈溢出中累累十几次搜索
var data_ChartStores = {
categories: [
{
category: [
{label: 'week_22'}, {label: 'week_23'}, {label: 'week_24'}, {label: 'week_25'},
]
}
],
dataset: [
{
seriesname: "Store 38",
data: [ { value: "0" }, { value: "0" }, { value: "1" }, { value: "0" }, ]
},
{
seriesname: "Store 137",
data: [ { value: "0" }, { value: "10" }, { value: "12" }, { value: "80" }, ]
},
{
seriesname: "Store 139",
data: [ { value: "40" }, { value: "50" }, { value: "2" }, { value: "2" }, ]
},
]
};
使用代码获取此代码
var res = JSON.parse(response);
var data_category = "";
var data_dataset = "";
$.each(res.weeks, function(i, item) {
data_category += "{label: '"+item+"'}, ";
});
$.each(res.record, function(i, item) {
data_dataset += '{seriesname: "Store '+i+'", data: [';
$.each(item, function(x, rec) {
data_dataset += '{ value: "'+rec+'" }, ';
});
data_dataset += ']},';
});
const dataSource = {
categories: [
{
category: [
data_category
]
}
],
dataset: [
data_dataset
]
};
没有错误,它只是融合图问题的格式