I am trying to build a JSON dynamically by reading from an array in D3-javascript. (The below code is not the actual one I used, but similar to this)
radius = [10,20,30];
jsonradius = '[{';
for i = 0 to radius.length {
jsonradius += '"radius":';
jsonradius += 'radius[i]';
jsonradius += ',';
}
jsonradius += '}]';
using flags I make sure that the comma is not placed after the last entry and it comes out as a perfect JSON when I print using text(jsonradius) function. '[{"radius":10,"radius":20,"radius":30}]'
But when I try to access it like as follows, no value is returned.
'd3.selectAll("circle").data(jsonradius).enter().select("circle").attr("r",function(d){return d.radius;});'
I am new to d3 and javascript. Pls help how to build json dynamically.