// set the chart options to a variable so we can change them later
var chartOptions = {
chart: {
type: 'column', renderTo: 'container'
},
title: {
text: 'Use of our apps'
},
xAxis: {
categories: ['App 1', 'App 2', 'App 3']
},
yAxis: {
allowDecimals: false,
min: 0,
title: {
text: 'Number of users'
}
},
tooltip: {
// for this formatter function, we want to change what
// shows up in the box based on whether we're showing
// a count or a percentage of the values
formatter: function () {
var total = 0; // the total of the values we're showing
var s = '<b>' + this.x + '</b><br/>'; // tooltip header
// go through each item in the column
$.each(this.points, function (i, point) {
switch(this.series.options.stacking) {
case 'percent':
s += this.series.name + ': ' + Highcharts.numberFormat(this.percentage,0) + '<br/>';
total += this.percentage;
break;
case 'normal':
s += this.series.name + ': ' + this.y + '<br/>';
total += this.y;
break;
}
});
return s + 'Total: ' + total;
}, shared: true
},
plotOptions: {
column: {
stacking: 'normal' // this will be our default
}
},
series: [{
name: 'IN',
data: [5, 3, 4]
}, {
name: 'US',
data: [2, 5, 6]
}, {
name: 'UK',
data: [3, 0, 4]
}]
};
// whenever someone clicks on a radio button, draw the chart
$('.ToggleFormRadio').click(function() {
switch($(this)[0].value) {
case 'percentage':
chartOptions.plotOptions.column.stacking = 'percent';
chartOptions.yAxis.title.text = 'Number of users (%)';
var chart = Highcharts.chart(chartOptions);
break;
case 'count':
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.