(function () {
var script = document.getElementById('highcharts-script');
function addChart() {
var onCustomCodeError;
function customCode(options, product) {
try {
// Sample from highcharts
var myTitle = "Democratic Women Most Likely to Block 'Friends' Because of Political Views", // 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
}
],
"columnTypes": [
"string",
"float"
],
"csv": ",Yes\nAll Americans,13\nRepublican men,8\nRepublican women,10\nDemocratic men,14\nDemocratic women,30"
};
dataOptions.sort = true
dataOptions.complete = completeHandler;
Highcharts.data(dataOptions, chartOptions);
} catch (error) {
console.log(error);
completeHandler(undefined);
}
}
var shareUrl = 'http://cloud.highcharts.com/show/uqexiwo';
var encodedUrl = encodeURIComponent(shareUrl);
var template = {
chart: {
renderTo: 'highcharts-uqexiwo'
},
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": {
"minorGridLineColor": "#d8d8d8",
"tickWidth": 1,
"gridLineWidth": 0,
"minorTickColor": "#d8d8d8",
"tickInterval": 10,
"minColor": "#d8d8d8",
"tickColor": "#d8d8d8",
"maxColor": "#d8d8d8",
"lineColor": "#d8d8d8",
"title": {
"style": {
"color": "#000000"
},
"text": null
},
"minorGridLineWidth": 0,
"lineWidth": 1
},
"xAxis": {
"minorGridLineColor": "#d8d8d8",
"minorTickColor": "#d8d8d8",
"tickColor": "#d8d8d8",
"lineColor": "#d8d8d8",
"minorGridLineWidth": 0,
"title": {
"style": {
"color": "#000000",
"fontSize": "10px"
},
"text": "Source: PRRI December 2016 Survey."
}
},
"exporting": {
"allowHTML": true
},
"credits": {
"href": "prri.org",
"text": "PRRI"
},
"legend": {
"verticalAlign": "top",
"y": 80,
"itemStyle": {
"color": "#000000"
},
"enabled": false
},
"series": [
{
"color": "#3d899e",
"index": 0
}
],
"subtitle": {
"style": {
"fontSize": "14px",
"color": "#000000",
"fontWeight": "normal"
},
"text": "Percent who say that after the presidential election, they blocked, unfriended, or stopped following someone on a social networking site because of what they posted about politics"
},
"tooltip": {
"backgroundColor": "#ffffff"
},
"title": {
"style": {
"color": "#000000",
"fontWeight": "bold"
},
"text": "Democratic Women Most Likely to Block \"Friends\" Because of Political Views"
},
"chart": {
"width": null,
"style": {
"fontFamily": "Arial"
},
"type": "column",
"height": null
}
};
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);
}
}());