Survey
Updated 6 years ago to v3.4.1 by Flourish team
How to use this template
This template is ideal for visualising survey responses and other data where each row represents a discrete entity such as a person. It lets you animate dots into different views, including groups, bars, and – for geographic data – a world map. It also allows you to compare different metrics in a grid view.
Data requirements
The survey template is ideal for datasets up to around 10,000 rows. Larger datasets will work, but perform more slowly.
You'll need a CSV or Excel file with a row for each person or entity that you want to visualise.
In the case of survey data, your CSV file should have:
– a row for each person who took the survey
- a column for each question in the survey or other piece of information about the respondent
Getting started
First, from your projects page, create a new Survey visualisation. Open the Data view, go to the “Data” sheet and import your data to overwrite the current sheet. Then, on the right, update the column settings:
- Set “Categorical columns” to point to any columns with categorical answers, i.e. text like "male"/"female" or "0-99"/"100-999"/"1000-9990". Type in the column numbers - e.g.
A-C
. These columns will appear in in the “Group by”, “Shade by” and “Compare” dropdown in the visualisation. - Set “Continuous columns” to point to any columns with continuous answers, i.e. raw numbers, such as income or weight. These columns will appear in the “Size by” dropdown in the visualisation.
If you switch back to the Preview view, you should now see your data in the survey.
Change the text displayed
It's quite common that you want to change text shown in the visualisation - for example, you might have y
and n
as answers in your raw data, but want this to be displayed as yes
or no
in your visualisation.
To avoid editing the raw data (which may make it harder to update later), you can use the “Label overrides” sheet. Simply type the values you want to change (e.g. y
) in the first column and the values you want to show (e.g. yes
) in the second column. The visualisation should automatically update to show the new text.
Change the ordering of groups
It's also quite common that you want to change the order of answers, which by default will display alphabetically. For example, you might prefer to show groups for Yes
, No
, and Answer not supplied
in that order.
To do this, go to the “Natural order” data sheet, and fill in the heading of column A with the column name of the relevant question in the “Data” sheet. Underneath, type or paste in the answer values in the order that you'd like them displayed. Then, in the column settings panel, update “Order of answers” to point at column A.
You can repeat this for as many columns as necessary.
Customise the popups
In the data bindings panel, find “Metadata” and add any columns that you want to include in popups. Then, in the settings panel, ensure “Show popups” is checked, and edit “Popup contents” to include the columns, with column names in {{brackets}}
.
The “Popup contents” is HTML, so you can include formatting, e.g. <strong>Name:</strong> {{Name}}
, or even images if you include image URL in your data sheet.
If this isn't working, check you're using the exact column names and that you haven't included spaces inside the brackets - so {{Name}}
not {{ Name }}
.
Let users filter the data
You can allow users to filter your survey results within the visualisation - e.g. by year or another attribute.
To do this, in the data bindings panel, update the “Slider or menu” binding to point at the column you want to filter by.
Then, in the settings panel, choose “Control style” to specify the type of filter control you want - a button group, dropdown, or slider.
Grouped question
Survey data often includes grouped questions – i.e. those in the form "What food do you like (pick up to three)". In this model, the data sheet would typically include a column for each possible answer with a yes or no answer. The template allows you to group these questions together to enable you to compare the frequency of the positive answers.
When grouping by such a question, the number of dots may increase, because each survey respondent may appear multiple times – one for each positive answer. Because of this it's not possible to shade by a grouped question.
To create a grouped question, use the “Answer Groups” sheet. Put in the question you want to create in the first column, the column header for each sub-question in the next column, the display name for the group in the following column, and finally the way a positive answer is seen – e.g. “y” or “1”.
Display your data on a map
If you have country names in your data, you can display the data on a world map without doing much extra work. Just ensure that the “Geographic columns” binding points at the column with country names in it, and that your country names match the “Countries” sheet.
If your data has other geographic locations, such as city names, you'll need to do a bit more work! First, ensure that the “Geographic columns” binding points at the column with locations in it. Then replace the “Countries” sheet with your geographic locations - you'll need latitude, longitude and name columns.
To change the default position displayed on the map, you'll need to create a Flourish story. Inside the story, click the map view, then zoom to the position you want to display: the slide will save the position. Publish the story to share it with your users.
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: @flourish/survey
version: 3
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: "@flourish/survey", version: "3", 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: "@flourish/survey", version: "3", 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 column_filter: 8, // index of a column in your data id: 9, // index of a column 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: "@flourish/survey", version: "3", 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: "@flourish/survey", version: "3", bindings: { questions: { metadata: ["QuestionsHeader1", "QuestionsHeader2", ...], categorical: ["QuestionsHeader3", "QuestionsHeader4", ...], continuous: ["QuestionsHeader5", "QuestionsHeader6", ...], geo: ["QuestionsHeader7", "QuestionsHeader8", ...], column_filter: "QuestionsHeader9", id: "QuestionsHeader10", }, 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: "@flourish/survey", version: "3", 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: "@flourish/survey", version: "3", data: { questions: [ { metadata: [...], categorical: [...], continuous: [...], geo: [...], column_filter: ..., id: ... }, ... ], 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: Information to make available in the popups
- questions.categorical: Each of these columns appears in the “Group by”, “Shade by” and “Compare” dropdowns.
- questions.continuous: Must contain numbers. Each of these columns appears in the “Size by” dropdown.
- questions.geo: Must contain place names matching those specified in the “Countries” sheet. Set to blank to disable the map mode.
- questions.column_filter: Add a time slider or menu to filter the data based on the contents of a single column
- questions.id: Specify to allow animations between multiple occurences of the same person or thing – e.g. when using a time slider
- 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
Opacity. Max: 1
dot_emoji string
Emoji. A emoji to show on the dots. Not recommended for use with large data sets as including an emoji on each dot will slow down animation performance.
colors colors
Colour when shading. The colours to use when shading by the answer to a question
avoid_neat_groups boolean
Messier groups. Fractionally randomises the size of the dots to avoid overly “neat” grid-style groups. Ignored when “Size by” is in use.
dot_shape string
Shape. Allowed values:
dot_sides number
Sides. Min: 3 Max: 16
Groups
all_group_label string
Name for "all" group.
include_grouped_questions_on_shade_menu boolean
Include grouped questions on shading menu. Should grouped questions be included on the shading menu?
order_groups_by_size boolean
Order groups by size.
exclusions string
Exclude groups with the following names. Case-sensitive comma-separated list
exclude_blanks boolean
Exclude groups with blank names.
Labels
label_color color
Text colour.
label_min_font_size number
Min font size. In pixels; the actual font size in any view is set automatically between the min and max
label_max_font_size number
Max font size. In pixels; the actual font size in any view is set automatically between the min and max
label_shadow_size number
Size. As percent of font size Max: 100
label_shadow_custom boolean
Colour. Allowed values:
label_shadow_color color
.
label_group_count boolean
Label number of dots in group. Adds the number in brackets after the main label; ignored in chart, map and compare modes
label_group_percent boolean
Label group size as percentage of visible dots. Adds to the labels group size as a in brackets after the main label; ignored in chart, map and compare modes, and when showing a grouped question
label_group_percent_decimals number
Decimal places on percentage labels.
always_show_x_label boolean
Show X 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 labels when comparing. Show groups labels on both axes when comparing two metrics
Header
header.title string
Title.
header.subtitle string
Subtitle.
header.color color
Color.
header.align string
Alignment. Allowed values:
header.margin number
Margin.
header.margin_advanced boolean
Advanced margin settings.
header.margin_top number
Top.
header.margin_right number
Right.
header.margin_bottom number
Bottom.
header.margin_left number
Left.
Background
background_color color
Background color.
gradient_opacity number
Gradient opacity. The gradient shade over the background and map. Set to zero if not required. Max: 1
background_image url
Image URL. Must be a secure URL, i.e. one that starts “https://”
background_image_mode string
Sizing. Allowed values:
Map
map_max_group_size number
Max group size in map view. Min: 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
max_map_strech number
Max map strech (%).
Translations
select_group_text string
Text above "Group by" dropdown.
select_map_text string
Text above "Group location" dropdown.
select_color_text string
Text above "Shade by" dropdown.
select_size_text string
Text above "Size by" dropdown.
select_compare_text string
Text above "Compare" dropdown.
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
margin_left number
Left.
margin_top number
Top.
margin_right number
Right.
compare_y_axis_width number
Y axis width.
compare_x_axis_height number
X axis height.
overlay_image_visible boolean
Show overlay image.
overlay_image_url url
Overlay image. Upload a file or point to an existing one at a publicly available URL
panel_background_color color
Background.
panel_background_opacity number
Opacity. Max: 1
panel_text_color color
Text color.
panel_text_size number
Text size.
panel_icon_color string
Icon color. Allowed values:
panel_width number
Panel width. Width of the controls panels on wide screens, ignored on mobile
panel_overlay boolean
Overlay panel over graphic.
Legend
legend_mode string
When to show legend. Legend is only available when shading by a column Allowed values:
legend_text_color color
Text.
legend_hide_space boolean
Remove space when empty. Turn off to avoid the legend taking up space when empty. Leave on to avoid the graphic jumping up and down a little when the legend is revealed or hidden.
legend_hide_label boolean
Remove legend title.
Slider/menu
column_filter_style string
Control style. Allowed values:
column_filter_show_play boolean
Show play button next to slider.
column_filter_show_all boolean
Include "All" in slider/menu.
column_filter_show_all_label string
Custom label for All.
Zoom
zoom_on_double_click boolean
Zoom on double click.
zoom_on_mousewheel boolean
Zoom on pinch/mousewheel.
Animations
transition_duration number
Duration. Time in milliseconds of each dot's animation
transition_stagger number
Stagger. The spread of time over which the dots start animating