I am working on a d3 graph with a specified Y-axis range in my code:
var yScale = d3.scaleLinear()
.domain([0, 1]) // input
.range([height, 0]); // output
However, I have realized that a scale of 0 to 1 may not be the most suitable for my data. As a beginner in this, I attempted to calculate the maximum value in my dataset like this:
// Data
var dataset = [{
y: 0.1
},
{
y: 0.6
},
{
y: 0.6
},
{
y: 0.7
}
];
var mymax = Math.max(dataset);
My intention was to then use this maximum value to adjust my .domain range like so:
.domain([0, mymax]) // input
Unfortunately, my approach seems to be incorrect as I am getting NaN as a result. I suspect the issue might be related to how I am referencing the data values as 'y' instead of actual numbers.
This post is not meant to be a duplicate question.