How do I use d3.domain to get d3.min and d3.max from multiple columns in a JSON file? How do I use d3.domain to get d3.min and d3.max from multiple columns in a JSON file? json json

How do I use d3.domain to get d3.min and d3.max from multiple columns in a JSON file?


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;});


Fortunately you don't need both in this scenario, but if you did, you could use the Math.max() and Math.min() function to take the max or min value of multiple values. So your max and min values might look like:

var max = d3.max(data, function(d){    Math.max(d.male, d.female, d.both);});var max = d3.min(data, function(d){    Math.min(d.male, d.female, d.both);});

The Math.max() and Math.min() functions work with however many columns you want to work with.