(function () {
var script = document.getElementById('highcharts-script');
function addChart() {
var onCustomCodeError;
function customCode(options, product) {
try {
// Sample from highcharts
var myTitle = "The Decline of Christmas as a Religious Holiday", // Set title for Twitter
myURL = "http://www.prri.org/research/poll-post-election-holiday-war-christmas/"; // Set URL to the article
var items = options.exporting && options.exporting.buttons &&
options.exporting.buttons.contextButton.menuItems,
encodedUrl = encodeURIComponent(myURL),
mySharers = [
[
'Share on Facebook'
],
[
'Share on Google+'
],
[
'Share on Twitter'
],
[
'Share on LinkedIn'
]
]
if (items) {
options.exporting.buttons.contextButton.menuItems = items.slice(0, -3);
Highcharts.each(mySharers, function (item, i){
options.exporting.buttons.contextButton.menuItems[i].text = item.join('');
});
}
} 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": ",Strongly religious,Somewhat religious,Not too religious\n2005,49,32,19\n2010,51,31,17\n2013,42,31,26\n2016,43,29,27"
};
dataOptions.sort = true
dataOptions.complete = completeHandler;
Highcharts.data(dataOptions, chartOptions);
} catch (error) {
console.log(error);
completeHandler(undefined);
}
}
var shareUrl = 'http://cloud.highcharts.com/show/uharele';
var encodedUrl = encodeURIComponent(shareUrl);
var template = {
chart: {
renderTo: 'highcharts-uharele'
},
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 = {
"plotOptions": {
"series": {
"dataLabels": {
"useHTML": true,
"style": {
"fontSize": "12px",
"color": "#000000"
},
"enabled": true
}
}
},
"yAxis": {
"minorTickColor": "#d8d8d8",
"tickInterval": 10,
"tickColor": "#d8d8d8",
"lineColor": "#d8d8d8",
"minorGridLineWidth": 0,
"title": {
"style": {
"fontSize": "13px"
},
"text": null
},
"lineWidth": 1,
"tickWidth": 1,
"minorGridLineColor": "#d8d8d8",
"gridLineWidth": 0,
"min": 0,
"minColor": "#d8d8d8",
"maxColor": "#d8d8d8"
},
"xAxis": {
"minorGridLineColor": "#d8d8d8",
"minorTickColor": "#d8d8d8",
"tickInterval": 1,
"tickColor": "#d8d8d8",
"lineColor": "#d8d8d8",
"title": {
"style": {
"fontSize": "10px",
"color": "#000000"
},
"text": "Sources: Gallup surveys, 2005-2010; PRRI surveys, 2013-2016."
},
"minorGridLineWidth": 0
},
"exporting": {
"allowHTML": true
},
"credits": {
"href": "publicreligion.org",
"text": "PRRI"
},
"legend": {
"layout": "vertical",
"verticalAlign": "top",
"itemStyle": {
"color": "#000000"
},
"y": 60
},
"series": [
{
"color": "#3d899e",
"marker": {
"symbol": "circle"
},
"index": 0
},
{
"color": "#bad26e",
"marker": {
"symbol": "circle"
},
"index": 1,
"negativeColor": "#000000"
},
{
"color": "#e9a43c",
"marker": {
"symbol": "circle"
},
"index": 2
}
],
"subtitle": {
"style": {
"fontWeight": "normal",
"fontSize": "14px",
"color": "#000000"
},
"text": "Thinking of the way you personally celebrate Christmas, is it a strongly religious holiday, somewhat religious, or not too religious?"
},
"tooltip": {
"backgroundColor": "#ffffff"
},
"title": {
"style": {
"fontWeight": "bold",
"color": "#000000"
},
"text": "The Decline of Christmas as a Religious Holiday"
},
"chart": {
"backgroundColor": "#ffffff",
"plotBackgroundColor": "#ffffff",
"width": null,
"style": {
"fontFamily": "Arial"
},
"type": "line"
},
"colors": [
"#76d155",
"#434348",
"#90ed7d",
"#f7a35c",
"#8085e9",
"#f15c80",
"#e4d354",
"#2b908f",
"#f45b5b",
"#97e4de"
]
};
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);
}
}());