> For the complete documentation index, see [llms.txt](https://docs.mediarithmics.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mediarithmics.io/setup-and-monitor/operate-and-monitor/create-a-custom-dashboard/dashboard-cookbook.md).

# Dashboard cookbook

Recipes for the dashboard shapes people build most often.

## Your goal

Get to a working dashboard faster by starting from a shape that already solves your problem.

## Before you start

These recipes are advanced-mode JSON. The structure they use - sections, cards, charts, datasets, transformations - is described in [Dashboard](/setup-and-monitor/operate-and-monitor/create-a-custom-dashboard/dashboard.md), and the workflow is in [Create a custom dashboard](/setup-and-monitor/operate-and-monitor/create-a-custom-dashboard.md).

Each `query_id` below is a placeholder: save your own query and use its ID. The comments show the query the recipe assumes.

## Friendly dates

`@date_histogram` queries return timestamps. The **`format-dates`** transformation makes them readable.

{% tabs %}
{% tab title="Single series" %}

```json
{
    "title": "Application events (last 6 months)",
    "type": "Bars",
    "dataset": {
        "type": "format-dates",
        "sources": [
            {
                // A @date_histogram query
                "type": "OTQL",
                "query_id": "666"
            }
        ],
        "date_options": {
            "format": "YYYY-MM-DD"
        }
    }
}
```

{% endtab %}

{% tab title="Multiple series" %}
The same transformation applies to the result of a `join`, so you can format the dates of several series at once - for instance monthly events per channel.

Wrap the `join` dataset in `format-dates` rather than formatting each source separately.
{% endtab %}
{% endtabs %}

## A collection volume with its history

A good way to show a collection volume is the **current number** next to a **short history**. That is two charts in one card:

* a `Metric` chart on an OTQL query such as `SELECT @count{} FROM UserPoint`,
* a `Bars` chart on a **collection volumes** query.

```json5
{
    // A small card with a vertical layout
    "x": 0,
    "y": 0,
    "h": 2,
    "w": 3,
    "layout": "vertical",
    "charts": [
        {
            "title": "UserPoint",
            "type": "Metric",
            "dataset": {
                "type": "OTQL",
                "query_id": "666"        // SELECT @count{} FROM UserPoint
            }
        },
        {
            "title": "",
            "type": "Bars",
            "dataset": {
                // format-dates so the axis shows dates, not timestamps
                "type": "format-dates",
                "sources": [
                    {
                        "type": "collection_volumes",
                        "query_json": {
                            "dimensions": [ { "name": "date_time" } ]
                            // plus metrics, filters, and date ranges
                        }
                    }
                ]
            }
        }
    ]
}
```

The collection volumes data source is described in [Monitor collection volume](/setup-and-monitor/operate-and-monitor/monitor-collection-volume.md).

## Comparing an audience to the datamart

To answer "do users in this audience behave differently from all users?", build a dashboard at the `builders` and/or `segments` scope with three things: the metric **for the audience**, the same metric **for all users**, and an **index** to show what is over- or under-represented.

```json5
{
    "title": "Viewing modes",
    "type": "Bars",
    "dataset": {
        "type": "index",
        "sources": [
            {
                "type": "OTQL",
                "query_id": "666",           // SELECT {events {session_mode @map}} FROM UserPoint
                "series_title": "Segment"
            },
            {
                "type": "OTQL",
                "query_id": "666",           // the same query
                "series_title": "Datamart",
                "adapt_to_scope": false      // <- this is what makes it the reference
            }
        ],
        "options": {
            "limit": 10,
            "minimum_percentage": 1,
            "sort": "Descending"
        }
    },
    "options": {
        "type": "bar",
        "plot_line_value": 100,              // the 100 = "same as reference" line
        "format": "index"
    }
}
```

{% hint style="success" %}
The trick is `adapt_to_scope: false` on the second source. Both sources use the **same query**; the first is automatically scoped to the segment or builder the dashboard sits in, and the second is not - which is what makes it the datamart-wide reference.

`plot_line_value: 100` draws the neutral line, so a reader can see at a glance which values are over-represented.
{% endhint %}

## Names instead of IDs

A chart returning channels, compartments, or segments shows IDs, which nobody recognises. The **`get-decorators`** transformation replaces them with names.

```json
{
    "title": "Data by channels",
    "type": "Bars",
    "dataset": {
        "type": "get-decorators",
        "sources": [
            {
                "type": "to-percentages",
                "sources": [
                    {
                        "type": "OTQL",
                        "query_id": "666"   // SELECT { channel_id @map } FROM UserEvent WHERE ...
                    }
                ]
            }
        ],
        "decorators_options": {
            "model_type": "CHANNELS"
        }
    },
    "options": {
        "format": "percentage"
    }
}
```

{% hint style="info" %}
Note how transformations **nest**: the OTQL result goes through `to-percentages`, and that result goes through `get-decorators`. Order matters - decorate last, once the values are final.

Setting `"format": "percentage"` on the chart options is what makes the labels and tooltips read as percentages.
{% endhint %}

## A `@cardinality` query as a single number

`@cardinality` queries return a key/value dataset. Even when that dataset holds a single value, it cannot be displayed as a `Metric` chart as-is. The **`reduce`** transformation puts it in the right format.

```json
{
    "title": "Number of different event names retrieved",
    "type": "Metric",
    "dataset": {
        "type": "reduce",
        "sources": [
            {
                "type": "OTQL",
                "query_id": "666"   // SELECT { nature @cardinality } FROM ActivityEvent
            }
        ]
    }
}
```

## Habits worth keeping

* **Several small dashboards, not one big one** - it avoids executing too many requests at once.
* **Save charts in the Query Tool** where you can, so a change propagates to every dashboard using them. Editing a chart in advanced mode **breaks that link**.
* **Decorate anything that returns an ID.**
* **Format dates** on every histogram, or your axis shows timestamps.
* Give every chart a title that states the question it answers.

## Related pages

<table data-view="cards" data-search="false"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Dashboard</strong></td><td>The object model and the transformation list.</td><td><a href="/setup-and-monitor/operate-and-monitor/create-a-custom-dashboard/dashboard.md">Dashboard</a></td></tr><tr><td><strong>Query Tool</strong></td><td>Where the queries behind these charts are written.</td><td><a href="/setup-and-monitor/operate-and-monitor/query-your-datamart/query-tool.md">Query Tool</a></td></tr><tr><td><strong>Monitor collection volume</strong></td><td>The collection volumes data source.</td><td><a href="/setup-and-monitor/operate-and-monitor/monitor-collection-volume.md">Monitor collection volume</a></td></tr></tbody></table>


---

# 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.mediarithmics.io/setup-and-monitor/operate-and-monitor/create-a-custom-dashboard/dashboard-cookbook.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.
