Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very Simple D3: How to Draw an Arc?

It would be nice to learn D3. After reading many examples, I think I understand it. My first project is to make a color wheel, without transitions for simplicity. But it appears even that is not simple enough for my first project! For project zero, I am trying to get something to show on the screen. Hopefully something I wrote (and dear read has fixed), and not an example.

What did I do wrong? http://jsfiddle.net/aGdMX/1/

var arc = d3.svg.arc()
    .innerRadius(40)
    .outerRadius(100)
    .startAngle(0)
    .endAngle(1)
    ;

var chart = d3.select("body").append("svg:svg")
    .attr("class", "chart")
    .attr("width", 420)
    .attr("height", 420).append("svg:g")
    .attr("transform", "translate(200,200)")
    ;

chart.selectAll("path")
    .data(data)
    .enter().append("svg:path")
    .attr("fill", function(d, i){
        return d3.rgb("black");
    })
    .attr("d", arc)
    ;

Thank you

like image 681
Kyle Lahnakoski Avatar asked Feb 27 '13 03:02

Kyle Lahnakoski


1 Answers

Your example here doesn't have any data defined. If you just want to draw the svg statically, skip the selectAll() and data() bindings:

chart
    .append("svg:path")
    .attr("fill", function(d, i){
        return d3.rgb("black");
    })
    .attr("d", arc)
    ;

Or define some data and use that to drive the drawing:

http://jsfiddle.net/findango/aGdMX/2/

(plus .attr("fill"... should be .style("fill"...)

like image 68
findango Avatar answered Nov 11 '22 17:11

findango