gpt4 book ai didi

html - 如何使用 d3.domain 从 JSON 文件的多个列中获取 d3.min 和 d3.max?

转载 作者:搜寻专家 更新时间:2023-10-31 22:44:06 25 4
gpt4 key购买 nike

这是我正在使用的 JSON 文件,我想使用 ysec.domain([d3.min(data, function (d) { return(三列“male”,“female”中的最小值and "both")}), d3.max(data, function (d) { return(三列“male”、“female”和“both”中的最大值)}) ]);无论如何,我是否可以将最小值设置为三列中的最低值:“男性”、“女性”和“两者”,这也适用于最大值吗?

[{"year":"1960","male":"61.7","female":"65.7","both":"63.7","rankmale":"47","rankfemale":"50","rankall":"45"},
{"year":"1970","male":"65.4","female":"70.2","both":"67.7","rankmale":"45","rankfemale":"45","rankall":"44"},
{"year":"1980","male":"68.9","female":"74.2","both":"71.5","rankmale":"33","rankfemale":"36","rankall":"29"},
{"year":"1990","male":"71.9","female":"76.9","both":"74.3","rankmale":"28","rankfemale":"30","rankall":"30"},
{"year":"2000","male":"76.1","female":"80.1","both":"78.1","rankmale":"11","rankfemale":"24","rankall":"15"},
{"year":"2011","male":"80.1","female":"84.6","both":"82.3","rankmale":"6","rankfemale":"8","rankall":"5"}]

最佳答案

在您的情况下,您真的不需要考虑 both 列,因为它是 malefemale 列的平均值。我能想到的解决问题的最简单方法是这样的

var max = d3.max(data, function(d){
return (d.male < d.female) ? d.female : d.male;
});

var min = d3.min(data, function(d){
return (d.male < d.female) ? d.male : d.female;
});

关于html - 如何使用 d3.domain 从 JSON 文件的多个列中获取 d3.min 和 d3.max?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25161867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com