(This chart is a part of the d3-charts collection available here.)
The subject of this project is nowhere near as exciting as its title would suggest. It aims to present a trend for a political party, or candidate, by combining the polling from multiple institutes as well as their confidence interval.
This chart has two basic views:
The single-party display is the main aim of the chart, but there is support for those of you who want to display multiple parties at once, be it all or a selection of your choice to make a poignant comparison.
This visualization shows the polling for the Danish Social Democrats.
An example of an all-party display can be found here.
Compare this to the trend charts for the Danish Social Democrats by Erik Gahner Larsen and M. Schmidt.
The chart employs a LOESS regression to plot a trend. The LOESS function currently has a bandwidth value of .2.
var dataset = "https://data.ndarville.com/danish-polls/data.csv", // "data.csv"
parseDate = d3.time.format("%Y/%m/%d").parse,
dateValue = "Date",
instituteValue = "Polling Firm",
lastElectionDate = "2011-09-15", // ""
nextElectionDate = "2015-09-14", // ""
periods = [
{
"start" : "2015-01-07",
"end" : "2015-02-14",
"color" : "",
"label" : "Hebdo and CPH"
}
], // `periods = []`
periodLabels = false, // true
yAxisTitle = "Votes (%)",
votingThreshold = 2.0,
showDots = true,
showAllParties = false,
recalculateYMax = false;
parties = showAllParties === true ? [] : ["A"];
var ignoreFilter = [
"Lead",
"Red (A+B+F+Ø)",
"Blue (V+O+I+C+K)"
]
// Autoconfig
var singleParty = (showAllParties === false && parties.length === 1) ? true : false,
displayInstitutes = singleParty;
parseDate refers to the date format---in this case YYYY/MM.
dateValue refers to the header of the date column in your data.csv.
instituteValue is the same, except for your column of polling institutes.
nextElectionDate refers to the date of the election, if known. This will change the maximum on the x-axis to said date to contextualize the trends.
lastElectionDate is the counterpart to nextElectionDate and sets the minimum of the x-axis.
periods takes an array of dictionaries of time intervals and displays them on the chart. The example currently shows the period from the Charlie Hebdo shooting to the Copenhagen shooting(s). It supports the following keys:
start: (no default)end: (no default)color: (default steelBlue)label: (Short) description to be displayed in the legendperiodLabels is an option for displaying labels defined for your periods.
showDots is an option to display dots for all the polls. You should at least use this or a trend chart.
votingThreshold is for displaying the voting threshold to gain a seat in parliament.
showAllParties is an option for displaying all parties or a manual selection.
recalculateYMax is an option for calculating the y-axis maximum based on your one selected party.
parties is an array to manually enter the parties you want to display.
ignoreFilter refers to headers of the columns you do not want to be parsed as poll data in your chart.
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js