Normally, labels for Pie chart’s slices are horizontal, and either arranged in columns or attached to the slice itself. This tutorial will show how you can make labels curve along the outer edge of the slice.
Let’s take a super basic pie chart as our starting point.
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
var chart = am4core . create ( " chartdiv " , am4charts . PieChart );
// Add and configure Series
var pieSeries = chart . series . push ( new am4charts . PieSeries ());
pieSeries . dataFields . value = " litres " ;
pieSeries . dataFields . category = " country " ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Pie chart with curved slice labels pie-chart-with-curved-slice-labels
To make the labels follow slice’s outer edge, we’ll need to do to things:
Disable alignment of labels.
Set their bent setting.
pieSeries . alignLabels = false ;pieSeries . labels . template . bent = true ;
pieSeries . alignLabels = false ; pieSeries . labels . template . bent = true ;
{ // ... "alignLabels": false, "series": [{ // ... "labels": { "bent": true } }]}
Let’s see what that gives us.
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
var chart = am4core . create ( " chartdiv " , am4charts . PieChart );
// Add and configure Series
var pieSeries = chart . series . push ( new am4charts . PieSeries ());
pieSeries . dataFields . value = " litres " ;
pieSeries . dataFields . category = " country " ;
pieSeries . alignLabels = false ;
pieSeries . labels . template . bent = true ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Pie chart with curved slice labels pie-chart-with-curved-slice-labels-2
You might also want to position labels closer, farther, or even inside the slices.
For that we have radius property.
Set it to bigger value to position labels further away from the slice.
Set it to negative value to move the label inside.
While at it, you might want to set labels padding to zero (so that padding does not interfere with fine-tuning of our positions), as well as disable ticks.
pieSeries . alignLabels = false ;pieSeries . labels . template . bent = true ;pieSeries . labels . template . radius = - 10 ;pieSeries . labels . template . padding ( 0 , 0 , 0 , 0 );pieSeries . labels . template . fill = am4core . color ( " #fff " );pieSeries . ticks . template . disabled = true ;
pieSeries . alignLabels = false ;
pieSeries . labels . template . bent = true ;
pieSeries . labels . template . radius = - 20 ;
pieSeries . labels . template . padding ( 0 , 0 , 0 , 0 );
pieSeries . labels . template . fill = am4core . color ( " #fff " );
pieSeries . ticks . template . disabled = true ;
{ // ... "alignLabels": false, "series": [{ // ... "labels": { "bent": true, "radius": -10, "paddingTop": 0, "paddingRight": 0, "paddingBottom": 0, "paddingLeft": 0, "fill": "#fff" }, "ticks": { "disabled": true } }]}
Let’s see how that looks.
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
var chart = am4core . create ( " chartdiv " , am4charts . PieChart );
// Add and configure Series
var pieSeries = chart . series . push ( new am4charts . PieSeries ());
pieSeries . dataFields . value = " litres " ;
pieSeries . dataFields . category = " country " ;
pieSeries . alignLabels = false ;
pieSeries . labels . template . bent = true ;
pieSeries . labels . template . radius = - 10 ;
pieSeries . labels . template . padding ( 0 , 0 , 0 , 0 );
pieSeries . labels . template . fill = am4core . color ( " #fff " );
pieSeries . ticks . template . disabled = true ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Pie chart with curved slice labels pie-chart-with-curved-slice-labels-3
Here’s another example, which will move the labels outside slice if they are less than X percent.
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
var chart = am4core . create ( " chartdiv " , am4charts . PieChart );
// Add and configure Series
var pieSeries = chart . series . push ( new am4charts . PieSeries ());
pieSeries . dataFields . value = " litres " ;
pieSeries . dataFields . category = " country " ;
pieSeries . alignLabels = false ;
pieSeries . labels . template . bent = true ;
pieSeries . labels . template . radius = - 20 ;
pieSeries . labels . template . padding ( 0 , 0 , 0 , 0 );
pieSeries . labels . template . fill = am4core . color ( " #fff " );
pieSeries . ticks . template . disabled = true ;
pieSeries . labels . template . adapter . add ( " radius " , function ( radius , target ) {
if ( target . dataItem . values . value . percent < 10 ) {
target . fill = am4core . color ( " #000 " );
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Pie chart with curved slice labels pie-chart-with-curved-slice-labels-4