javascript - How can I assign values to an array in D3 using a loop? -



javascript - How can I assign values to an array in D3 using a loop? -

in next code wish assign values variable arr. doing manually referring each index of points array. there way to in single step , using loop or similar.

var svg = d3.select("body") .append("svg") .attr("width", 2000) .attr("height", 2000); var scren = [1, 2, 3, 1, 4, 5, 6, 4]; var maximum =d3.max(scren); var points = d3.range(1, maximum).map(function(i) { homecoming [i * 2000 / (maximum), 350]; }); var arr = [ {d: 'm ' + points[1][0] +' 350 10 10 0 1 0 '+ points[0][0]+' 350', stroke: 'green', 'strokewidth': 2, fill: 'none'}, {d: 'm ' + points[2][0] +' 350 10 5 0 1 0 ' + points[1][0]+' 350', stroke: 'green', 'strokewidth': 2, fill: 'none'}, // etc.. ]; svg.selectall('path') .data(arr) .enter() .append('path') .attr('d', function(d) {return d.d;}) .attr('stroke', function(d) {return d.stroke;}) .attr('stroke-width', function(d) {return d.strokewidth;}) .attr('fill', function(d) {return d.fill;}); svg.selectall("circle") .data(points) .enter() .append("circle") .attr("cx", function(d) { homecoming d[0]; }) .attr("cy", function(d) { homecoming d[1]; }) .attr("r", 5);

you can loop if need, , can utilize length of array set limits of loop. i'm not sure have within points like:

var arr = [];

for (i = 0; < points.length - 1; i++) { arr.push({d: 'm ' + points[i+1][0] +' 350 10 5 0 1 0 ' + points[i][0]+' 350', stroke: 'green', 'strokewidth': 2, fill: 'none'}) }

javascript arrays d3.js

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -