> 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/echarts.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# E-Charts

Draws any Apache ECharts chart, with the query's rows as its data.

{% 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": "RECharts",
        "bind": {
          "query": "SELECT [month], SUM(revenue) AS revenue FROM orders GROUP BY [month]"
        },
        "props": {
          "style": { "height": 230 },
          "option": {
            "xAxis": { "show": true, "type": "category" },
            "yAxis": { "show": true },
            "tooltip": { "show": true, "trigger": "axis" },
            "grid": { "left": 48, "right": 16, "top": 16, "bottom": 24 },
            "series": [
              {
                "type": "line",
                "smooth": true,
                "encode": { "x": "month", "y": "revenue" },
                "itemStyle": { "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": "RECharts",
      "bind": { "query": "SELECT [month], SUM(revenue) AS revenue FROM orders GROUP BY [month]" },
      "props": {
        "style": { "height": 230 },
        "option": {
          "xAxis": { "show": true, "type": "category" },
          "yAxis": { "show": true },
          "tooltip": { "show": true, "trigger": "axis" },
          "grid": { "left": 48, "right": 16, "top": 16, "bottom": 24 },
          "series": [{ "type": "line", "smooth": true, "encode": { "x": "month", "y": "revenue" } }]
        }
      }
    }
  ]
}
```

An E-Charts item draws a chart with [Apache ECharts](https://echarts.apache.org/) 5. `option` is the chart's ECharts [option](https://echarts.apache.org/en/option.html), written as in ECharts: `series` (the bars, lines, slices), axes, `legend`, `tooltip`, `grid`, `color` and so on.

The query's rows become the chart's [dataset](https://echarts.apache.org/en/tutorial.html#Dataset), and each series picks the fields it draws with `encode`. A few kinds of chart take the rows another way; see [Placeholders](#placeholders).

{% hint style="warning" %}
**Turn on the axes and the tooltip**

The built-in option hides the x axis, the y axis and the tooltip. Set `"show": true` on the ones you want, as above.
{% endhint %}

{% hint style="danger" %}
**series is required**

Without `option.series`, the chart can't be drawn, and the item it's in shows an error in place of its contents. A chart with no data yet still needs its `series`.
{% endhint %}

For common charts, the [E-Charts templates](https://docs.rierino.com/sdk-dv-ui/charts/echarts-templates.md) set the option up and only need a query.

## The query's rows

The rows are passed to ECharts as a dataset, with the **fields of the first row** as its dimensions. A series names the fields it draws in `encode`:

| Series             | `encode`                                            |
| ------------------ | --------------------------------------------------- |
| Bar, line, scatter | `x` and `y`: the fields on each axis                |
| Pie, funnel        | `itemName` (slice names) and `value` (slice sizes)  |
| Any                | `tooltip`: the fields listed in the default tooltip |

Without `encode`, ECharts takes the first field for the category axis and the next ones for the series, in order. Every series gets all the rows; to draw a subset, change the query.

Labels can show any field of the row with `{@field}`, such as `"formatter": "${@revenue}"`. Tooltip strings can't: they only know `{a}` (series name), `{b}` (name), `{c}` (value) and `{d}` (percentage, on pies). For a tooltip built from the row's fields, see [Formatting](#formatting).

## Examples

### Several series

Each entry of `series` is drawn from the same rows. Here revenue is drawn as bars and the number of orders as a line on a second axis: a list in `yAxis` replaces the built-in 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-80" } },
    "items": [
      {
        "type": "RECharts",
        "bind": {
          "query": "SELECT [month], SUM(revenue) AS revenue, SUM(orders) AS orders FROM orders GROUP BY [month]"
        },
        "props": {
          "style": { "height": 260 },
          "option": {
            "color": ["#9a42ff", "#ff7e47"],
            "legend": { "show": true, "top": 0 },
            "tooltip": { "show": true, "trigger": "axis" },
            "grid": { "left": 56, "right": 48, "top": 36, "bottom": 24 },
            "xAxis": { "show": true, "type": "category" },
            "yAxis": [
              { "type": "value", "name": "Revenue" },
              { "type": "value", "name": "Orders", "splitLine": { "show": false } }
            ],
            "series": [
              {
                "type": "bar",
                "name": "Revenue",
                "encode": { "x": "month", "y": "revenue" }
              },
              {
                "type": "line",
                "name": "Orders",
                "yAxisIndex": 1,
                "encode": { "x": "month", "y": "orders" }
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% 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
{
  "yAxis": [
    { "type": "value", "name": "Revenue" },
    { "type": "value", "name": "Orders", "splitLine": { "show": false } }
  ],
  "series": [
    { "type": "bar", "name": "Revenue", "encode": { "x": "month", "y": "revenue" } },
    { "type": "line", "name": "Orders", "yAxisIndex": 1, "encode": { "x": "month", "y": "orders" } }
  ]
}
```

### Horizontal bars

Swap the axes: the value axis is `xAxis`, the category axis `yAxis`. ECharts draws the first row at the bottom, so the query sorts in ascending order to put the largest bar on top.

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

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue by city", "classes": { "rootExtra": "relative h-72" } },
    "items": [
      {
        "type": "RECharts",
        "bind": {
          "query": "SELECT city, SUM(revenue) AS revenue FROM orders GROUP BY city ORDER BY revenue"
        },
        "props": {
          "style": { "height": 230 },
          "option": {
            "tooltip": { "show": true },
            "grid": { "left": 16, "right": 56, "top": 8, "bottom": 8, "containLabel": true },
            "xAxis": { "type": "value" },
            "yAxis": { "show": true, "type": "category", "axisTick": { "show": false } },
            "series": [
              {
                "type": "bar",
                "encode": { "x": "revenue", "y": "city" },
                "itemStyle": { "color": "#9a42ff", "borderRadius": [0, 6, 6, 0] },
                "label": { "show": true, "position": "right", "formatter": "${@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 %}

### Pie

{% 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-72" } },
    "items": [
      {
        "type": "RECharts",
        "bind": { "query": "SELECT channel, share FROM channels" },
        "props": {
          "style": { "height": 230 },
          "option": {
            "color": ["#9a42ff", "#ff7e47", "#22c55e"],
            "tooltip": { "show": true, "formatter": "{b}: {d}%" },
            "legend": { "show": true, "orient": "vertical", "right": 0, "top": "middle" },
            "series": [
              {
                "type": "pie",
                "radius": ["45%", "75%"],
                "center": ["35%", "50%"],
                "encode": { "itemName": "channel", "value": "share" },
                "label": { "show": false }
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% 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
{
  "tooltip": { "show": true, "formatter": "{b}: {d}%" },
  "legend": { "show": true, "orient": "vertical", "right": 0, "top": "middle" },
  "series": [
    {
      "type": "pie",
      "radius": ["45%", "75%"],
      "encode": { "itemName": "channel", "value": "share" },
      "label": { "show": false }
    }
  ]
}
```

### Scatter

One point per row. `encode.tooltip` lists the fields shown on hover.

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

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": {
      "title": "Orders and revenue, by city and month",
      "classes": { "rootExtra": "relative h-80" }
    },
    "items": [
      {
        "type": "RECharts",
        "bind": { "query": "SELECT orders, revenue, city, [month] FROM orders" },
        "props": {
          "style": { "height": 260 },
          "option": {
            "tooltip": { "show": true },
            "grid": { "left": 56, "right": 16, "top": 16, "bottom": 40 },
            "xAxis": {
              "show": true,
              "type": "value",
              "name": "Orders",
              "nameLocation": "middle",
              "nameGap": 26,
              "min": 35
            },
            "yAxis": { "show": true, "type": "value", "min": 3000 },
            "series": [
              {
                "type": "scatter",
                "symbolSize": 10,
                "encode": {
                  "x": "orders",
                  "y": "revenue",
                  "tooltip": ["city", "month", "orders", "revenue"]
                },
                "itemStyle": { "color": "#9a42ff", "opacity": 0.7 }
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% 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 %}

### Stacked bars

Series with the same `stack` are drawn on top of each other. Give each part its own field in the query, here with a `CASE` per region, and draw each field as a series:

{% 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-80" } },
    "items": [
      {
        "type": "RECharts",
        "bind": {
          "query": "SELECT [month], SUM(revenue) AS revenue, SUM(CASE WHEN region = 'North' THEN revenue ELSE 0 END) AS north, SUM(CASE WHEN region = 'South' THEN revenue ELSE 0 END) AS south, SUM(CASE WHEN region = 'West' THEN revenue ELSE 0 END) AS west FROM orders GROUP BY [month]"
        },
        "props": {
          "style": { "height": 260 },
          "option": {
            "color": ["#363b4a", "#9a42ff", "#ff7e47", "#22c55e"],
            "legend": { "show": true, "top": 0 },
            "tooltip": { "show": true, "trigger": "axis" },
            "grid": { "left": 56, "right": 16, "top": 36, "bottom": 24 },
            "xAxis": { "show": true, "type": "category" },
            "yAxis": { "show": true },
            "series": [
              {
                "type": "line",
                "name": "Total",
                "encode": { "x": "month", "y": "revenue" }
              },
              {
                "type": "bar",
                "name": "North",
                "stack": "regions",
                "encode": { "x": "month", "y": "north" }
              },
              {
                "type": "bar",
                "name": "South",
                "stack": "regions",
                "encode": { "x": "month", "y": "south" }
              },
              {
                "type": "bar",
                "name": "West",
                "stack": "regions",
                "encode": { "x": "month", "y": "west" }
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% 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
{
  "series": [
    { "type": "line", "name": "Total", "encode": { "x": "month", "y": "revenue" } },
    { "type": "bar", "name": "North", "stack": "regions", "encode": { "x": "month", "y": "north" } },
    { "type": "bar", "name": "South", "stack": "regions", "encode": { "x": "month", "y": "south" } },
    { "type": "bar", "name": "West", "stack": "regions", "encode": { "x": "month", "y": "west" } }
  ]
}
```

### Without a query

With no `bind`, the chart is drawn from the values written in its series, here a gauge:

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

```json
{
  "sources": [],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue goal", "classes": { "rootExtra": "relative h-72" } },
    "items": [
      {
        "type": "RECharts",
        "props": {
          "style": { "height": 230 },
          "option": {
            "series": [
              {
                "type": "gauge",
                "radius": "95%",
                "center": ["50%", "60%"],
                "progress": { "show": true, "width": 16 },
                "axisLine": { "lineStyle": { "width": 16 } },
                "pointer": { "show": false },
                "axisTick": { "show": false },
                "splitLine": { "show": false },
                "axisLabel": { "show": false },
                "itemStyle": { "color": "#9a42ff" },
                "title": { "offsetCenter": [0, "25%"], "fontSize": 12, "color": "#6b7280" },
                "detail": {
                  "formatter": "{value}%",
                  "fontSize": 28,
                  "offsetCenter": [0, "-5%"],
                  "color": "#363b4a"
                },
                "data": [{ "value": 72, "name": "of the quarter's goal" }]
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

```json
{
  "type": "RECharts",
  "props": {
    "style": { "height": 230 },
    "option": {
      "series": [
        {
          "type": "gauge",
          "progress": { "show": true, "width": 16 },
          "pointer": { "show": false },
          "detail": { "formatter": "{value}%" },
          "data": [{ "value": 72, "name": "of the quarter's goal" }]
        }
      ]
    }
  }
}
```

Gauges and other series that ECharts doesn't draw from a dataset can't take values from the query: write the values in the series, or use a [Plotly](https://docs.rierino.com/sdk-dv-ui/charts/plotly.md#a-single-value) indicator.

## Placeholders

Two kinds of chart can't be drawn from a dataset, so the rows go in another way:

* **A treemap** (first series `"type": "treemap"`): the rows **are** the treemap's data. Each row needs a `name` and a `value` field.
* **A stack** (first series with a `stack`): the rows go into the series through placeholders, as in a [Plotly](https://docs.rierino.com/sdk-dv-ui/charts/plotly.md#placeholders) chart. `"{{field}}"` becomes that field's values in all the rows, `"{{field[0]}}"` its value in the first row.

### Treemap

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

```json
{
  "sources": [{ "key": "orders", "url": "SourceVisData?queryId=orders", "params": {} }],
  "layout": {
    "type": "RCard",
    "props": { "title": "Revenue by city", "classes": { "rootExtra": "relative h-80" } },
    "items": [
      {
        "type": "RECharts",
        "bind": {
          "query": "SELECT city AS name, SUM(revenue) AS [value] FROM orders GROUP BY city"
        },
        "props": {
          "style": { "height": 260 },
          "option": {
            "color": ["#9a42ff", "#b57bff", "#ff7e47", "#ffa77f", "#22c55e"],
            "tooltip": { "show": true },
            "series": [
              {
                "type": "treemap",
                "roam": false,
                "nodeClick": false,
                "breadcrumb": { "show": false },
                "top": 0,
                "left": 0,
                "right": 0,
                "bottom": 0,
                "label": { "show": true, "formatter": "{b} ${c}" },
                "itemStyle": { "borderColor": "#fff", "borderWidth": 2, "gapWidth": 2 }
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% 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": "RECharts",
  "bind": { "query": "SELECT city AS name, SUM(revenue) AS [value] FROM orders GROUP BY city" },
  "props": {
    "option": {
      "series": [
        { "type": "treemap", "breadcrumb": { "show": false }, "label": { "show": true, "formatter": "{b}\n${c}" } }
      ]
    }
  }
}
```

### A series per row

In a stack, `repeatContents: true` draws the **first** series once per row, with only that row, so each row is a segment with its own name, colour and legend entry:

{% 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-48" } },
    "items": [
      {
        "type": "RECharts",
        "bind": { "query": "SELECT channel, share FROM channels" },
        "props": {
          "style": { "height": 130 },
          "repeatContents": true,
          "option": {
            "color": ["#9a42ff", "#ff7e47", "#22c55e"],
            "tooltip": { "show": true },
            "legend": { "show": true, "bottom": 0 },
            "grid": { "left": 8, "right": 8, "top": 8, "bottom": 40 },
            "xAxis": { "type": "value", "max": 1 },
            "yAxis": { "type": "category" },
            "series": [
              {
                "type": "bar",
                "stack": "total",
                "name": "{{channel[0]}}",
                "data": ["{{share[0]}}"],
                "barWidth": 24,
                "label": {
                  "show": true,
                  "_formatter": {
                    "value": "value",
                    "valueFormat": { "options": { "style": "percent" } }
                  }
                }
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% 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,
  "option": {
    "xAxis": { "type": "value", "max": 1 },
    "yAxis": { "type": "category" },
    "series": [
      {
        "type": "bar",
        "stack": "total",
        "name": "{{channel[0]}}",
        "data": ["{{share[0]}}"],
        "label": {
          "show": true,
          "_formatter": { "value": "value", "valueFormat": { "options": { "style": "percent" } } }
        }
      }
    ]
  }
}
```

Without `repeatContents`, each series is drawn once, with all the rows: `"data": "{{north}}"` draws every row's `north`.

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

* Only in the **top level of each series** (`name`, `data`), and in a treemap or with `repeatContents`, the top level of `option` (such as `"color": "{{color}}"`, all the rows' colours). Not in axes or other nested settings: a category axis can't take its labels from the query. For stacked bars with labels, use a [dataset](#stacked-bars).
* Field names of letters, digits and `_`.
  {% endhint %}

## Formatting

### Labels

`_formatter` on a series' `label` formats a number with the browser's [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat):

```json
{
  "label": {
    "show": true,
    "_formatter": {
      "value": "value",
      "valueFormat": { "locales": "en-US", "options": { "style": "percent" } }
    }
  }
}
```

`value` names the number to format, from ECharts' label [parameters](https://echarts.apache.org/en/option.html#series-bar.label.formatter): `value`, or `percent` on a pie. Without `options`, two decimals are shown.

### Tooltips with code

`_formatter` on a series' `tooltip` is a **JavaScript expression** that returns the tooltip's HTML. `params` holds the item under the pointer: `params.data` is its row.

{% 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": "RECharts",
        "bind": {
          "query": "SELECT [month], SUM(revenue) AS revenue, SUM(orders) AS orders FROM orders GROUP BY [month]"
        },
        "props": {
          "style": { "height": 230 },
          "option": {
            "tooltip": { "show": true, "trigger": "item" },
            "grid": { "left": 56, "right": 16, "top": 16, "bottom": 24 },
            "xAxis": { "show": true, "type": "category" },
            "yAxis": { "show": true },
            "series": [
              {
                "type": "bar",
                "encode": { "x": "month", "y": "revenue" },
                "itemStyle": { "color": "#9a42ff", "borderRadius": [6, 6, 0, 0] },
                "tooltip": {
                  "_formatter": "`<b>${params.data.month}</b><br/>$${params.data.revenue.toLocaleString('en-US')} from ${params.data.orders} orders`"
                }
              }
            ]
          }
        }
      }
    ]
  }
}
```

{% 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": "bar",
  "encode": { "x": "month", "y": "revenue" },
  "tooltip": {
    "_formatter": "`<b>${params.data.month}</b><br/>$${params.data.revenue.toLocaleString('en-US')} from ${params.data.orders} orders`"
  }
}
```

{% hint style="danger" %}
**Runs code from the definition**

The expression runs in the viewer's browser, with access to the page. `<Dashboard>` runs it only when it has the `allowScripts` prop; without it, the default tooltip is shown. The Rierino admin runs it. Only allow it for definitions you trust, and the page's Content Security Policy must allow `unsafe-eval`.
{% endhint %}

`_formatter` works on a series' `tooltip`, not on `option.tooltip`.

## Size

The chart is as wide as its item and **300px** tall. Set `style.height` to change the height: a number is in pixels, and text is any CSS height.

To fill a [Card](https://docs.rierino.com/sdk-dv-ui/layout/card.md) or cell that has a height, set the height to `100%` and give the item `h-full`:

```json
{
  "style": { "height": "100%" },
  "classes": { "rootExtra": "h-full" }
}
```

The chart is drawn as SVG.

## Built-in option

Your `option` is merged onto this one. Objects are merged, so `"xAxis": { "show": true }` keeps the other axis settings; a list (such as two y axes) replaces an object.

```json
{
  "tooltip": { "show": false, "textStyle": { "fontFamily": "Montserrat", "fontSize": 11, "color": "#363B4A" } },
  "xAxis": { "show": false },
  "yAxis": { "show": false }
}
```

ECharts' own defaults apply to everything else, including its colours.

## Props

| Prop             | Type       | Default | Description                                                                      |
| ---------------- | ---------- | ------- | -------------------------------------------------------------------------------- |
| `option`         | `object`   |         | **Required.** ECharts option, merged onto the built-in one. Must have `series`.  |
| `style`          | `object`   |         | CSS for the chart, mostly `height` (300px by default). The width is always 100%. |
| `repeatContents` | `boolean`  | `false` | In a stack, draw the first series once per row.                                  |
| `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: **Option** and **Style** (JSON) and **Classes**. `repeatContents` and `sample` aren't in the designer: set them in the item's JSON.

## Classes

| Part   | Built-in classes | Styles                   |
| ------ | ---------------- | ------------------------ |
| `root` | none             | The box around the chart |

Set `classes.root` to replace the built-in classes, or `classes.rootExtra` 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/echarts.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.
