D3.js scale returning wrong values from dataset

Viewed 2372

I'm having a problem with scales in d3.js. As I type the min and max into the Firefox console, I get the max value as the min and the second-max value as the max. What's the problem here?

Here is my dataset in form of csv file:

word,occur
obama,11
theguardian,9
world, 8
state, 8
care, 7
pakistan,7
block, 6
blog, 6
healthcare, 5

here is what I type into the console and the values I get in return:

    d3.min(dataset, function(d) { return d.occur}); => "11"
    d3.max(dataset, function(d) { return d.occur}); = "9"

the d3.max should return me 11 and d3.min should return me 5

2 Answers

For people who are not using CSV files, but may be graphing a JSON dataset, you can use parseInt in your accessor definition.

for example

yAccessor = (d) => parseInt(d.occur);
Related