Miller
Miller

Reputation: 145

Size of graph in highcharts

enter image description hereI have created piecharts in my django project using highcharts.Each pie is in a seperate div and the width of all divs are set to 25%.I have created the pie using a for loop so they all have the same properties yet the pies differ in size.What could be the reason for this. This is the code for my div.

var div = document.createElement("div");
div.id = "container"+i;
div.style.cssFloat = "left";
div.style.width="25%"
document.getElementById("main").appendChild(div);

And this is the code for my chart

 for(i=0;i<res.length;i++)

        {
    Highcharts.chart('container'+String(i), {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: server[i]
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                style: {
                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                }
            }
        }
    },
    series: [{

          name: 'Success',
          data: res[i]
}]
});

}

Upvotes: 1

Views: 38

Answers (1)

Wojciech Chmiel
Wojciech Chmiel

Reputation: 7372

Pie size by default is automatically adjusted so that data labels have enough space to be rendered. This behavior can be changed by setting plotOptions.pie.size - the diameter of the pie relative to the plot area.

Code:

  plotOptions: {
    pie: {
      size: '50%' // Can be a percentage or pixel value
    }
  }

Demo:

API reference:

Upvotes: 1

Related Questions