如何使用d3.domain从JSON文件的多个列中获取d3.min和d3.max? [英] How do I use d3.domain to get d3.min and d3.max from multiple columns in a JSON file?
问题描述
这是我正在使用的JSON文件,我想使用ysec.domain([d3.min(data,function(d)} {return(男性,女性三列中的最小值和 both)})),d3.max(数据,函数(d){return( male, female和 both的三列中的最大值))))));
反正我有否将最小值设置为男性,女性和两者三列中的最小值,这也适用于最大值?
This is a JSON file that I am using and I would like to use ysec.domain([d3.min(data, function (d) { return (the lowest value from the three columns "male","female" and "both")}), d3.max(data, function (d) { return (the highest value from the three columns "male","female" and "both")}) ]); Is there anyway for me to set the min value to be the lowest value from the three columns: "male","female" and "both" and this applies to the max value too?
[{"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"}]
推荐答案
在您的情况下,您实际上并不需要同时考虑
co因为它是男性
和女性
列的平均值,所以显示为我能想到的解决问题的最简单方法就是这样
In your case, you don't really need to consider both
column since it's the average of male
and female
column. The simplest way that I can think of to solve your problem is something like this
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;
});
这篇关于如何使用d3.domain从JSON文件的多个列中获取d3.min和d3.max?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!