chart

Render a chart without JavaScript, CSS, external services, or external assets.

The data argument can be a list of {Label, Value} tuples, [Label, Value] lists, or maps with label and value keys and an optional color. Numeric values can be numbers or strings. It can also be a map where each key is a label and each value is its chart value:

For example:

{% chart type="pie"
         title=_"Responses"
         data=[["Yes", 42], ["No", 8]] %}

{% chart type="pie" data=[
    %{ "label": _"Yes", "value": "42", "color": "#4477aa" },
    %{ "label": _"No", "value": "8" }
] %}

{% chart type="pie" data=%{"Yes": 42, "No": 8} %}

If data is not supplied, the labels and values lists are zipped. Values must be finite numbers. Generated data tables include the same color swatches as categorical charts, so every value can be matched to its chart mark.

Supported types are pie, donut, horizontal_bar, vertical_bar, and line. The optional arguments are:

ArgumentDescription
titleAccessible chart title and table caption.
dataLabel/value rows or a map of labels to values. Row maps can set color.
labelsLabels to zip with values when data is not supplied.
valuesValues to zip with labels when data is not supplied.
widthView box width, clamped between 64 and 4096. Defaults to 400.
heightView box height, clamped between 64 and 4096. Defaults to 240.
colorOne hexadecimal RGB color. Data points use brightness variations of this color.
paletteList of hexadecimal RGB colors. Later points use shades when the list is exhausted. Invalid colors are ignored.
colorsBackwards-compatible alias for palette.
sortSort with -value, +value, -label, or +label. A missing sign means ascending; the bare flag means -value.
classAdditional classes on the generated figure.
label_headerHeader for the label column in the data table.
value_headerHeader for the value column in the data table.
hide_tableDo not generate a table. Use only when the data is already shown in a table.
legendauto by default. With a hidden table, pie and donut charts get a color key. Set to true or false to override.
show_labelsShow outside labels with leader lines. Enabled by default for pie and donut charts; set to false to hide them.
label_min_percentCombine pie and donut values below this percentage into Other. Defaults to 0.
max_pie_valuesNumber of highest original pie or donut values to retain before combining the rest into Other. Defaults to 50; clamped between 1 and 1000.
aria_describedbyId of an existing table or description for the SVG.

Color selection uses color, palette, colors, the optional site.chart_palette configuration, and finally the built-in palette, in that order. The configured palette is a comma or whitespace separated list.

For security and predictable rendering, at most 1000 data points are used, labels are truncated, zero values are omitted from pie and donut charts, and those charts retain a bounded number of highest values and combine the rest into Other. The Other category stays at the low-value end of the ordering instead of being sorted by its aggregate value. Arbitrary SVG/CSS is not accepted, and the component is never cached independently. The component only renders supplied data and does not perform data access or authorization.

Edit on GitHub