I'm trying to take a given array of numbers and normalize them be 0-100.
Clearly I'm doing something wrong here, but I can't for the life of me figure it out. Someone please help me find my dumb mistake?
var arr = [6345, 45678, 34572, 59867, 23517, 20938, 9872345, 2986];
arr.sort();
var scale = d3.scale.linear().domain([0, arr[0]]).range([0, 100]);
for ( var i in arr ){
console.log(scale(arr[i]));
}
jsFiddle
Try:
var max = d3.max(arr);
var scale = d3.scale.linear().domain([0, max]).range([0, 100]);
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