> For the complete documentation index, see [llms.txt](https://datalab-docs.datacamp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://datalab-docs.datacamp.com/work/chart-cell/pivot-charts.md).

# Pivot charts

<figure><img src="https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2F8dSvnV07uF8EM7wVkdpC%2FScreenshot%202025-03-26%20at%2016.26.34.png?alt=media&amp;token=5f6f3feb-4c8e-4b8c-9608-b94845f320e6" alt=""><figcaption><p>Pivot chart comparing multiple aggregated series</p></figcaption></figure>

In the default charting mode, you can easily create a simple chart with selected columns on both axes.  However, creating a chart that compares multiple series (like the screenshot above) requires enabling the **pivot mode** by using the toggle at the top of the chart.

<figure><img src="https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FE5lVJbkTK12FMZdbXQet%2FScreenshot%202025-03-26%20at%2016.00.30.png?alt=media&amp;token=b265a474-40d7-4345-a036-6fc5801b8aa6" alt=""><figcaption><p>Toggle pivot mode</p></figcaption></figure>

Once enabled, you will see that the *Set Up* tab has changed. Instead of choosing a category and series, you can now additionally choose *Color by* and *Group by* fields.

For this guide, we will try to recreate the chart in the top screenshot and assume a dataset about car sales with the following structure:

| brand  | year | nb\_sales |
| ------ | ---- | --------- |
| Ford   | 2025 | 5791      |
| Ford   | 2024 | 3381      |
| Toyota | 2025 | 4002      |
| Toyota | 2024 | 5821      |
| ...    | ...  | ...       |

**Note**: the number of sales are imaginary numbers.

#### 1. Color by

The "*Color by*" field decides which column your data will be pivoted on. In other words, the data will be split into the values of the column you choose here, and each value will be represented with a unique color. In our example, let's pick the **brands** column because we want to see the number of sales per brand.

**Note**: this is the equivalent of the "*Color"* field in the legacy chart configuration.

<figure><img src="https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FPgfNoT8NLNn5wPZeZcNJ%2FScreenshot%202025-03-26%20at%2016.28.14.png?alt=media&amp;token=7bebd3ad-f22d-4f65-a962-1ddd341fda0f" alt=""><figcaption></figcaption></figure>

#### 2. Series

Similarly to the normal charting mode, series are the numerical values you want to chart. When adding a series, you'll first have to select the column. Additionally, since the data is being pivoted, you must also choose an aggregate. By default this will be set to average.

<figure><img src="https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FlVr9B4g6vaLvaZOKCHHA%2FScreenshot%202025-03-26%20at%2016.31.36.png?alt=media&amp;token=7ec461de-25b4-473e-a1f2-c99897ff4a54" alt=""><figcaption></figcaption></figure>

#### 3. Group by

Finally, you can optionally choose to group your data by a specific column. It's a way to split your data into different segments on top of the "*Color by*" field. In this example we can choose to group the data by year so that we can see the trends.

<figure><img src="https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FRMfX73VLeZnC73n8c3A9%2FScreenshot%202025-03-26%20at%2016.42.18.png?alt=media&amp;token=8d048ac0-4936-4e59-af77-aa8ff1a28e7c" alt=""><figcaption></figcaption></figure>

Finally, in the *Chart* tab, don't forget to change the chart type from a bar chart to a line chart.


---

# 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://datalab-docs.datacamp.com/work/chart-cell/pivot-charts.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.
