(function () {
var script = document.getElementById('highcharts-script');
function addChart() {
function parseData(completeHandler, chartOptions) {
try {
var dataOptions = {
"seriesMapping": [
{
"x": 0
}
],
"columnTypes": [
"string",
"float"
],
"csv": "Date,GDP growth\nQ1 2003,0.7\nQ2 2003,0.9\nQ3 2003,0.8\nQ4 2003,0.7\nQ1 2004,0.7\nQ2 2004,0.5\nQ3 2004,0.2\nQ4 2004,0.5\nQ1 2005,0.7\nQ2 2005,1.1\nQ3 2005,1\nQ4 2005,1.4\nQ1 2006,0.4\nQ2 2006,0.3\nQ3 2006,0.1\nQ4 2006,0.6\nQ1 2007,1\nQ2 2007,0.6\nQ3 2007,0.8\nQ4 2007,0.8\nQ1 2008,0.2\nQ2 2008,-0.6\nQ3 2008,-1.7\nQ4 2008,-2.3\nQ1 2009,-1.6\nQ2 2009,-0.2\nQ3 2009,0.2\nQ4 2009,0.4\nQ1 2010,0.4\nQ2 2010,0.8\nQ3 2010,0.5\nQ4 2010,0.1\nQ1 2011,0.7\nQ2 2011,0.3\nQ3 2011,0.8\nQ4 2011,0.2\nQ1 2012,0.2\nQ2 2012,-0.2\nQ3 2012,1\nQ4 2012,-0.1\nQ1 2013,0.7\nQ2 2013,0.6\nQ3 2013,0.9\nQ4 2013,0.6\nQ1 2014,0.6\nQ2 2014,0.8\nQ3 2014,0.7\nQ4 2014,0.7\nQ1 2015,0.4\nQ2 2015,0.6\nQ3 2015,0.4\nQ4 2015,0.5"
};
dataOptions.sort = true
dataOptions.complete = completeHandler;
Highcharts.data(dataOptions, chartOptions);
} catch (error) {
console.log(error);
completeHandler(undefined);
}
}
var shareUrl = 'https://app.everviz.com/show/asaseq';
var encodedUrl = encodeURIComponent(shareUrl);
var template = {
chart: {
renderTo: 'highcharts-asaseq'
},
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": "GDP growth (QoQ %)"
}
},
"xAxis": {
"tickInterval": 4
},
"legend": {
"enabled": false
},
"series": [
{
"tooltip": {
"valueSuffix": "pc"
},
"index": 0,
"negativeColor": "#b03060"
}
],
"subtitle": {
"text": "Source: ONS"
},
"title": {
"text": "The UK economy has grown for 12 consecutive quarters"
},
"chart": {
"type": "column"
}
};
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);
var chart = new Highcharts['Chart'](options);
}, 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);
}
}());