I'm trying to read a json file with d3.js
where the graphic y axis depends on the maximum number in the json file. When logging the data inside the file I get 30
and 900
which I can use to set my cy
but when I put it in yscale()
function, it says the data is NaN
var yScale = d3.scale.linear()
.domain([0,d3.max(charts)])
.range([0,height])
var height = 600,
width = 800,
circleWidth = 50,
offSetX = 15
d3.json('_/data.json', function(data){
for (key in data) {
charts.push(data[key].amount);
};
var graph = d3.select("#graph").append('svg')
.selectAll('circle').data(charts)
.enter().append('circle')
.attr('cx', function(d, i){
return (i * circleWidth) + offSetX;
})
.attr('cy', function(d){
return yScale(d);
})
Json file
[
{
"song":"Song1",
"amount":30
},
{
"song":"Song2",
"amount":900
}
]