> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-dv-ui/charts/plotly.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# Plotly

Draws any Plotly chart, with the query's values put into its traces.

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue by month", "classes": { "rootExtra": "relative h-72" } },
    "items": [
      {
        "type": "RPlotly",
        "bind": {
          "query": "SELECT [month], SUM(revenue) AS revenue FROM orders GROUP BY [month]"
        },
        "props": {
          "layout": {
            "margin": { "l": 48, "r": 8, "t": 8, "b": 32 },
            "xaxis": { "type": "category" }
          },
          "contents": [
            {
              "type": "scatter",
              "mode": "lines+markers",
              "x": "{{month}}",
              "y": "{{revenue}}",
              "line": { "color": "#9a42ff" }
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`orders` (30 rows)

```json
[
  { "month": "2026-07", "city": "Boston", "region": "North", "orders": 40, "revenue": 3200 },
  { "month": "2026-07", "city": "Chicago", "region": "North", "orders": 53, "revenue": 3777 },
  { "month": "2026-07", "city": "Austin", "region": "South", "orders": 41, "revenue": 4354 },
  { "month": "2026-07", "city": "Miami", "region": "South", "orders": 54, "revenue": 4931 },
  { "month": "2026-07", "city": "Denver", "region": "West", "orders": 42, "revenue": 5508 },
  { "month": "2026-08", "city": "Boston", "region": "North", "orders": 47, "revenue": 4291 },
  { "month": "2026-08", "city": "Chicago", "region": "North", "orders": 60, "revenue": 4868 },
  { "month": "2026-08", "city": "Austin", "region": "South", "orders": 48, "revenue": 5445 },
  { "month": "2026-08", "city": "Miami", "region": "South", "orders": 61, "revenue": 3622 },
  { "month": "2026-08", "city": "Denver", "region": "West", "orders": 49, "revenue": 4199 },
  { "month": "2026-09", "city": "Boston", "region": "North", "orders": 54, "revenue": 5382 },
  { "month": "2026-09", "city": "Chicago", "region": "North", "orders": 42, "revenue": 5959 },
  { "month": "2026-09", "city": "Austin", "region": "South", "orders": 55, "revenue": 4136 },
  { "month": "2026-09", "city": "Miami", "region": "South", "orders": 43, "revenue": 4713 },
  { "month": "2026-09", "city": "Denver", "region": "West", "orders": 56, "revenue": 5290 },
  { "month": "2026-10", "city": "Boston", "region": "North", "orders": 61, "revenue": 4073 },
  { "month": "2026-10", "city": "Chicago", "region": "North", "orders": 49, "revenue": 4650 },
  { "month": "2026-10", "city": "Austin", "region": "South", "orders": 62, "revenue": 5227 },
  { "month": "2026-10", "city": "Miami", "region": "South", "orders": 50, "revenue": 5804 },
  { "month": "2026-10", "city": "Denver", "region": "West", "orders": 63, "revenue": 3981 },
  { "month": "2026-11", "city": "Boston", "region": "North", "orders": 43, "revenue": 5164 },
  { "month": "2026-11", "city": "Chicago", "region": "North", "orders": 56, "revenue": 5741 },
  { "month": "2026-11", "city": "Austin", "region": "South", "orders": 44, "revenue": 6318 },
  { "month": "2026-11", "city": "Miami", "region": "South", "orders": 57, "revenue": 4495 },
  { "month": "2026-11", "city": "Denver", "region": "West", "orders": 45, "revenue": 5072 },
  { "month": "2026-12", "city": "Boston", "region": "North", "orders": 50, "revenue": 6255 },
  { "month": "2026-12", "city": "Chicago", "region": "North", "orders": 63, "revenue": 4432 },
  { "month": "2026-12", "city": "Austin", "region": "South", "orders": 51, "revenue": 5009 },
  { "month": "2026-12", "city": "Miami", "region": "South", "orders": 64, "revenue": 5586 },
  { "month": "2026-12", "city": "Denver", "region": "West", "orders": 52, "revenue": 6163 }
]
```

{% endtab %}
{% endtabs %}

## Usage

```json
{
  "type": "RCard",
  "props": { "title": "Revenue by month", "classes": { "rootExtra": "relative h-72" } },
  "items": [
    {
      "type": "RPlotly",
      "bind": { "query": "SELECT [month], SUM(revenue) AS revenue FROM orders GROUP BY [month]" },
      "props": {
        "layout": { "margin": { "l": 48, "r": 8, "t": 8, "b": 32 }, "xaxis": { "type": "category" } },
        "contents": [
          { "type": "scatter", "mode": "lines+markers", "x": "{{month}}", "y": "{{revenue}}" }
        ]
      }
    }
  ]
}
```

A Plotly item draws a chart with [Plotly](https://plotly.com/javascript/) 2.35. You write the chart as Plotly does:

* `contents` is Plotly's `data`: the list of **traces** (a bar series, a line, a pie, a map). Any [trace type](https://plotly.com/javascript/reference/) works.
* `layout` is Plotly's [`layout`](https://plotly.com/javascript/reference/layout/): axes, legend, margins, colours.
* `config` is Plotly's [`config`](https://plotly.com/javascript/configuration-options/).

The query's values go into the traces through placeholders, described below. Plotly is loaded the first time a dashboard shows a Plotly chart, so the chart shows "Loading..." for a moment the first time.

For common charts, the [Plotly presets](https://docs.rierino.com/sdk-dv-ui/charts/plotly-presets.md) set all of this up and only need a query.

## Placeholders

A text value in a trace written as `{{field}}` is replaced by the values of that field in **all** the rows, in order: with six rows, `"x": "{{month}}"` becomes a list of six months. Write `{{field[0]}}` for the value of **one** row, here the first.

| In `contents`                | Becomes                                                 |
| ---------------------------- | ------------------------------------------------------- |
| `"y": "{{revenue}}"`         | `"y": [21770, 22425, 25480, 23735, 26790, 27445]`       |
| `"value": "{{progress[0]}}"` | `"value": 0.72`                                         |
| `"x": ["{{share[0]}}"]`      | `"x": [0.54]`: each text item of a list is replaced too |

{% hint style="warning" %}
**Where placeholders work**

* **Only in `contents`**, not in `layout` or `config`.
* **At the top level of a trace**, such as `x`, `y`, `name`, `text`, `value`. A placeholder inside an object, such as `marker.color`, stays as text unless `deepCheck` is set (see [Values in nested settings](#values-in-nested-settings)), and even then only one level down.
* **Field names of letters, digits and `_`**. Rename other fields in the query (`AS`).
  {% endhint %}

When the query returns no rows, the chart is drawn with its traces as written, so an empty chart (axes only) is shown.

## Examples

### Several traces

Each entry of `contents` is a trace, and all of them get the same rows. Here revenue is drawn as bars and the number of orders as a line on a second axis.

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue and orders", "classes": { "rootExtra": "relative h-72" } },
    "items": [
      {
        "type": "RPlotly",
        "bind": {
          "query": "SELECT [month], SUM(revenue) AS revenue, SUM(orders) AS orders FROM orders GROUP BY [month]"
        },
        "props": {
          "layout": {
            "margin": { "l": 48, "r": 40, "t": 8, "b": 32 },
            "xaxis": { "type": "category" },
            "yaxis2": { "overlaying": "y", "side": "right", "showgrid": false },
            "showlegend": true,
            "legend": { "orientation": "h", "y": 1.15 }
          },
          "contents": [
            {
              "type": "bar",
              "name": "Revenue",
              "x": "{{month}}",
              "y": "{{revenue}}",
              "marker": { "color": "#c9b8ff" }
            },
            {
              "type": "scatter",
              "mode": "lines+markers",
              "name": "Orders",
              "x": "{{month}}",
              "y": "{{orders}}",
              "yaxis": "y2",
              "line": { "color": "#9a42ff" }
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`orders` (30 rows)

```json
[
  { "month": "2026-07", "city": "Boston", "region": "North", "orders": 40, "revenue": 3200 },
  { "month": "2026-07", "city": "Chicago", "region": "North", "orders": 53, "revenue": 3777 },
  { "month": "2026-07", "city": "Austin", "region": "South", "orders": 41, "revenue": 4354 },
  { "month": "2026-07", "city": "Miami", "region": "South", "orders": 54, "revenue": 4931 },
  { "month": "2026-07", "city": "Denver", "region": "West", "orders": 42, "revenue": 5508 },
  { "month": "2026-08", "city": "Boston", "region": "North", "orders": 47, "revenue": 4291 },
  { "month": "2026-08", "city": "Chicago", "region": "North", "orders": 60, "revenue": 4868 },
  { "month": "2026-08", "city": "Austin", "region": "South", "orders": 48, "revenue": 5445 },
  { "month": "2026-08", "city": "Miami", "region": "South", "orders": 61, "revenue": 3622 },
  { "month": "2026-08", "city": "Denver", "region": "West", "orders": 49, "revenue": 4199 },
  { "month": "2026-09", "city": "Boston", "region": "North", "orders": 54, "revenue": 5382 },
  { "month": "2026-09", "city": "Chicago", "region": "North", "orders": 42, "revenue": 5959 },
  { "month": "2026-09", "city": "Austin", "region": "South", "orders": 55, "revenue": 4136 },
  { "month": "2026-09", "city": "Miami", "region": "South", "orders": 43, "revenue": 4713 },
  { "month": "2026-09", "city": "Denver", "region": "West", "orders": 56, "revenue": 5290 },
  { "month": "2026-10", "city": "Boston", "region": "North", "orders": 61, "revenue": 4073 },
  { "month": "2026-10", "city": "Chicago", "region": "North", "orders": 49, "revenue": 4650 },
  { "month": "2026-10", "city": "Austin", "region": "South", "orders": 62, "revenue": 5227 },
  { "month": "2026-10", "city": "Miami", "region": "South", "orders": 50, "revenue": 5804 },
  { "month": "2026-10", "city": "Denver", "region": "West", "orders": 63, "revenue": 3981 },
  { "month": "2026-11", "city": "Boston", "region": "North", "orders": 43, "revenue": 5164 },
  { "month": "2026-11", "city": "Chicago", "region": "North", "orders": 56, "revenue": 5741 },
  { "month": "2026-11", "city": "Austin", "region": "South", "orders": 44, "revenue": 6318 },
  { "month": "2026-11", "city": "Miami", "region": "South", "orders": 57, "revenue": 4495 },
  { "month": "2026-11", "city": "Denver", "region": "West", "orders": 45, "revenue": 5072 },
  { "month": "2026-12", "city": "Boston", "region": "North", "orders": 50, "revenue": 6255 },
  { "month": "2026-12", "city": "Chicago", "region": "North", "orders": 63, "revenue": 4432 },
  { "month": "2026-12", "city": "Austin", "region": "South", "orders": 51, "revenue": 5009 },
  { "month": "2026-12", "city": "Miami", "region": "South", "orders": 64, "revenue": 5586 },
  { "month": "2026-12", "city": "Denver", "region": "West", "orders": 52, "revenue": 6163 }
]
```

{% endtab %}
{% endtabs %}

### A trace per group

With `groupContents` set to a field, the rows are split by that field's value, and the **first** entry of `contents` is drawn once per group, with that group's rows. `{{region[0]}}` names each trace after its group. Rows without a value for the field go in a group called `-`.

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue by region", "classes": { "rootExtra": "relative h-72" } },
    "items": [
      {
        "type": "RPlotly",
        "bind": {
          "query": "SELECT region, [month], SUM(revenue) AS revenue FROM orders GROUP BY region, [month] ORDER BY [month]"
        },
        "props": {
          "groupContents": "region",
          "layout": {
            "margin": { "l": 48, "r": 8, "t": 8, "b": 32 },
            "xaxis": { "type": "category" },
            "showlegend": true,
            "colorway": ["#9a42ff", "#5f59cf", "#ff7e47"]
          },
          "contents": [
            {
              "type": "scatter",
              "mode": "lines",
              "name": "{{region[0]}}",
              "x": "{{month}}",
              "y": "{{revenue}}"
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`orders` (30 rows)

```json
[
  { "month": "2026-07", "city": "Boston", "region": "North", "orders": 40, "revenue": 3200 },
  { "month": "2026-07", "city": "Chicago", "region": "North", "orders": 53, "revenue": 3777 },
  { "month": "2026-07", "city": "Austin", "region": "South", "orders": 41, "revenue": 4354 },
  { "month": "2026-07", "city": "Miami", "region": "South", "orders": 54, "revenue": 4931 },
  { "month": "2026-07", "city": "Denver", "region": "West", "orders": 42, "revenue": 5508 },
  { "month": "2026-08", "city": "Boston", "region": "North", "orders": 47, "revenue": 4291 },
  { "month": "2026-08", "city": "Chicago", "region": "North", "orders": 60, "revenue": 4868 },
  { "month": "2026-08", "city": "Austin", "region": "South", "orders": 48, "revenue": 5445 },
  { "month": "2026-08", "city": "Miami", "region": "South", "orders": 61, "revenue": 3622 },
  { "month": "2026-08", "city": "Denver", "region": "West", "orders": 49, "revenue": 4199 },
  { "month": "2026-09", "city": "Boston", "region": "North", "orders": 54, "revenue": 5382 },
  { "month": "2026-09", "city": "Chicago", "region": "North", "orders": 42, "revenue": 5959 },
  { "month": "2026-09", "city": "Austin", "region": "South", "orders": 55, "revenue": 4136 },
  { "month": "2026-09", "city": "Miami", "region": "South", "orders": 43, "revenue": 4713 },
  { "month": "2026-09", "city": "Denver", "region": "West", "orders": 56, "revenue": 5290 },
  { "month": "2026-10", "city": "Boston", "region": "North", "orders": 61, "revenue": 4073 },
  { "month": "2026-10", "city": "Chicago", "region": "North", "orders": 49, "revenue": 4650 },
  { "month": "2026-10", "city": "Austin", "region": "South", "orders": 62, "revenue": 5227 },
  { "month": "2026-10", "city": "Miami", "region": "South", "orders": 50, "revenue": 5804 },
  { "month": "2026-10", "city": "Denver", "region": "West", "orders": 63, "revenue": 3981 },
  { "month": "2026-11", "city": "Boston", "region": "North", "orders": 43, "revenue": 5164 },
  { "month": "2026-11", "city": "Chicago", "region": "North", "orders": 56, "revenue": 5741 },
  { "month": "2026-11", "city": "Austin", "region": "South", "orders": 44, "revenue": 6318 },
  { "month": "2026-11", "city": "Miami", "region": "South", "orders": 57, "revenue": 4495 },
  { "month": "2026-11", "city": "Denver", "region": "West", "orders": 45, "revenue": 5072 },
  { "month": "2026-12", "city": "Boston", "region": "North", "orders": 50, "revenue": 6255 },
  { "month": "2026-12", "city": "Chicago", "region": "North", "orders": 63, "revenue": 4432 },
  { "month": "2026-12", "city": "Austin", "region": "South", "orders": 51, "revenue": 5009 },
  { "month": "2026-12", "city": "Miami", "region": "South", "orders": 64, "revenue": 5586 },
  { "month": "2026-12", "city": "Denver", "region": "West", "orders": 52, "revenue": 6163 }
]
```

{% endtab %}
{% endtabs %}

```json
{
  "groupContents": "region",
  "contents": [
    { "type": "scatter", "mode": "lines", "name": "{{region[0]}}", "x": "{{month}}", "y": "{{revenue}}" }
  ]
}
```

### A trace per row

With `repeatContents: true`, the first entry of `contents` is drawn once **per row**, with only that row, so each row gets its own name, colour and legend entry. Here each sales channel is one segment of a stacked bar (`barmode: "stack"` in `layout`).

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "channels", "url": "SourceVisData?queryId=channels", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue by channel", "classes": { "rootExtra": "relative h-44" } },
    "items": [
      {
        "type": "RPlotly",
        "bind": { "query": "SELECT channel, share FROM channels" },
        "props": {
          "repeatContents": true,
          "layout": {
            "barmode": "stack",
            "margin": { "l": 8, "r": 8, "t": 8, "b": 8 },
            "xaxis": { "visible": false },
            "yaxis": { "visible": false },
            "showlegend": true,
            "legend": { "orientation": "h", "traceorder": "normal" },
            "colorway": ["#9a42ff", "#5f59cf", "#ff7e47"]
          },
          "contents": [
            {
              "type": "bar",
              "orientation": "h",
              "name": "{{channel[0]}}",
              "x": ["{{share[0]}}"],
              "y": ["Share"],
              "text": ["{{channel[0]}}"],
              "hoverinfo": "name+x"
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`channels` (3 rows)

```json
[
  { "channel": "Web store", "share": 0.54 },
  { "channel": "Mobile app", "share": 0.31 },
  { "channel": "Marketplace", "share": 0.15 }
]
```

{% endtab %}
{% endtabs %}

```json
{
  "repeatContents": true,
  "contents": [
    { "type": "bar", "orientation": "h", "name": "{{channel[0]}}", "x": ["{{share[0]}}"], "y": ["Share"] }
  ]
}
```

`groupContents` takes precedence over `repeatContents`. Both use only the first entry of `contents`; any others are ignored.

### Values in nested settings

Set `deepCheck: true` to also replace placeholders in objects inside a trace, such as `marker`. Here the query works out a colour for each city, and `marker.color` takes them.

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Cities above $29,500", "classes": { "rootExtra": "relative h-72" } },
    "items": [
      {
        "type": "RPlotly",
        "bind": {
          "query": "SELECT city, SUM(revenue) AS revenue, CASE WHEN SUM(revenue) > 29500 THEN '#9a42ff' ELSE '#d9c6ff' END AS color FROM orders GROUP BY city"
        },
        "props": {
          "deepCheck": true,
          "layout": { "margin": { "l": 48, "r": 8, "t": 8, "b": 32 } },
          "contents": [
            {
              "type": "bar",
              "x": "{{city}}",
              "y": "{{revenue}}",
              "marker": { "color": "{{color}}" }
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`orders` (30 rows)

```json
[
  { "month": "2026-07", "city": "Boston", "region": "North", "orders": 40, "revenue": 3200 },
  { "month": "2026-07", "city": "Chicago", "region": "North", "orders": 53, "revenue": 3777 },
  { "month": "2026-07", "city": "Austin", "region": "South", "orders": 41, "revenue": 4354 },
  { "month": "2026-07", "city": "Miami", "region": "South", "orders": 54, "revenue": 4931 },
  { "month": "2026-07", "city": "Denver", "region": "West", "orders": 42, "revenue": 5508 },
  { "month": "2026-08", "city": "Boston", "region": "North", "orders": 47, "revenue": 4291 },
  { "month": "2026-08", "city": "Chicago", "region": "North", "orders": 60, "revenue": 4868 },
  { "month": "2026-08", "city": "Austin", "region": "South", "orders": 48, "revenue": 5445 },
  { "month": "2026-08", "city": "Miami", "region": "South", "orders": 61, "revenue": 3622 },
  { "month": "2026-08", "city": "Denver", "region": "West", "orders": 49, "revenue": 4199 },
  { "month": "2026-09", "city": "Boston", "region": "North", "orders": 54, "revenue": 5382 },
  { "month": "2026-09", "city": "Chicago", "region": "North", "orders": 42, "revenue": 5959 },
  { "month": "2026-09", "city": "Austin", "region": "South", "orders": 55, "revenue": 4136 },
  { "month": "2026-09", "city": "Miami", "region": "South", "orders": 43, "revenue": 4713 },
  { "month": "2026-09", "city": "Denver", "region": "West", "orders": 56, "revenue": 5290 },
  { "month": "2026-10", "city": "Boston", "region": "North", "orders": 61, "revenue": 4073 },
  { "month": "2026-10", "city": "Chicago", "region": "North", "orders": 49, "revenue": 4650 },
  { "month": "2026-10", "city": "Austin", "region": "South", "orders": 62, "revenue": 5227 },
  { "month": "2026-10", "city": "Miami", "region": "South", "orders": 50, "revenue": 5804 },
  { "month": "2026-10", "city": "Denver", "region": "West", "orders": 63, "revenue": 3981 },
  { "month": "2026-11", "city": "Boston", "region": "North", "orders": 43, "revenue": 5164 },
  { "month": "2026-11", "city": "Chicago", "region": "North", "orders": 56, "revenue": 5741 },
  { "month": "2026-11", "city": "Austin", "region": "South", "orders": 44, "revenue": 6318 },
  { "month": "2026-11", "city": "Miami", "region": "South", "orders": 57, "revenue": 4495 },
  { "month": "2026-11", "city": "Denver", "region": "West", "orders": 45, "revenue": 5072 },
  { "month": "2026-12", "city": "Boston", "region": "North", "orders": 50, "revenue": 6255 },
  { "month": "2026-12", "city": "Chicago", "region": "North", "orders": 63, "revenue": 4432 },
  { "month": "2026-12", "city": "Austin", "region": "South", "orders": 51, "revenue": 5009 },
  { "month": "2026-12", "city": "Miami", "region": "South", "orders": 64, "revenue": 5586 },
  { "month": "2026-12", "city": "Denver", "region": "West", "orders": 52, "revenue": 6163 }
]
```

{% endtab %}
{% endtabs %}

```json
{
  "deepCheck": true,
  "contents": [
    { "type": "bar", "x": "{{city}}", "y": "{{revenue}}", "marker": { "color": "{{color}}" } }
  ]
}
```

Only one level down: `marker.color` works, `marker.line.color` doesn't. A `layout` with `barmode: "stack"` turns `deepCheck` on by itself.

### A single value

`{{field[0]}}` takes one value, for traces such as Plotly's [indicator](https://plotly.com/javascript/indicator/) (a number or a gauge):

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "goals", "url": "SourceVisData?queryId=goals", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue goal", "classes": { "rootExtra": "relative h-64" } },
    "items": [
      {
        "type": "RPlotly",
        "bind": { "query": "SELECT progress FROM goals WHERE goal = 'Revenue'" },
        "props": {
          "layout": { "margin": { "l": 24, "r": 24, "t": 16, "b": 8 } },
          "contents": [
            {
              "type": "indicator",
              "mode": "gauge+number",
              "value": "{{progress[0]}}",
              "number": { "valueformat": ".0%" },
              "gauge": {
                "axis": { "range": [0, 1], "tickformat": ".0%" },
                "bar": { "color": "#9a42ff" }
              }
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`goals` (3 rows)

```json
[
  { "goal": "Revenue", "progress": 0.72 },
  { "goal": "New customers", "progress": 0.45 },
  { "goal": "Repeat orders", "progress": 0.9 }
]
```

{% endtab %}
{% endtabs %}

```json
{
  "type": "indicator",
  "mode": "gauge+number",
  "value": "{{progress[0]}}",
  "number": { "valueformat": ".0%" },
  "gauge": { "axis": { "range": [0, 1], "tickformat": ".0%" }, "bar": { "color": "#9a42ff" } }
}
```

### Without a query

With no `bind`, the traces are drawn as written, so the values can be part of the definition:

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [],
  "layout": {
    "type": "RCard",
    "props": { "title": "Targets by quarter", "classes": { "rootExtra": "relative h-64" } },
    "items": [
      {
        "type": "RPlotly",
        "props": {
          "layout": { "margin": { "l": 48, "r": 8, "t": 8, "b": 32 } },
          "contents": [
            {
              "type": "bar",
              "x": ["Q1", "Q2", "Q3", "Q4"],
              "y": [60000, 72000, 75000, 90000],
              "marker": { "color": "#5f59cf" }
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

### Annotation

`annotation` is HTML shown next to the chart, such as a total. It's fixed: placeholders don't work in it. With an annotation, the chart and the annotation each take half the width, the annotation on the right. They sit side by side only inside a flex container, so put the chart in a [Row](https://docs.rierino.com/sdk-dv-ui/layout/container.md) that fills its card:

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue by month", "classes": { "rootExtra": "relative h-64" } },
    "items": [
      {
        "type": "RRow",
        "props": { "classes": { "rootExtra": "h-full" } },
        "items": [
          {
            "type": "RPlotly",
            "bind": {
              "query": "SELECT [month], SUM(revenue) AS revenue FROM orders GROUP BY [month]"
            },
            "props": {
              "annotation": "<div><div class='text-regular-22 text-paris-m'>$147,645</div><div class='text-lynch text-sm'>up 26% since July</div></div>",
              "classes": { "annotationExtra": "flex items-center justify-center" },
              "layout": {
                "margin": { "l": 8, "r": 8, "t": 8, "b": 8 },
                "xaxis": { "visible": false },
                "yaxis": { "visible": false }
              },
              "contents": [
                {
                  "type": "bar",
                  "x": "{{month}}",
                  "y": "{{revenue}}",
                  "marker": { "color": "#9a42ff" }
                }
              ]
            }
          }
        ]
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`orders` (30 rows)

```json
[
  { "month": "2026-07", "city": "Boston", "region": "North", "orders": 40, "revenue": 3200 },
  { "month": "2026-07", "city": "Chicago", "region": "North", "orders": 53, "revenue": 3777 },
  { "month": "2026-07", "city": "Austin", "region": "South", "orders": 41, "revenue": 4354 },
  { "month": "2026-07", "city": "Miami", "region": "South", "orders": 54, "revenue": 4931 },
  { "month": "2026-07", "city": "Denver", "region": "West", "orders": 42, "revenue": 5508 },
  { "month": "2026-08", "city": "Boston", "region": "North", "orders": 47, "revenue": 4291 },
  { "month": "2026-08", "city": "Chicago", "region": "North", "orders": 60, "revenue": 4868 },
  { "month": "2026-08", "city": "Austin", "region": "South", "orders": 48, "revenue": 5445 },
  { "month": "2026-08", "city": "Miami", "region": "South", "orders": 61, "revenue": 3622 },
  { "month": "2026-08", "city": "Denver", "region": "West", "orders": 49, "revenue": 4199 },
  { "month": "2026-09", "city": "Boston", "region": "North", "orders": 54, "revenue": 5382 },
  { "month": "2026-09", "city": "Chicago", "region": "North", "orders": 42, "revenue": 5959 },
  { "month": "2026-09", "city": "Austin", "region": "South", "orders": 55, "revenue": 4136 },
  { "month": "2026-09", "city": "Miami", "region": "South", "orders": 43, "revenue": 4713 },
  { "month": "2026-09", "city": "Denver", "region": "West", "orders": 56, "revenue": 5290 },
  { "month": "2026-10", "city": "Boston", "region": "North", "orders": 61, "revenue": 4073 },
  { "month": "2026-10", "city": "Chicago", "region": "North", "orders": 49, "revenue": 4650 },
  { "month": "2026-10", "city": "Austin", "region": "South", "orders": 62, "revenue": 5227 },
  { "month": "2026-10", "city": "Miami", "region": "South", "orders": 50, "revenue": 5804 },
  { "month": "2026-10", "city": "Denver", "region": "West", "orders": 63, "revenue": 3981 },
  { "month": "2026-11", "city": "Boston", "region": "North", "orders": 43, "revenue": 5164 },
  { "month": "2026-11", "city": "Chicago", "region": "North", "orders": 56, "revenue": 5741 },
  { "month": "2026-11", "city": "Austin", "region": "South", "orders": 44, "revenue": 6318 },
  { "month": "2026-11", "city": "Miami", "region": "South", "orders": 57, "revenue": 4495 },
  { "month": "2026-11", "city": "Denver", "region": "West", "orders": 45, "revenue": 5072 },
  { "month": "2026-12", "city": "Boston", "region": "North", "orders": 50, "revenue": 6255 },
  { "month": "2026-12", "city": "Chicago", "region": "North", "orders": 63, "revenue": 4432 },
  { "month": "2026-12", "city": "Austin", "region": "South", "orders": 51, "revenue": 5009 },
  { "month": "2026-12", "city": "Miami", "region": "South", "orders": 64, "revenue": 5586 },
  { "month": "2026-12", "city": "Denver", "region": "West", "orders": 52, "revenue": 6163 }
]
```

{% endtab %}
{% endtabs %}

```json
{
  "type": "RRow",
  "props": { "classes": { "rootExtra": "h-full" } },
  "items": [
    {
      "type": "RPlotly",
      "props": {
        "annotation": "<div><div class='text-regular-22 text-paris-m'>$147,645</div><div class='text-lynch text-sm'>up 26% since July</div></div>",
        "classes": { "annotationExtra": "flex items-center justify-center" }
      }
    }
  ]
}
```

The annotation's HTML isn't sanitized: write it in the definition, never from user input.

### Toolbar

Plotly's toolbar (zoom, pan, download as PNG) is hidden. Turn it on in `config`; it shows when the pointer is over the chart.

{% tabs %}
{% tab title="Definition" %}

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Orders by month", "classes": { "rootExtra": "relative h-72" } },
    "items": [
      {
        "type": "RPlotly",
        "bind": { "query": "SELECT [month], SUM(orders) AS orders FROM orders GROUP BY [month]" },
        "props": {
          "config": { "displayModeBar": true, "displaylogo": false },
          "layout": {
            "margin": { "l": 48, "r": 8, "t": 24, "b": 32 },
            "xaxis": { "type": "category" },
            "hovermode": "x"
          },
          "contents": [
            {
              "type": "bar",
              "name": "Orders",
              "x": "{{month}}",
              "y": "{{orders}}",
              "marker": { "color": "#5f59cf" }
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Sample data" %}
The rows the dashboard's sources return.

`orders` (30 rows)

```json
[
  { "month": "2026-07", "city": "Boston", "region": "North", "orders": 40, "revenue": 3200 },
  { "month": "2026-07", "city": "Chicago", "region": "North", "orders": 53, "revenue": 3777 },
  { "month": "2026-07", "city": "Austin", "region": "South", "orders": 41, "revenue": 4354 },
  { "month": "2026-07", "city": "Miami", "region": "South", "orders": 54, "revenue": 4931 },
  { "month": "2026-07", "city": "Denver", "region": "West", "orders": 42, "revenue": 5508 },
  { "month": "2026-08", "city": "Boston", "region": "North", "orders": 47, "revenue": 4291 },
  { "month": "2026-08", "city": "Chicago", "region": "North", "orders": 60, "revenue": 4868 },
  { "month": "2026-08", "city": "Austin", "region": "South", "orders": 48, "revenue": 5445 },
  { "month": "2026-08", "city": "Miami", "region": "South", "orders": 61, "revenue": 3622 },
  { "month": "2026-08", "city": "Denver", "region": "West", "orders": 49, "revenue": 4199 },
  { "month": "2026-09", "city": "Boston", "region": "North", "orders": 54, "revenue": 5382 },
  { "month": "2026-09", "city": "Chicago", "region": "North", "orders": 42, "revenue": 5959 },
  { "month": "2026-09", "city": "Austin", "region": "South", "orders": 55, "revenue": 4136 },
  { "month": "2026-09", "city": "Miami", "region": "South", "orders": 43, "revenue": 4713 },
  { "month": "2026-09", "city": "Denver", "region": "West", "orders": 56, "revenue": 5290 },
  { "month": "2026-10", "city": "Boston", "region": "North", "orders": 61, "revenue": 4073 },
  { "month": "2026-10", "city": "Chicago", "region": "North", "orders": 49, "revenue": 4650 },
  { "month": "2026-10", "city": "Austin", "region": "South", "orders": 62, "revenue": 5227 },
  { "month": "2026-10", "city": "Miami", "region": "South", "orders": 50, "revenue": 5804 },
  { "month": "2026-10", "city": "Denver", "region": "West", "orders": 63, "revenue": 3981 },
  { "month": "2026-11", "city": "Boston", "region": "North", "orders": 43, "revenue": 5164 },
  { "month": "2026-11", "city": "Chicago", "region": "North", "orders": 56, "revenue": 5741 },
  { "month": "2026-11", "city": "Austin", "region": "South", "orders": 44, "revenue": 6318 },
  { "month": "2026-11", "city": "Miami", "region": "South", "orders": 57, "revenue": 4495 },
  { "month": "2026-11", "city": "Denver", "region": "West", "orders": 45, "revenue": 5072 },
  { "month": "2026-12", "city": "Boston", "region": "North", "orders": 50, "revenue": 6255 },
  { "month": "2026-12", "city": "Chicago", "region": "North", "orders": 63, "revenue": 4432 },
  { "month": "2026-12", "city": "Austin", "region": "South", "orders": 51, "revenue": 5009 },
  { "month": "2026-12", "city": "Miami", "region": "South", "orders": 64, "revenue": 5586 },
  { "month": "2026-12", "city": "Denver", "region": "West", "orders": 52, "revenue": 6163 }
]
```

{% endtab %}
{% endtabs %}

```json
{ "config": { "displayModeBar": true, "displaylogo": false } }
```

## Size and axes

The chart fills the item it's in: give its [Card](https://docs.rierino.com/sdk-dv-ui/layout/card.md) or cell a height. With no height around it, the chart is 450px tall, Plotly's default. `width` and `height` set a size in pixels instead.

The built-in `layout` has these defaults, which your `layout` is merged onto:

```json
{
  "plot_bgcolor": "#FFFFFF",
  "showlegend": false,
  "margin": { "b": 0, "l": 0, "r": 0, "t": 20 },
  "hoverlabel": {
    "bgcolor": "#FFFFFF",
    "bordercolor": "#FFFFFF",
    "font": { "color": "#363B4A", "family": "Montserrat", "size": 11 }
  }
}
```

{% hint style="warning" %}
**Axis labels need margins**

With margins of `0`, the axis labels are drawn outside the chart and can't be seen. Set `layout.margin` (such as `{ "l": 48, "b": 32 }`) to show them, or hide the axes with `"xaxis": { "visible": false }`.
{% endhint %}

Plotly reads text like `2026-07` as a date and labels it `Jul 2026`. Set `"xaxis": { "type": "category" }` to show the values as they are.

`showlegend` is `false`: set it to `true` for charts with several traces.

## Maps

Map traces (`choropleth`, `scattergeo`) load their map from `https://cdn.plot.ly/` when shown. To serve the map files yourself, for example behind a strict Content Security Policy, set `config.topojsonURL` to the folder they're in (they come with plotly.js, in `dist/topojson/`). See the [Choropleth preset](https://docs.rierino.com/sdk-dv-ui/charts/plotly-presets.md#choropleth).

## Props

| Prop             | Type       | Default                     | Description                                                           |
| ---------------- | ---------- | --------------------------- | --------------------------------------------------------------------- |
| `contents`       | `object[]` | `[]`                        | The traces (Plotly `data`), with placeholders for the query's values. |
| `layout`         | `object`   |                             | Plotly layout, merged onto the defaults above.                        |
| `config`         | `object`   | `{ displayModeBar: false }` | Plotly config, merged onto the default.                               |
| `groupContents`  | `string`   |                             | Field to split the rows by: the first trace is drawn once per value.  |
| `repeatContents` | `boolean`  | `false`                     | Draw the first trace once per row.                                    |
| `deepCheck`      | `boolean`  | `false`                     | Also replace placeholders one level down in each trace.               |
| `width`          | `number`   |                             | Width in pixels. Without it, the chart fills its item.                |
| `height`         | `number`   |                             | Height in pixels. Without it, the chart fills its item.               |
| `annotation`     | `string`   |                             | HTML shown next to the chart.                                         |
| `sample`         | `object[]` |                             | Rows used when there is no data, for designing.                       |
| `classes`        | `object`   |                             | Class names for the parts, see Classes below.                         |

In the Rierino designer: **Width**, **Height**, **Config**, **Layout**, **Contents** (JSON), **Annotation** (HTML) and **Classes**. `groupContents`, `repeatContents`, `deepCheck` and `sample` aren't in the designer: set them in the item's JSON.

## Classes

| Part           | Built-in classes | Styles                                              |
| -------------- | ---------------- | --------------------------------------------------- |
| `notAnnotated` | `w-full h-full`  | The chart, without an annotation                    |
| `annotated`    | `h-full w-6/12`  | The chart **and** the annotation, when there is one |
| `annotation`   | `order-2`        | The annotation                                      |

Set `classes.<part>` to replace the built-in classes, or `classes.<part>Extra` to add to them.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-dv-ui/charts/plotly.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
