(function () {
var script = document.getElementById('highcharts-script');
function addChart() {
var onCustomCodeError;
function customCode(options, product) {
try {
Highcharts.extend(options, Highcharts.merge(options, {
"chart": {
"type": 'column'
},
"title": {
"text": 'Trends in the ethnic and place of birth compositions of UK population'
},
"xAxis": {
"categories": ['1995', '2000', '2005', '2010', '2015']
},
"yAxis": {
"allowDecimals": false,
"min": 0,
},
"tooltip": {
"formatter": function () {
return '' + this.x + '
' +
this.series.name + ': ' + this.y + '
' +
'Total: ' + this.point.stackTotal;
}
},
"plotOptions": {
"column": {
"stacking": 'normal'
}
},
"series": [{
"name": 'Foreign-born',
"data": [6.8, 7.8, 9.4, 11.5, 13.4],
"stack": 'Foreign-born'
}, {
"name": 'Non-white ethnicity: foreign-born',
"data": [3, 4, 5, 6, 7],
"stack": 'Non-white'
}, {
"name": 'Non-white ethnicity: UK-born',
data: [2.9, 3.4, 4.2, 5.2, 6.2],
stack: 'Non-white'
}]
}));
} catch(error) {
console.error(error)
if (onCustomCodeError && onCustomCodeError(error) === false){
// stop execution
return;
}
}
var chart = new Highcharts['Chart'](options);
}
function parseData(completeHandler, chartOptions) {
try {
var dataOptions = {
"seriesMapping": [],
"columnTypes": [
null,
null,
null,
null
],
"csv": "Category\n"
};
dataOptions.sort = true
dataOptions.complete = completeHandler;
Highcharts.data(dataOptions, chartOptions);
} catch (error) {
console.log(error);
completeHandler(undefined);
}
}
var shareUrl = 'https://cloud.highcharts.com/show/azoleho';
var encodedUrl = encodeURIComponent(shareUrl);
var template = {
chart: {
renderTo: 'highcharts-azoleho'
},
navigation: {
menuItemStyle: {
fontFamily: Highcharts.SVGRenderer.prototype.getStyle().fontFamily,
padding: '2px 10px'
}
},
exporting: {
buttons: {
contextButton: {
menuItems: [{
text: '' +
'Share on Facebook'
}, {
text: '' +
'Share on Google+'
}, {
text: '' +
'Share on Twitter'
}, {
text: '' +
'Share on LinkedIn'
}, {
separator: true
}]
.concat(Highcharts.getOptions().exporting.buttons.contextButton.menuItems)
.concat([{
separator: true
}, {
text: '' + 'Edit chart'
}, {
text: '' + 'Create chart'
}])
}
}
}
};
var chartOptions = {
"yAxis": {
"title": {
"text": "Percentage of total UK population"
}
},
"credits": {
"href": null,
"text": "UK Labour Force Survey. Note: there are minor changes in the definition of the ethnicity variable over time."
},
"subtitle": {
"text": "Chart provided by www.migrationobservatory.ox.ac.uk"
},
"title": {
"text": "Trends in the ethnic and place of birth compositions of UK population"
}
};
parseData(function (dataOptions) {
// Merge series configs
if (chartOptions.series && dataOptions) {
Highcharts.each(chartOptions.series, function (series, i) {
chartOptions.series[i] = Highcharts.merge(series, dataOptions.series[i]);
});
}
var options = Highcharts.merge(dataOptions, chartOptions, template);
customCode(options, 'Chart');
}, chartOptions);
}
// Load the Highcharts script if undefined, and add the chart
if (typeof Highcharts !== 'undefined') {
addChart();
} else if (script) {
script.deferredCharts.push(addChart);
} else {
script = document.createElement('script');
script.id = 'highcharts-script';
script.src = '//cloud.highcharts.com/resources/js/highstock-cloud-5.0.7.js';
script.type = 'text/javascript';
script.deferredCharts = [addChart];
script.onload = function () {
// Prevent double firing of event in IE9/IE10
if (!script.chartsAdded) {
script.chartsAdded = true;
while(script.deferredCharts.length) {
script.deferredCharts.shift()();
}
}
};
script.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
script.onload();
}
};
document.getElementsByTagName('head')[0].appendChild(script);
}
}());