在 JavaScript 中,如何将“长表格式”转换为适合折线图的数据结构:
var data = [
{"type":"A"," year":2000," value":50},
{"type":"A"," year":2001," value":51},
{"type":"A"," year":2002," value":52},
{"type":"B"," year":2000," value":60},
{"type":"B"," year":2001," value":55},
{"type":"B"," year":2002," value":57}
]
=>
var series = [
{type: "A", values : [{x: 2000, y: 50}, {x: 2001, y: 52},] },
{type: "B", values : [{x: 2000, y: 60}, {x: 2001, y: 55},] },
]
一个普通的 JavaScript 解决方案以及一个带有 Crossfilter 库的解决方案 - 可以在数据的任何维度上工作 - 将很有价值: https ://github.com/square/crossfilter/wiki/API-Reference