【发布时间】:2016-04-19 05:00:51
【问题描述】:
这个怎么转:
var colors = ["#1f77b4", "#ff7f0e","#2ca02c", "#d62728"];
file =
[
{
DeviceName: 'DeviceName1',
counter1: '85%',
counter2: '87%',
counter3: '75%',
counter4: '63%' },
{
DeviceName: 'DeviceName2',
counter1: '85%',
counter2: '87%',
counter3: '75%',
counter4: '63%'
}
]
到这里:
data = [
{
key: "counter1",
color: "#1f77b4",
values:
[
{ x : "DeviceName1", y : '85%' },
{ x : "DeviceName2", y : '87%' }
]
},
{
key: "counter2",
color: "#ff7f0e",
values:
[
{ x : "DeviceName1", y : '85%' },
{ x : "DeviceName2", y : '87%' }
]
},
{
key: "counter3",
color: "#2ca02c",
values:
[
{ x : "DeviceName1", y : '85%' },
{ x : "DeviceName2", y : '87%' }
]
},
{
key: "counter4",
color: "#d62728",
values:
[
{ x : "DeviceName1", y : '85%' },
{ x : "DeviceName2", y : '87%' }
]
}
];
所以我基本上希望数组的每个对象中都有 1 个计数器
这是我的入门,还有很长的路要走,但我想知道如何或是否使用 map 或 reduce 来实现这一目标。
file.map(function(item,i){
return { key: item
}
})
【问题讨论】:
-
继续使用 map()。你的具体问题是什么?听起来您希望有人为您编写此代码
标签: javascript dataset