d3.js,我想在json中添加数据值

时间:2017-01-10 07:50:03

标签: json d3.js

我正在使用d3.js. 创建并希望在文件json中创建总能量值。 我应该使用nest()函数吗?

[
{"name":"a","energy":200},
{"name":"b","energy":400},
{"name":"c","energy":450},
{"name":"d","energy":300},
{"name":"e","energy":120}
]

1 个答案:

答案 0 :(得分:1)

你的问题不明确。我想你想要为每个对象添加一个新属性总数...在这种情况下,使用if (!UIApplication.SharedApplication.OpenUrl(NSUrl.FromString("testscheme://com.account.appname"))) { NSString urlString = new NSString(Session.DropboxAPIHost); NSUrl myFileUrl = new NSUrl(urlString); UIApplication.SharedApplication.OpenUrl(myFileUrl) }

forEach
var data = [
{"name":"a","energy":200},
{"name":"b","energy":400},
{"name":"c","energy":450},
{"name":"d","energy":300},
{"name":"e","energy":120}
];

var total = d3.sum(data, d=> d.energy);

data.forEach(d => {
d.total = total;
});

console.log(data);