Survey
Updated 7 years ago by Template retirement home
How to use this template
A template for visualising survey responses and other data where each row represents a discrete entity such as a person.
The template allows you animate dots into different views, including groups, bars, and – for global data – a world map. It also allows you to compare different metrics in a grid view.
Ideal for datasets up to around 20,000 rows. Larger datasets will work but perform more slowly.
API information
This section documents API usage specific to this template, so for an introduction we suggest you refer to the generic API documentation instead.
template: _134
version: _9
Template data
There are three different formats in which you can supply data to this template. The most convenient for you to use likely depends on the source of your data, as described below.
1. Array of arrays, and a bindings object
You can supply arrays of arrays to opts.data
, which might look
like:
{ data: { questions: [ [ "QuestionsColumn1Value1", "QuestionsColumn2Value1", [ "QuestionsColumn1Value2", "QuestionsColumn2Value2", [ "QuestionsColumn1Value3", "QuestionsColumn2Value3", ... ], order: [ [ "OrderColumn1Value1", "OrderColumn2Value1", [ "OrderColumn1Value2", "OrderColumn2Value2", [ "OrderColumn1Value3", "OrderColumn2Value3", ... ], labels: [ [ "LabelsColumn1Value1", "LabelsColumn2Value1", [ "LabelsColumn1Value2", "LabelsColumn2Value2", [ "LabelsColumn1Value3", "LabelsColumn2Value3", ... ], colors: [ [ "ColorsColumn1Value1", "ColorsColumn2Value1", [ "ColorsColumn1Value2", "ColorsColumn2Value2", [ "ColorsColumn1Value3", "ColorsColumn2Value3", ... ], places: [ [ "PlacesColumn1Value1", "PlacesColumn2Value1", [ "PlacesColumn1Value2", "PlacesColumn2Value2", [ "PlacesColumn1Value3", "PlacesColumn2Value3", ... ], answer_groups: [ [ "Answer_groupsColumn1Value1", "Answer_groupsColumn2Value1", [ "Answer_groupsColumn1Value2", "Answer_groupsColumn2Value2", [ "Answer_groupsColumn1Value3", "Answer_groupsColumn2Value3", ... ] } }
where each array of arrays represents the rows in a data sheet.
To tell the API how the values from each column should be
associated with the keys that the template is expecting, you must also supply
an object attached to opts.bindings
. (The meanings of the
keys in the bindings object are documented
below.) The minimal bindings you can
supply for this template are as shown in this example:
{ template: "_134", version: "_9", bindings: { questions: { }, order: { }, labels: { label: 0, // index of a column in your data replacement: 1, // index of a column in your data }, colors: { question: 0, // index of a column in your data answer: 1, // index of a column in your data color: 2, // index of a column in your data }, places: { latitude: 0, // index of a column in your data longitude: 1, // index of a column in your data }, answer_groups: { group: 0, // index of a column in your data question: 1, // index of a column in your data display_as: 2, // index of a column in your data } }, data: { questions: [ [ "QuestionsColumn1Value1", "QuestionsColumn2Value1", [ "QuestionsColumn1Value2", "QuestionsColumn2Value2", [ "QuestionsColumn1Value3", "QuestionsColumn2Value3", ... ], order: [ [ "OrderColumn1Value1", "OrderColumn2Value1", [ "OrderColumn1Value2", "OrderColumn2Value2", [ "OrderColumn1Value3", "OrderColumn2Value3", ... ], labels: [ [ "LabelsColumn1Value1", "LabelsColumn2Value1", [ "LabelsColumn1Value2", "LabelsColumn2Value2", [ "LabelsColumn1Value3", "LabelsColumn2Value3", ... ], colors: [ [ "ColorsColumn1Value1", "ColorsColumn2Value1", [ "ColorsColumn1Value2", "ColorsColumn2Value2", [ "ColorsColumn1Value3", "ColorsColumn2Value3", ... ], places: [ [ "PlacesColumn1Value1", "PlacesColumn2Value1", [ "PlacesColumn1Value2", "PlacesColumn2Value2", [ "PlacesColumn1Value3", "PlacesColumn2Value3", ... ], answer_groups: [ [ "Answer_groupsColumn1Value1", "Answer_groupsColumn2Value1", [ "Answer_groupsColumn1Value2", "Answer_groupsColumn2Value2", [ "Answer_groupsColumn1Value3", "Answer_groupsColumn2Value3", ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_134", version: "_9", bindings: { questions: { metadata: [0, 1, ...], // index(es) of column(s) in your data categorical: [2, 3, ...], // index(es) of column(s) in your data continuous: [4, 5, ...], // index(es) of column(s) in your data geo: [6, 7, ...], // index(es) of column(s) in your data }, order: { categories: [0, 1, ...], // index(es) of column(s) in your data }, labels: { label: 0, // index of a column in your data replacement: 1, // index of a column in your data }, colors: { question: 0, // index of a column in your data answer: 1, // index of a column in your data color: 2, // index of a column in your data }, places: { latitude: 0, // index of a column in your data longitude: 1, // index of a column in your data names: [2, 3, ...], // index(es) of column(s) in your data }, answer_groups: { group: 0, // index of a column in your data question: 1, // index of a column in your data display_as: 2, // index of a column in your data affirmative_answers: [3, 4, ...], // index(es) of column(s) in your data } }, data: { questions: [ [ "QuestionsColumn1Value1", "QuestionsColumn2Value1", [ "QuestionsColumn1Value2", "QuestionsColumn2Value2", [ "QuestionsColumn1Value3", "QuestionsColumn2Value3", ... ], order: [ [ "OrderColumn1Value1", "OrderColumn2Value1", [ "OrderColumn1Value2", "OrderColumn2Value2", [ "OrderColumn1Value3", "OrderColumn2Value3", ... ], labels: [ [ "LabelsColumn1Value1", "LabelsColumn2Value1", [ "LabelsColumn1Value2", "LabelsColumn2Value2", [ "LabelsColumn1Value3", "LabelsColumn2Value3", ... ], colors: [ [ "ColorsColumn1Value1", "ColorsColumn2Value1", [ "ColorsColumn1Value2", "ColorsColumn2Value2", [ "ColorsColumn1Value3", "ColorsColumn2Value3", ... ], places: [ [ "PlacesColumn1Value1", "PlacesColumn2Value1", [ "PlacesColumn1Value2", "PlacesColumn2Value2", [ "PlacesColumn1Value3", "PlacesColumn2Value3", ... ], answer_groups: [ [ "Answer_groupsColumn1Value1", "Answer_groupsColumn2Value1", [ "Answer_groupsColumn1Value2", "Answer_groupsColumn2Value2", [ "Answer_groupsColumn1Value3", "Answer_groupsColumn2Value3", ... ] } }
2. Array of objects with arbitrary keys, and a bindings object
This format is most likely useful when you have data from an external source,
such as CSV data loaded from d3-dsv.
You should supply this attached to the opts.data
, which might look
like:
{ questions: [ { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, ... ], order: [ { "OrderHeader1": ..., "OrderHeader2": ..., ... }, { "OrderHeader1": ..., "OrderHeader2": ..., ... }, { "OrderHeader1": ..., "OrderHeader2": ..., ... }, ... ], labels: [ { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, ... ], colors: [ { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, ... ], places: [ { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, ... ], answer_groups: [ { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, ... ] }
... but with the keys being the column headers from your
source data instead. You must also supply an object attached to
opts.bindings
. The minimal bindings you can
supply for this template are as shown in this example:
{ template: "_134", version: "_9", bindings: { questions: { }, order: { }, labels: { label: "LabelsHeader1", replacement: "LabelsHeader2", }, colors: { question: "ColorsHeader1", answer: "ColorsHeader2", color: "ColorsHeader3", }, places: { latitude: "PlacesHeader1", longitude: "PlacesHeader2", }, answer_groups: { group: "Answer_groupsHeader1", question: "Answer_groupsHeader2", display_as: "Answer_groupsHeader3", } }, data: { questions: [ { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, ... ], order: [ { "OrderHeader1": ..., "OrderHeader2": ..., ... }, { "OrderHeader1": ..., "OrderHeader2": ..., ... }, { "OrderHeader1": ..., "OrderHeader2": ..., ... }, ... ], labels: [ { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, ... ], colors: [ { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, ... ], places: [ { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, ... ], answer_groups: [ { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_134", version: "_9", bindings: { questions: { metadata: ["QuestionsHeader1", "QuestionsHeader2", ...], categorical: ["QuestionsHeader3", "QuestionsHeader4", ...], continuous: ["QuestionsHeader5", "QuestionsHeader6", ...], geo: ["QuestionsHeader7", "QuestionsHeader8", ...], }, order: { categories: ["OrderHeader1", "OrderHeader2", ...], }, labels: { label: "LabelsHeader1", replacement: "LabelsHeader2", }, colors: { question: "ColorsHeader1", answer: "ColorsHeader2", color: "ColorsHeader3", }, places: { latitude: "PlacesHeader1", longitude: "PlacesHeader2", names: ["PlacesHeader3", "PlacesHeader4", ...], }, answer_groups: { group: "Answer_groupsHeader1", question: "Answer_groupsHeader2", display_as: "Answer_groupsHeader3", affirmative_answers: ["Answer_groupsHeader4", "Answer_groupsHeader5", ...], } }, data: { questions: [ { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, { "QuestionsHeader1": ..., "QuestionsHeader2": ..., ... }, ... ], order: [ { "OrderHeader1": ..., "OrderHeader2": ..., ... }, { "OrderHeader1": ..., "OrderHeader2": ..., ... }, { "OrderHeader1": ..., "OrderHeader2": ..., ... }, ... ], labels: [ { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, { "LabelsHeader1": ..., "LabelsHeader2": ..., ... }, ... ], colors: [ { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, { "ColorsHeader1": ..., "ColorsHeader2": ..., ... }, ... ], places: [ { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, { "PlacesHeader1": ..., "PlacesHeader2": ..., ... }, ... ], answer_groups: [ { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, { "Answer_groupsHeader1": ..., "Answer_groupsHeader2": ..., ... }, ... ] } }
(As before, the keys containing "Header" would be replaced by column names from your data source.)
3. Array of objects with template-defined keys
There is an alternative format you can use, which is likely to be easier to
use if your data is not from a spreadsheet source. With this alternative format
you supply your data to the template as
an array of objects, attached to opts.data
, where the keys must
be those used by the template, as documented below. In this case
there is no need to supply a bindings object, since the key names are already
those expected by the template. The required properties in the data
object are as follows (scroll down for a
description of what each property is):
{ template: "_134", version: "_9", data: { questions: [ { metadata: [...], categorical: [...], continuous: [...], geo: [...] }, ... ], order: [ { categories: [...] }, ... ], labels: [ { label: ..., replacement: ... }, ... ], colors: [ { question: ..., answer: ..., color: ... }, ... ], places: [ { latitude: ..., longitude: ..., names: [...] }, ... ], answer_groups: [ { group: ..., question: ..., display_as: ..., affirmative_answers: [...] }, ... ] }, ... }
And the full list of all possible properties is as follows:
{ template: "_134", version: "_9", data: { questions: [ { metadata: [...], categorical: [...], continuous: [...], geo: [...] }, ... ], order: [ { categories: [...] }, ... ], labels: [ { label: ..., replacement: ... }, ... ], colors: [ { question: ..., answer: ..., color: ... }, ... ], places: [ { latitude: ..., longitude: ..., names: [...] }, ... ], answer_groups: [ { group: ..., question: ..., display_as: ..., affirmative_answers: [...] }, ... ] }, ... }
Meanings of the template data keys:
- questions.metadata: Identifying information
- questions.categorical: categorical
- questions.continuous: continuous
- questions.geo: geo
- order.categories: categories
- labels.label: label
- labels.replacement: replacement
- colors.question: question
- colors.answer: answer
- colors.color: color
- places.latitude: latitude
- places.longitude: longitude
- places.names: names
- answer_groups.group: group
- answer_groups.question: question
- answer_groups.display_as: display_as
- answer_groups.affirmative_answers: The respondent is included in the group if their answer to the question is one of the answers listed in these columns
Template settings
Options for opts.state
.
Dots
dot_fill color
Default colour. The colour of the dots if nothing is selected on the “Shade by” menu
dot_opacity number
Dot opacity. The opacity of the dots. A number between 0 and 1. Max: 1
colors text
Shading colours. The colours to use when shading by the answer to a question
include_grouped_questions_on_shade_menu boolean
Include grouped questions on shading menu. Should grouped questions be included on the shading menu?
Animations
transition_duration number
Animation length. Time in milliseconds of each dot's animation
transition_stagger number
Animation stagger. The spread of time over which the dots start animating
Popups
show_popups boolean
Show popups. Whether or not to show info popups when hovering over the dots
popup text
Popup contents. Can include any HTML with column headers in double curly brackets, such as {{Gender}}
Layout
fill_wide_screens boolean
Fill wide screens vertically. Check for big screen use or fixed heigh embeds; leave unchecked for responsive embeds
margin_left number
Left margin (pixels).
margin_top number
Top margin (pixels).
margin_right number
Right margin (pixels).
panel_width number
Panel widths (pixels). Width of the legend and controls panels on wide screens, ignored on mobile
order_groups_by_size boolean
Order groups by size.
order_grouped_groups_by_size boolean
… even for grouped questions?. If “Order groups by size” is not ticked, this option is ignored
overlay_image_visible boolean
Show overlay image.
overlay_image_url string
Overlay image URL.
Page design
gradient_opacity number
Gradient opacity. The gradient shade over the map Max: 1
map_opacity_map_mode number
Map opacity (in map mode). Max: 1
map_opacity_non_map_mode number
Map opacity (in other modes). Max: 1
background_color color
Background color.
background_image string
Background image URL.
Filter
exclusions string
Exclude groups with the following names. Case-sensitive comma-separated list
exclude_blanks boolean
Exclude groups with blank names.
Zoom
zoom_on_double_click boolean
Zoom on double click.
zoom_on_mousewheel boolean
Zoom on pinch/mousewheel.
Labels
label_color color
Label colour.
label_shadow_color color
Label shadow colour.
label_shadow_size number
Label shadow size. Measured in pixels
always_show_x_label boolean
Show X-axis groups label when not comparing. Show the groups label at the bottom when not comparing two metrics
show_xy_axis_labels_when_comparing boolean
Show X/Y-axis groups labels when comparing. Show groups labels on both axes when comparing two metrics