Search code examples
amcharts

Opposite and horizontal property for labels in Pie Series


I was wondering if there is any way I can show labels Horizontally for PieSeries above Pie Graph, as by default it is shown below graph and vertically. I tried to find a way similar to Opposite property of AxisRendererX as given in OppositeProperty explanation, But I failed to show my labels in a Horizontal way above graph! An image of Pie Series that needs to be updated is attached for your reference.PieChart


Solution

  • amcharts uses the full area you provide for a chart. If you set the width of your chart to a small value, you have the result you showed. If you resize your chart like I did in the code pen below, the labels are shown horizontally.

    To change the legend position you can use the legend.position attribute.

    Available options are: "left", "right", "top", "bottom" (default), and "absolute".

    https://www.amcharts.com/docs/v4/concepts/legend/#Positioning

    In your case you can use the following code to move the legend to the top:

    chart.legend = new am4charts.Legend();
    chart.legend.position = 'top';
    

    I created a code pen for your example.