Line and area charts
Updated 7 years ago by Template retirement home
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: _165
version: _6
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: { data: [ [ "DataColumn1Value1", "DataColumn2Value1", [ "DataColumn1Value2", "DataColumn2Value2", [ "DataColumn1Value3", "DataColumn2Value3", ... ] } }
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: "_165", version: "_6", bindings: { data: { x: 0, // index of a column in your data } }, data: { data: [ [ "DataColumn1Value1", "DataColumn2Value1", [ "DataColumn1Value2", "DataColumn2Value2", [ "DataColumn1Value3", "DataColumn2Value3", ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_165", version: "_6", bindings: { data: { x: 0, // index of a column in your data y: [1, 2, ...], // index(es) of column(s) in your data facet: 3, // index of a column in your data } }, data: { data: [ [ "DataColumn1Value1", "DataColumn2Value1", [ "DataColumn1Value2", "DataColumn2Value2", [ "DataColumn1Value3", "DataColumn2Value3", ... ] } }
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:
{ data: [ { "DataHeader1": ..., "DataHeader2": ..., ... }, { "DataHeader1": ..., "DataHeader2": ..., ... }, { "DataHeader1": ..., "DataHeader2": ..., ... }, ... ] }
... 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: "_165", version: "_6", bindings: { data: { x: "DataHeader1", } }, data: { data: [ { "DataHeader1": ..., "DataHeader2": ..., ... }, { "DataHeader1": ..., "DataHeader2": ..., ... }, { "DataHeader1": ..., "DataHeader2": ..., ... }, ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_165", version: "_6", bindings: { data: { x: "DataHeader1", y: ["DataHeader2", "DataHeader3", ...], facet: "DataHeader4", } }, data: { data: [ { "DataHeader1": ..., "DataHeader2": ..., ... }, { "DataHeader1": ..., "DataHeader2": ..., ... }, { "DataHeader1": ..., "DataHeader2": ..., ... }, ... ] } }
(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: "_165", version: "_6", data: { data: [ { x: ..., y: [...] }, ... ] }, ... }
And the full list of all possible properties is as follows:
{ template: "_165", version: "_6", data: { data: [ { x: ..., y: [...], facet: ... }, ... ] }, ... }
Meanings of the template data keys:
- data.x: x
- data.y: y
- data.facet: If you want to facet by an additional dimention of the data, specify the relevant column here and turn off "Facet by series" in the settings above.
Template settings
Options for opts.state
.
Title and subtitle
title string
Title.
subtitle string
Subitle.
Chart design
chart_type string
Allowed values:
- line (Line chart)
- area (Stacked area chart)
facet_aspect number
Chart aspect ratio. Height as proportion of width
layout_fit boolean
Stretch charts to fit container (for embedding at fixed heights). If choosing this option be sure to choose a fixed height if generating an embed code
Margins
margin_top number
Margin top.
margin_right number
Margin right.
margin_bottom number
Margin bottom.
margin_left number
Margin left.
Colours
bg_color color
Background color.
palette string
Color scheme. Allowed values:
legend_show boolean
Show legend.
Facet grid
facet_by_series boolean
One mini grid per series.
facet_min_w number
Min column width in grid view.
facet_cols number
Number of facet columns. Leave blank or set to zero for automatic layout
Line styles
line_width number
Line width.
line_opacity number
Line opacity. Max: 1
line_curve string
Line style. Allowed values:
line_end_labels boolean
Show labels at end of lines. Add margin-right the layout panel if using end labels
Dots
show_dots boolean
Show data-point dots.
dot_radius number
Dot radius.
dot_opacity number
Dot opacity. Max: 1
X axis
x_axis_show boolean
Show x axis.
x_axis_label string
X axis label.
x_axis_min number
X min.
x_axis_max number
X max.
x_axis_padding_left number
X axis padding. Horizontal space between the y and x axes
x_axis_show_domain boolean
Line at bottom.
x_axis_num_ticks number
Number of tick marks. Approximate. The actual number will depend on the range of values, chart size, etc.
x_axis_tick_dashed number
Tick dash size. Zero for a solid line, bigger numbers for bigger dashes
x_axis_color color
Text colour.
x_axis_tick_color color
Tick colour.
x_axis_tall_ticks boolean
Tick marks full height.
x_axis_ticks_inline boolean
Tick labels next to line.
Y axis
y_axis_show boolean
Show y axis.
y_axis_label string
Y label.
y_axis_min number
Y min.
y_axis_max number
Y max.
y_axis_show_domain boolean
Line at edge.
y_axis_num_ticks number
Number of tick marks. Approximate. The actual number will depend on the range of values, chart size, etc.
y_axis_tick_dashed number
Tick dash size. Zero for a solid line, bigger numbers for bigger dashes
y_axis_color color
Text colour.
y_axis_wide_ticks boolean
Tick marks full width.
y_axis_ticks_inline boolean
Tick labels above line.
Interaction
show_popups boolean
Show popups.
popup_font_size number
Font size.