Line charts

Line charts with small multiples. Use to display and compare time series

Updated 7 years ago by Template retirement home

This section documents API usage specific to this template, so for an introduction we suggest you refer to the generic API documentation instead.

template: _131

version: _15

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: "_131",
    version: "_15",
    bindings: {
        data: {
            facet: 0, // index of a column in your data
            name: 1, // index of a column in your data
            time: 2, // 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: "_131",
    version: "_15",
    bindings: {
        data: {
            facet: 0, // index of a column in your data
            name: 1, // index of a column in your data
            time: 2, // index of a column in your data
            values: [3, 4, ...], // index(es) of column(s) 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: "_131",
    version: "_15",
    bindings: {
        data: {
            facet: "DataHeader1",
            name: "DataHeader2",
            time: "DataHeader3",
        }
    },
    data: {
        data: [
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            { "DataHeader1": ..., "DataHeader2": ..., ... },
            ...
        ]
    }
}

All possible bindings that you can supply are shown in this example:

{
    template: "_131",
    version: "_15",
    bindings: {
        data: {
            facet: "DataHeader1",
            name: "DataHeader2",
            time: "DataHeader3",
            values: ["DataHeader4", "DataHeader5", ...],
        }
    },
    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: "_131",
    version: "_15",
    data: {
    data: [
        {
            facet: ...,
            name: ...,
            time: ...,
            values: [...]
        },
        ...
    ]
},
    ...
}

And the full list of all possible properties is as follows:

{
    template: "_131",
    version: "_15",
    data: {
    data: [
        {
            facet: ...,
            name: ...,
            time: ...,
            values: [...]
        },
        ...
    ]
},
    ...
}

Meanings of the template data keys:

  • data.facet: facet
  • data.name: name
  • data.time: time
  • data.values: values

Template settings

Options for opts.state.

Layout

title string

Title.

subtitle string

Subitle.

layout_fit boolean

Fit charts into current container.

facet_aspect number

Chart aspect ratio. Height as proportion of width

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

margin_top number

Margin top.

margin_right number

Margin right.

margin_bottom number

Margin bottom.

margin_left number

Margin left.

Lines

line_width number

Line width.

line_opacity number

Line opacity.

Max: 1

line_curve string

Line style. Choose from a d3 line style such as [[curveLinear]], [[curveNatural]], [[curveMonotoneX]], [[curveStep]] or [[curveStepBefore]]

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

Colours

bg_color color

Background color.

palette string

Color scheme. Choose a d3 color scheme, such as [[schemeCategory20]], [[schemeCategory20b]], [[schemeCategory20c]] or [[schemeCategory10]]

legend_show boolean

Show legend.

X axis

x_axis_show boolean

Show x axis.

x_axis_label string

X axis label.

x_axis_min string

X axis minimum.

x_axis_max string

X axis maximum.

x_axis_show_domain boolean

Line at bottom.

x_axis_tick_dashed number

Tick marks dashed. Zero for a solid line, bigger numbers for bigger dashes

x_axis_color color

Colour.

x_axis_tall_ticks boolean

Tick marks full height.

x_axis_num_ticks string

Approx number of tick marks. The actual number will depend on the range of values, chart size, etc

x_axis_ticks_inline boolean

Tick labels next to line.

x_axis_padding_left number

X axis padding. Horizontal space between the y and x axes

Y axis

y_axis_show boolean

Show y axis.

y_axis_label string

Label.

y_axis_min string

Min value.

y_axis_max string

Max value.

y_axis_show_domain boolean

Line at edge.

y_axis_tick_dashed number

Tick marks dashed. Zero for a solid line, bigger numbers for bigger dashes

y_axis_color color

Colour.

y_axis_wide_ticks boolean

Tick marks full width.

y_axis_num_ticks string

Approx number of tick marks. The actual number will depend on the range of values, chart size, etc

y_axis_ticks_inline boolean

Tick labels above line.

Popups

show_popups boolean

Show popups.

Font size.