d3.js - Very basic syntax error, lines not drawing in d3 -
for reason, in last block of code append("g)
successful, data bind append lines not. know should print 10 lines on top of each other, cannot them print page reason. can see error? help!
var w = 300; var dataset = 10; var svg = d3.select("body").append("svg") .attr("width", w) .attr("height", w); svg.append("line") .attr("x1", w/2) .attr("y1", 0) .attr("x2", w/2) .attr("y2", w); svg.append("line") .attr("x1", 0) .attr("y1", w/2) .attr("x2", w) .attr("y2", w/2); svg.append("g") .selectall("line") .data(dataset) .enter() .append("line") .attr("x1", 0) .attr("y1", w/4) .attr("x2", w/2) .attr("y2", w/4);
dataset
in .data(dataset)
has array nothing. if use, example .data([dataset])
1 line. if want 10 lines can use .data(d3.range(10))
, add color see it/them:
svg.append("g").selectall("line") .data(d3.range(10)) .enter() .append("line") .attr("x1", 0) .attr("y1", w/4) .attr("x2", w/2) .attr("y2", w/4) .style('stroke', 'green');
Comments
Post a Comment