Highcharts LabelFormatter
by KP Singh Chundawat
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
JavaScript
$(function() {
var chart;
$(document).ready(function() {
// Build the chart
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'bottom',
x: 0,
y: -10,
symbolHeight: '0px',
labelFormatter: function() {
var legendName = this.name;
var match = legendName.match(/.{1,10}/g);
/* return match.toString().replace(/\,/g,"<br/>") */;
return '<span style="color: '+this.color+'">'+ this.name + '</span>'
}
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['FirefoxFirefoxFirefoxFirefoxFirefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]}]
});
});
});