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

3 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS