# chart

Source: https://zotonic.com/docs/2697/chart

URI: https://zotonic.com/id/2697

Language: en



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:

Line charts bridge null/undefined samples with a dotted line between known values. Their data table shows a dash for missing values. Other chart types omit them.

For example:

```django
{% 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:

| Argument            | Description                                                                      |
| ------------------- | -------------------------------------------------------------------------------- |
| `title`             | Accessible chart title and table caption.                                        |
| `data`              | Label/value rows or a map of labels to values. Row maps can set `color`.         |
| `series`            | For line charts: up to 101 maps with `label`, `data`, optional hexadecimal `color` and `width` (0.5-8). Replaces `data`. Series share positional x coordinates and a value scale; supply aligned samples, using null for gaps. First series is drawn on top. A colour legend is shown by default. |
| `labels`            | Labels to zip with `values` when `data` is not supplied.                         |
| `values`            | Values to zip with `labels` when `data` is not supplied.                         |
| `width`             | View box width, clamped between 64 and 4096. Defaults to 400.                    |
| `height`            | View box height, clamped between 64 and 4096. Defaults to 240.                   |
| `color`             | One hexadecimal RGB color. Data points use brightness variations of this color.  |
| `palette`           | List of hexadecimal RGB colors. Later points use shades when the list is exhausted. Invalid colors are ignored. |
| `colors`            | Backwards-compatible alias for `palette`.                                        |
| `sort`              | Sort with `-value`, `+value`, `-label`, or `+label`. A missing sign means ascending; the bare flag means `-value`. |
| `class`             | Additional classes on the generated `figure`.                                    |
| `label_header`      | Header for the label column in the data table.                                   |
| `value_header`      | Header for the value column in the data table.                                   |
| `hide_table`        | Do not generate a table. Use only when the data is already shown in a table.     |
| `legend`            | `auto` by default. With a hidden table, pie and donut charts get a color key. Set to true or false to override. |
| `show_labels`       | Show outside labels with leader lines. Enabled by default for pie and donut charts; set to false to hide them. |
| `label_min_percent` | Combine pie and donut values below this percentage into `Other`. Defaults to 0.  |
| `max_pie_values`    | Number of highest original pie or donut values to retain before combining the rest into `Other`. Defaults to 50; clamped between 1 and 1000. |
| `aria_describedby`  | Id 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 per series 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.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2697?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2697?language=en>)
