var stateNames = { "AL": "Alabama", "AK": "Alaska", "AS": "American Samoa", "AZ": "Arizona", "AR": "Arkansas", "CA": "California", "CO": "Colorado", "CT": "Connecticut", "DE": "Delaware", "DC": "District Of Columbia", "FM": "Federated States Of Micronesia", "FL": "Florida", "GA": "Georgia", "GU": "Guam", "HI": "Hawaii", "ID": "Idaho", "IL": "Illinois", "IN": "Indiana", "IA": "Iowa", "KS": "Kansas", "KY": "Kentucky", "LA": "Louisiana", "ME": "Maine", "MH": "Marshall Islands", "MD": "Maryland", "MA": "Massachusetts", "MI": "Michigan", "MN": "Minnesota", "MS": "Mississippi", "MO": "Missouri", "MT": "Montana", "NE": "Nebraska", "NV": "Nevada", "NH": "New Hampshire", "NJ": "New Jersey", "NM": "New Mexico", "NY": "New York", "NC": "North Carolina", "ND": "North Dakota", "MP": "Northern Mariana Islands", "OH": "Ohio", "OK": "Oklahoma", "OR": "Oregon", "PW": "Palau", "PA": "Pennsylvania", "PR": "Puerto Rico", "RI": "Rhode Island", "SC": "South Carolina", "SD": "South Dakota", "TN": "Tennessee", "TX": "Texas", "UT": "Utah", "VT": "Vermont", "VI": "Virgin Islands", "VA": "Virginia", "WA": "Washington", "WV": "West Virginia", "WI": "Wisconsin", "WY": "Wyoming" }

var colorGradient = ["#feebe2", "#fcc5c0", "#fa9fb5", "#f768a1", "#dd3497", "#ae017e", "#7a0177"];

function setResults() { var stateResults = {};

electionResults.forEach(function(state) { var stateName = state.name; var colorIndex = state.winningVotes; var styleObject = { "background-color": colorGradient[colorIndex - 6], "group": colorIndex - 5, "label": { "font-size": 14 }, "tooltip": { "text": stateNames[stateName] + " voted for the elected president in " + Math.floor((state.winningVotes / state.totalVotes) * 100) + "% of the past 12 elections", "width": 200, "wrap-text": true, "text-align": "left", "font-size": 18 } }; stateResults[stateName] = styleObject; });

return { "background-color": "#FFF", "gui": { "watermark": { "position": "tr" } }, "globals": { "font-family": "Open Sans Condensed", "shadow": false }, "title": { "text": "Likelihood of a State Voting for the Elected President", "background-color": "#FFF", "color": "#333", "font-size": 24, "text-align": "left", "x": 10, "y": 10 }, "subtitle": { "text": "Based off the past 12 elections (1960-2012)*", "font-size": 16, "color": "#333", "text-align": "left", "x": 10, "y": 40 }, "labels": [{ "padding-top": "40px", "text": "* The 1960 presidential election was the first in which Hawaii and Alaska voted.", "font-size": 14, "y": 470, "x": 355 }], "legend": { "toggle-action": "none", "offset-y": -10, "border-width": 0, "background-color": "none", "vertical-align": "bottom", "marker": { "type": "rectangle", "width": 20, "height": 10, }, "item": { "font-size": 16 } }, "series": [ // render legend items { "legend-item": { "text": "50%" }, "legend-marker": { "background-color": "#feebe2", } }, { "legend-item": { "text": "58%" }, "legend-marker": { "background-color": "#fcc5c0", } }, { "legend-item": { "text": "66%" }, "legend-marker": { "background-color": "#fa9fb5", } }, { "legend-item": { "text": "75%" }, "legend-marker": { "background-color": "#f768a1", } }, { "legend-item": { "text": "83%" }, "legend-marker": { "background-color": "#dd3497", } }, { "legend-item": { "text": "91%" }, "legend-marker": { "background-color": "#ae017e", } }, { "legend-item": { "text": "100%" }, "legend-marker": { "background-color": "#7a0177", } } ], "shapes": [ // render map { "type": "zingchart.maps", "options": { "y": 40, "id": "map", "name": "usa", "scale": true, "style": { "hover-state": { "background-color": "#FFF", "alpha": 0.3, "border-width": 3 }, "border-color": "#FFF", "items": stateResults } } } ] } }

// renders chart zingchart.loadModules('maps, maps-usa', function(e) { zingchart.render({ id: 'myChart', data: setResults(), height: '100%', width: '100%' }); });