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 > </ 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 > </ 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: