(function () {
var script = document.getElementById('highcharts-script');
function addChart() {
var onCustomCodeError;
function customCode(options, product) {
try {
// Sample from highcharts
var myTitle = "A Historic Gender Gap", // Set title for Twitter
myURL = "http://www.prri.org/research/prri-atlantic-october-11-2016-presidential-election-horserace-clinton-trump/"; // 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
},
{
"x": 0
},
{
"x": 0
},
{
"x": 0
}
],
"columnTypes": [
"string",
"float",
"float",
"float",
"float",
"float",
"float"
],
"csv": ",Don\u0027t know/Refused,Some other candidate,Jill Stein,Gary Johnson,Donald Trump,Hillary Clinton\nWomen,9,2,,,28,61\nMen,6,5,1,3,48,37"
};
dataOptions.sort = true
dataOptions.complete = completeHandler;
Highcharts.data(dataOptions, chartOptions);
} catch (error) {
console.log(error);
completeHandler(undefined);
}
}
var shareUrl = 'http://cloud.highcharts.com/show/exazune';
var encodedUrl = encodeURIComponent(shareUrl);
var template = {
chart: {
renderTo: 'highcharts-exazune'
},
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"
},
"enabled": true
},
"stacking": "normal"
}
},
"yAxis": {
"tickWidth": 1,
"minorGridLineColor": "#d8d8d8",
"minorTickColor": "#d8d8d8",
"gridLineWidth": 0,
"max": 100,
"minColor": "#d8d8d8",
"tickColor": "#d8d8d8",
"maxColor": "#d8d8d8",
"lineColor": "#d8d8d8",
"title": {
"style": {
"color": "#000000",
"fontSize": "10px"
},
"text": "Source: PRRI/The Atlantic Mid-October Survey."
},
"lineWidth": 1
},
"xAxis": {
"minorGridLineColor": "#d8d8d8",
"minorTickColor": "#d8d8d8",
"tickColor": "#d8d8d8",
"lineColor": "#d8d8d8",
"minorGridLineWidth": 0,
"title": {
"style": {
"color": "#000000",
"fontSize": "10px"
}
}
},
"exporting": {
"allowHTML": true
},
"credits": {
"href": "http://www.prri.org",
"text": "PRRI"
},
"legend": {
"verticalAlign": "top",
"itemStyle": {
"color": "#000000"
},
"y": 45,
"reversed": true
},
"series": [
{
"color": "#bfc0bf",
"index": 0
},
{
"color": "#c7bd99",
"index": 1
},
{
"color": "#e68275",
"index": 2
},
{
"color": "#e9a53d",
"index": 3
},
{
"color": "#bad270",
"index": 4
},
{
"color": "#3d899e",
"index": 5
}
],
"subtitle": {
"style": {
"fontSize": "14px",
"color": "#000000"
},
"text": "Presidential vote choice among likely voters by gender"
},
"tooltip": {
"backgroundColor": "#ffffff"
},
"title": {
"style": {
"fontWeight": "bold",
"color": "#000000"
},
"text": "A Historic Gender Gap"
},
"chart": {
"width": 0,
"style": {
"fontFamily": "Arial"
},
"type": "column",
"inverted": true
}
};
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-4.2.5.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);
}
}());