(function () {
var script = document.getElementById('highcharts-script');
function addChart() {
var onCustomCodeError;
function customCode(options, product) {
try {
// Extend default options for the chart
Highcharts.extend(options, Highcharts.merge(options, {
yAxis: [
// Primary yAxis, leave this alone. Note that Highcharts.merge does not deep merge arrays.
options.yAxis || {},
{ // Add secondary yAxis
title: {
text: 'Share'
},
labels: {
format: '{value}%'
},
opposite: true, // This puts the secondary yAxis on the opposite side of the chart
// ----
// Here you can add more options to customize the second yAxis, as described in the API
// https://api.highcharts.com/highcharts#yAxis
// ----
}
]
}));
// Here we select which series to show on the secondary yAxis:
options.series[1].yAxis = 1;
options.series[2].yAxis = 1;
} 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": [
{
"x": 0
},
{
"x": 0
},
{
"x": 0
}
],
"columnTypes": [
"float",
"float",
"float",
"float"
],
"csv": ",Inflow,GDP growth,Unemployment\n1991,329,-1.1,8.9\n1992,268.1,0.4,9.9\n1993,265.6,2.5,10.4\n1994,315,3.9,9.5\n1995,312.4,2.5,8.6\n1996,318.4,2.5,8.1\n1997,326.7,3.1,6.9\n1998,391,3.2,6.2\n1999,453.8,3.3,6\n2000,478.7,3.7,5.4\n2001,480.7,2.7,5.1\n2002,515.8,2.4,5.2\n2003,511,3.5,5\n2004,589,2.5,4.8\n2005,566.7,3,4.8\n2006,596,2.5,5.4\n2007,573.8,2.6,5.3\n2008,590.2,-0.6,5.7\n2009,566.5,-4.3,7.6\n2010,590.9,1.9,7.9\n2011,566,1.5,8.1\n2012,498,1.3,8\n2013,526,1.9,7.6\n2014,632,3.1,6.2\n2015,631.5,2.2,5.4"
};
dataOptions.sort = true
dataOptions.complete = completeHandler;
Highcharts.data(dataOptions, chartOptions);
} catch (error) {
console.log(error);
completeHandler(undefined);
}
}
var shareUrl = 'https://app.everviz.com/show/yjujyh';
var encodedUrl = encodeURIComponent(shareUrl);
var template = {
chart: {
renderTo: 'highcharts-yjujyh'
},
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": "Thousands"
}
},
"credits": {
"text": "\u003cb\u003eSource:\u003c/b\u003e ONS for LTIM and OECD for GPD growth and unemployment",
"href": null
},
"series": [
{
"index": 0,
"type": "column"
},
{
"index": 1
},
{
"index": 2
}
],
"subtitle": {
"text": "Chart provided by www.migrationobservatory.ox.ac.uk"
},
"title": {
"text": "Immigration, GDP growth and unemployment rates, 1991-2015"
},
"chart": {
"type": "line"
}
};
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 = '//app.everviz.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);
}
}());