I am new to D3 and playing with a scatter chart. I can not get d3.max (data) to work correctly when setting up a domain!
I have the following setting for a random data set:
var data = []; for (i=0; i < 40; i++){ data.push({"x": i/40, "y": i/8, "a": Math.floor(Math.random() * 3), "x2": Math.random()}); }
And then to set the coordinates:
var x = d3.scale.linear().domain([0, 1]).range([0 + margin, w-margin]), y = d3.scale.linear().domain([0, d3.max(data)]).range([0 + margin, h-margin]), c = d3.scale.linear().domain([0, 3]).range(["hsl(100,50%,50%)", "rgb(350, 50%, 50%)"]).interpolate(d3.interpolateHsl);
This puts all 40 points in one horizontal line. If I replaced d3.max (data) with "5", then this is the diagonal (although from the upper left corner to the right to the right, I'm still trying to flip the y-coordinates). Why is d3.max (data) working as expected?
source share