Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HighCharts - Make the pie chart 100% of the div

How can I make a pie chart fill 100% of the divit is contained in? The div has a width of 198px and it's height is 152px.

Additionally I would like to have a linear-gradient effect inside each pie slice, can you advise on how to do that?

enter image description here

like image 662
Alon Avatar asked Jul 31 '12 07:07

Alon


People also ask

How to increase pie chart size in HighCharts?

You can achieve the full height of the pie chart by setting the size attribute in the plotOptions of pie and removing margins , spacing and titles from the chart.

Which chart is used to show percentages that add up to 100 %?

Pie Charts A pie chart represents numbers in percentages, and the total sum of all the divided segments equals 100 percent.

How do I change the size of Highcharts?

Height and width is set either by setting a height and width of the container div, or by setting the chart. height and chart. width Highcharts options.

How do I make a pie chart full height in Excel?

1 Answer 1. You can achieve the full height of the pie chart by setting the size attribute in the plotOptions of pie and removing margins, spacing and titles from the chart. Here is an example demonstrating this.

How is the height of a chart percentage calculated?

If given a percentage string (for example '56%' ), the height is given as the percentage of the actual chart width. This allows for preserving the aspect ratio across responsive sizes. By default (when null) the height is calculated from the offset height of the containing element, or 400 pixels if the containing element's height is 0.

How do I add a background image to a Highcharts plot?

In styled mode, the plot background is set with the .highcharts-plot-background class. The URL for an image to use as the plot background. To set an image as the background for the entire chart, set a CSS background image to the container element.

How much space should be between the content of a chart?

The space between the left edge of the chart and the content (plot area, axis title and labels, title, subtitle or legend in top position). Defaults to 10. The space between the right edge of the chart and the content (plot area, axis title and labels, title, subtitle or legend in top position). Defaults to 10.


2 Answers

You can achieve the full height of the pie chart by setting the size attribute in the plotOptions of pie and removing margins, spacing and titles from the chart.

Code

    chart: {           
        margin: [0, 0, 0, 0],
        spacingTop: 0,
        spacingBottom: 0,
        spacingLeft: 0,
        spacingRight: 0
    },
    plotOptions: {
        pie: {
            size:'100%',
            dataLabels: {
                enabled: false
            }
        }
    }

Example (updated the fiddle to point to version 2.2.4)

Here is an example demonstrating this.

As to the linear gradients, I don't know if they have been implemented yet, but here is an example showing radial gradients.

Radial gradients are also part of Highcharts 3.0 now, here is an example

Update

Looks like as of Highcharts 3.0, this is not possible anymore due to the chart auto-scaling within the plot area, an excerpt from their documentation:

size: The diameter of the pie relative to the plot area. Can be a percentage or pixel value. Pixel values are given as integers. The default behaviour (as of 3.0) is to scale to the plot area and give room for data labels within the plot area. As a consequence, the size of the pie may vary when points are updated and data labels more around. In that case it is best to set a fixed value, for example "75%". Defaults to .

in my opinion this should not be the case since dataLabels are disabled. should probably be logged as a bug

Update (Aug 2014)

As per Torstein's comment, this is indeed still possible. slicedOffset needs to be set to 0 in addition to the margins begin set. (example)

$(function () {
    $('#container').highcharts({
        title: null,
        chart: {
            type: 'pie',
            margin: 0
        },
        
        plotOptions: {
            pie: {
                slicedOffset: 0,
                size: '100%',
                dataLabels: {
                    enabled: false
                }
            }
        },
        
        series: [{
            data: [
                ['Firefox',   44.2],
                ['IE7',       26.6],
                ['IE6',       20],
                ['Chrome',    3.1],
                ['Other',    5.4]
            ]
        }]
    });
});
#container {
    outline: 1px solid red;
    padding: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px; width: 500"></div>
like image 158
epoch Avatar answered Oct 18 '22 03:10

epoch


my solutions; (for legend position margin-top error..)

chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    type: 'pie',
                    height:'100%' // added...
                },

plotOptions: {
        pie: {
            size:'100%',
             height: '100%',
            dataLabels: {
                enabled: false
            }
        }
    }
like image 1
Ziya Ulaş SEDEF Avatar answered Oct 18 '22 04:10

Ziya Ulaş SEDEF