Highchart collect rest
by Ben Clayton
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
JavaScript
// Build the chart
Highcharts.chart('container', {
chart: {
type: 'pie',
events: {
load: function() {
var chart = this;
var threshold = 1 / 100;
var series = chart.series[0];
var points = series.points;
var total = points[0].total;
var del = [];
var rest = 0;
for ( var n = 0; n < points.length; n++ ) {
if ( points[n].y / total < threshold ) {
rest += points[n].y;
del.push(n);
};
};
while ( del.length ) {
series.removePoint( del.pop() );
};
if ( rest > 0 ) {
series.addPoint({
y: rest,
name: "Other"
});
}
}
}
},
title: {
text: "Fruit used in smoothie's"
},
tooltip: {
pointFormat: 'Qty:{point.y} <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format:"{point.name} {y} <b>{point.percentage:.1f}%</b>"
},
showInLegend: true
}
},
series: [{
name: 'Fruit',
colorByPoint: true,
data: [{
name: 'Apple',
y: 170
}, {
name: 'Bannana',
y: 80
}, {
name: 'Peach',
y: 2
}, {
name: 'Strawberry',
y: 40
}, {
name: 'Raspberry',
y: 2
}, {
name: 'Sloe',
y: 1
}, {
name: 'Grape',
y: 1.5
}, {
name: 'Pear',
y: 1
}]
}]
});