Search code examples
javascriptamcharts

Left align pie chart (amCharts)


I am using amcharts to render a simple pie chart and I would like the pie chart to start on the left most edge of the container. I have gone through the amcharts API but nothing seems to do what I need. Below you can see the code I am using and an image of what I get (With some red lines drawn on of what I want Example of how the chart renders

        am4core.useTheme(am4themes_animated);
        // Themes end

        var data = [
          {
            revenueSource: "Fee Revenue",
            value: 356
          },
          {
            revenueSource: "Retail Revenue",
            value: 247
          },
          {
            revenueSource: "Ticket Revenue",
            value: 9876
          }
        ];

        var chart1 = am4core.create("chartdiv", am4charts.PieChart);
        chart1.hiddenState.properties.opacity = 0;
        chart1.data = data;
        chart1.innerRadius = am4core.percent(50);
        chart1.legend = new am4charts.Legend();
        chart1.legend.position = "right";

        var series1 = chart1.series.push(new am4charts.PieSeries());
        series1.dataFields.value = "value";
        series1.dataFields.category = "revenueSource";
        series1.ticks.template.disabled = true;
        series1.labels.template.disabled = true;

Note. The div that the chart renders within has a height of 400px and a width of 100%


Solution

  • chart1.seriesContainer.align = "left"; Should do the job.