Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a simple arc with D3

I would like to add one simple arc in the chart section like a circle:

vis.append("circle")
    .style("stroke", "gray")
    .style("fill", "white")
    .attr("r", 40)
    .attr("cx", 50)
    .attr("cy", 50);

The provided examples of D3 are working with data properties but i would like to see it without any underlying data.

like image 478
Oliver Avatar asked Aug 22 '12 14:08

Oliver


People also ask

How to Create an arc with d3 js?

arc() returns a generator that when called automatically generates and returns a string of characters that can be assigned to the d attribute of a path element to define an arc, circle, or annulus. To create an arc generator simply call d3. arc() . var arcGen = d3.

What is the correct syntax to draw a circle in d3?

var circle = d3. selectAll("circle"); With a selection, we can make various changes to selected elements.

What is pie arc?

In a pie chart, the arc length of each slice (and consequently its central angle and area) is proportional to the quantity it represents. While it is named for its resemblance to a pie which has been sliced, there are variations on the way it can be presented.


1 Answers

D3 uses a path generator for arcs. If you don't want to data-drive your arc just define the arc generator and add some methods...

var arc = d3.svg.arc()
    .innerRadius(50)
    .outerRadius(70)
    .startAngle(45 * (Math.PI/180)) //convert from degs to radians
    .endAngle(3) //just radians

vis.append("path")
    .attr("d", arc)
    .attr("transform", "translate(50,50)")

You can see a demo here: http://jsfiddle.net/h9XNz/

like image 134
methodofaction Avatar answered Oct 13 '22 00:10

methodofaction