To create an arc shape in D3, use the d3.arc() generator. This function returns a generator that, when called with a configuration object, produces a path string (d attribute) for an SVG <path> element.
Required/Common configuration properties:
innerRadius: The radius of the inner circle (use 0 for a pie slice).outerRadius: The radius of the outer circle.startAngle: The starting angle in radians.endAngle: The ending angle in radians.
import * as d3 from "d3";
// Create an svg path using the arc function
const arcGenerator = d3.arc();
const arcPath = arcGenerator({
innerRadius: 40,
outerRadius: 100,
startAngle: 0,
endAngle: Math.PI
});
// Add a path to the DOM with d3
d3.select("#my_dataviz")
.append("g")
.attr("transform", "translate(100, 100)")
.append("path")
.attr("d", arcPath)
.attr("fill", "#69b3a2")
.attr("stroke", "black");