score:9
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];
console.log(d3.max(myarray));
<script src="https://d3js.org/d3.v4.min.js"></script>
that's the expected value. but look what happens if we use strings:
var myarray = ["1", "65", "9", "32", "42"];
console.log(d3.max(myarray));
<script src="https://d3js.org/d3.v4.min.js"></script>
solution: change your values to numbers:
var value = +record[year];
Source: stackoverflow.com
Related Query
- d3.max() not returning the max value in an array?
- D3 - Returning the whole array with the max count
- getBoundingClientRect() not returning the correct value on window restore down
- C3 bargraph going upper-side if we give y axis max value and the data array are same
- x-axis tick is not incremented correctly and it is set to the max value of y
- d3.js - max and min value from json data which has array of values
- Why is my call to selection.join() not returning the enter selection?
- How to get the specific JSON array from a value in that array
- D3.js: "On the fly" added elements to array are not refreshing the svg graphic
- Get the real max of an array in D3
- Return value from JSON, not the children count
- Chart is not showing the data array of objects
- d3 js transition over the array of rectangles does not work
- d3js:The xaxis time is not showing the complete date value
- Line chart not hitting the right value on chart and has a smooth line
- Find the max value in a column in d3.js
- Get max value from array with multiple columns
- Find the max value for Y axis scaling across an arbitrary number of columns referenced indirectly
- Trying to make reusable javascript function, but the data is not returning
- Finding min and max values of an array of arrays using D3.JS not plain Javascript
- Add line for y value based on the max x value
- d3 axis not showing tick label if two ticks have the same value
- D3 v4 url(#gradient) not returning the fill color
- Why the maximum variable take the d3.max() value but the minimum one d3.min() does not work properly?
- D3 : get value from the array
- D3 Accessing max value in 2d array of objects - brushing Y axis
- Maximum value of the second column of an array
- D3.js Traverse Through Nested Array to Find Max Value
- Understanding D3 data join using the new syntax - Array data is update but DOM not
- How to find min and max value in a array of objects
More Query from same tag
- D3 js collapsible chart increasing the arc curve radius
- D3 tick with background
- xAxis ordinal() does not start in left corner
- d3.js in visualize china map in geojson format about the projection setting
- d3.js Les Miserables JQuery Visualisation
- reload d3 graph when a 'dropdown menu value changes
- D3js path update enter and exit
- Updating SVG Element Z-Index With D3
- Draw an arc between two points
- D3 JSON file with source and index as strings rather than indices
- Network multi-route orthogonal graph in d3.js
- how to add directive to d3 library in angular
- CORS : No 'Access-Control-Allow-Origin' header is present on the requested resource
- New to d3.js. Trying to back into this dendogram
- AngularJS with nvD3 service not returning value
- d3.v4: How to use linkRadial instead of linkVertical/Horizontal
- How do I specify the initial zoom level in D3?
- Show and hide additional element in d3.js
- D3: gauge chart with growing arc
- Stop D3.js from redrawing
- DC.JS Selecting a Bar on Click
- D3, JSON, graph, force layout, data update, not complete redraw, drag
- How to use D3 hierarchical edge bundling graph with Plotly
- how to convert data selected from a postgres database to json or csv to use it with d3js lib?
- Multi bar chart using NVD3.js
- Multiple elements with multiple event handlers passing parameters; d3.js; simplify code
- generate circle for each line of CSV D3.js
- Interactively fixing a node in a directed force graph
- Cannot read property 'getHours' of undefined
- Sort links D3js force directed graph