How do i find the max and min values from JSON data. I want the max of checkins and Checkintimes of data1,data2 ...data(n). My code is :
var max = d3.max(data, function(d) { return d.Checkintimes;} );
var min = d3.min(data, function(d) { return d.Checkintimes;} );
I tried this option too
d3.json("Values.json", function(data) {
var maxmbt = d3.max(d3.values(data) );
var maxcheckins = d3.max(d3.values(data));
console.log(maxmbt);
console.log(maxcheckins);
xScale.domain([0,maxcheckins]);
xScale.domain([0,maxmbt]);
});
I have a json in this format:
[
{
"name":"data1",
"checkins":[[1,0],[2,0],[3,0],[4,3],[5,0],[6,0],[7,0],[8,3],[9,0],[10,0],[11,0],[12,0]],
"teamsize":[[1,0],[2,0],[3,0],[4,3],[5,0],[6,0],[7,0],[8,1],[9,0],[10,0],[11,0],[12,0]],
"Checkintimes":[[1,0],[2,0],[3,0],[4,184],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,0],[12,0]]
},
{"name":"data2",
"checkins":[[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,27],[12,12]],
"teamsize":[[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,11],[12,11]],
"Checkintimes":[[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,10],[12,12]]
}
]
currently when i use the returning value is an array. not an unitary value. For e.g checkins max value here is 27 and Checkintimes - 184 in the aforesaid example.
The d3.max
function needs to have an accessor that gets individual values. You would need nested calls as you have nested data:
var max = d3.max(data, function(d) {
return d3.max(d.Checkintimes, function(e) { return d3.max(e); });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With