Saturday, November 15, 2025
HomeLanguagesJavascriptD3.js pie.startAngle() Function

D3.js pie.startAngle() Function

The pie.startAngle() function in D3.js is used to set the start angle of the pie. When an angle is specified, it sets the start angle to the given angle or function and returns a pie generator. When the angle is not specified, it returns the current start angle accessor, which defaults to no start angle.

Syntax:

pie.startAngle( angle )

Parameters: This function accepts a single parameter as mentioned above and described below.

  • angle: It is a number or function that specifies the start angle in radians. It is an optional parameter.

Return Values: This function does not return anything.

Below given are a few examples of pie.startAngle() function in D3.js;

Example 1:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src="https://d3js.org/d3.v6.min.js">
    </script>
</head>
 
<body>
    <div style="width:300px; height:300px;">
        <center>
            <h1 style="color:green">
                neveropen
            </h1>
            <h2>
                pie.startAngle()
            </h2>
        </center>
        <svg width="300" height="250">
        </svg>
    </div>
     
    <script>
 
        // Data to be added in the pie chart
        var data = [
            { "property": "p5", "value": 19 },
            { "property": "p5", "value": 12 },
            { "property": "p4", "value": 11 },
            { "property": "p3", "value": 10 },
            { "property": "p2", "value": 9 },
            { "property": "p1", "value": 5 },
            { "property": "p3", "value": 10 },
            { "property": "p2", "value": 9 },
            { "property": "p1", "value": 5 },
        ]
 
        // Selecting SVG using d3.select()
        var svg = d3.select("svg");
 
        // Creating Pie generator
        var pie = d3.pie()
            .value((d) => { return d.value })
            // Use of pie.startAngle() Function
            .startAngle(1)
            (data);
        // Creating arc
        var arc = d3.arc()
            .innerRadius(0)
            .outerRadius(80);
 
        let g = svg.append("g")
            .attr("transform", "translate(150,120)");
 
        // Grouping different arcs
        var arcs = g.selectAll("arc")
            .data(pie)
            .enter()
            .append("g");
 
        // Appending path
        arcs.append("path")
            .attr("fill", (data, i) => {
                return d3.schemeSet3[i];
            })
            .attr("d", arc);
    </script>
</body>
 
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src="https://d3js.org/d3.v6.min.js">
    </script>
</head>
 
<body>
    <div style="width:300px; height:300px;">
        <center>
            <h1 style="color:green">
                neveropen
            </h1>
            <h2>
                pie.startAngle()
            </h2>
        </center>
        <svg width="300" height="250">
        </svg>
    </div>
     
    <script>
        // Data to be added in the pie chart
        var data = [
            { "property": "p5", "value": 19 },
            { "property": "p5", "value": 12 },
            { "property": "p4", "value": 11 },
            { "property": "p3", "value": 10 },
            { "property": "p2", "value": 9 },
            { "property": "p1", "value": 5 },
            { "property": "p3", "value": 10 },
            { "property": "p2", "value": 9 },
            { "property": "p1", "value": 5 },
        ]
 
        // Selecting SVG using d3.select()
        var svg = d3.select("svg");
 
        // Creating Pie generator
        var pie = d3.pie()
            .value((d) => { return d.value })
            // Use of pie.startAngle() Function
            .startAngle(5)
            (data);
        // Creating arc
        var arc = d3.arc()
            .innerRadius(40)
            .outerRadius(80);
 
        let g = svg.append("g")
            .attr("transform", "translate(150,120)");
 
        // Grouping different arcs
        var arcs = g.selectAll("arc")
            .data(pie)
            .enter()
            .append("g");
 
        // Appending path
        arcs.append("path")
            .attr("fill", (data, i) => {
                return d3.schemeSet3[i];
            })
            .attr("d", arc);
    </script>
</body>
 
</html>


Output:

RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6890 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS