好友
阅读权限 20
听众
最后登录 1970-1-1
本帖最后由 as614001 于 2020-12-8 10:52 编辑
我想问下基于 key-value 不做转换,怎么可以按 x 日期 y运动量 渠道 处理呢?处理了半天都没处理好。其实按官方实例处理数据格式后是可以做到的。
1
option = {
legend: {},
tooltip: {},
dataset: {
source:
[
{'channel': '张叔', 'IDA y': '2020-11-08', 'sportnum': '1484'},
{'channel': '李二', 'iday': '2020-11-08', 'sportnum': '1232'},
{'channel': '王五', 'iday': '2020-11-08', 'sportnum': '84'},
{'channel': '张叔', 'iday': '2020-11-09', 'sportnum': '1495'},
{'channel': '李二', 'iday': '2020-11-09', 'sportnum': '1171'},
{'channel': '王五', 'iday': '2020-11-09', 'sportnum': '124'},
{'channel': '张叔', 'iday': '2020-11-10', 'sportnum': '2173'},
{'channel': '李二', 'iday': '2020-11-10', 'sportnum': '1731'},
{'channel': '王五', 'iday': '2020-11-10', 'sportnum': '160'}
],
},
xAxis: {type: 'category'},
yAxis: {},
// Declare several bar series, each will be mapped
// to a column of dataset.source by default.
series: [
{type: 'line', smooth: true,},
{type: 'line', smooth: true,},
{type: 'line', smooth: true,}
]
};
屈服了~~~~~~~~~~~~~~~~~~~~~~~~~~~
附带转换大法:
[JavaScript] 纯文本查看 复制代码
{
// 原始key-value形式的objArr
let objArr=[
{product: 'Matcha Latte', count: 823, score: 95.8},
{product: 'Milk Tea', count: 235, score: 81.4},
{product: 'Cheese Cocoa', count: 1042, score: 91.2},
{product: 'Walnut Brownie', count: 988, score: 76.9}
];
// 目标值为二维数组arrArr
let arrArr=[];
let dimensions=Object.keys(objArr[0]);
console.log(dimensions);
objArr.forEach((value,index)=>{
arrArr[index]=[];
dimensions.forEach(val => {
arrArr[index].push(value[val]||null)
});
});
console.log(arrArr);
}