As expected, d3.max() is indeed returning the maximum value... however, it is returning the maximum value among strings, not among numbers.

The explanation is that, by default, d3.csv() will load all the values as strings, even if they are numbers. Therefore, when you do:

var value = record[year];

value is a string, not a number. And in JavaScript the maximum for an array of strings is different from the maximum for an array of numbers. For instance, using numbers:

var myArray = [1, 65, 9, 32, 42];
<script src=""></script>

That's the expected value. But look what happens if we use strings:

var myArray = ["1", "65", "9", "32", "42"];
<script src=""></script>

Solution: change your values to numbers:

var value = +record[year];

Related Query

More Query from same tag