javascript - Invalid value for <circle> attribute r="NaN" in D3 scatterplot code -
i getting nan error on r value in d3 scatterplot.
console error: error: invalid value attribute r="nan"
from section of code:
g.selectall(".response") .attr("r", function(d){ return responsescale(d.responses); }) .attr("cx", function(d){ return x(d.age); }) .attr("cy", function(d){ return y(d.value); })
here how scale set up:
var responsescale = d3.scale.linear() .domain(d3.extent(data, function(d){ return d.responses; })) .range(2, 15);
here sample of data:
var data = [ {glazed: 3.14, jelly: 4.43, powdered: 2.43, sprinkles: 3.86, age: 18, responses: 7}, {glazed: 3.00, jelly: 3.67, powdered: 2.67, sprinkles: 4.00, age: 19, responses: 3}, {glazed: 2.00, jelly: 4.00, powdered: 2.33, sprinkles: 4.33, age: 20, responses: 3},
i have tried putting plus sign in front of d.responses , using parsefloat().
the code example used in course, learning visualize data d3.js (chapter on creating scatterplot)
any suggestions appreciated!
in code:
var responsescale = d3.scale.linear() .domain(d3.extent(data, function(d){ return d.responses; })) .range(2, 15);
the parameter range() function should array of values, this: .range([2,15]);
corrected scale:
var responsescale = d3.scale.linear() .domain(d3.extent(data, function(d){ return d.responses; })) .range([2, 15])
;
more info on scales can found here. if still in trouble, let me know!
Comments
Post a Comment