﻿---
title: Build pie charts with Kibana
description: Instructions and best practices for building pie and donut charts with Kibana Lens in Elastic.
url: https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/visualize/charts/pie-charts
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# Build pie charts with Kibana
Pie charts display parts of a whole as slices, where each slice represents a value and its size represents its prevalence. Pie charts are ideal for illustrating the relative prevalence of categorical data, and for displaying percentage or proportional data. They work best with a **maximum of 6 slices** and when proportions are around 25%, 50%, or 75%, as these are easiest to perceive accurately. For more than 6 categories, precise comparisons, or negative values, consider using [bar charts](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/visualize/charts/bar-charts) instead. For comparing similarly-sized proportions or displaying percentages as discrete units, consider using [waffle charts](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/visualize/charts/waffle-charts).
You can create pie charts in Kibana using [**Lens**](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/visualize/lens).
![Example Lens pie chart](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/kibana-lens-pie-chart.png)

## Build a pie chart

Before you start, make sure you have data [indexed into Elasticsearch](https://www.elastic.co/elastic/docs-builder/docs/3016/manage-data/ingest) or [install sample data](https://www.elastic.co/elastic/docs-builder/docs/3016/manage-data/ingest/sample-data). By default, Lens uses [data views](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/find-and-organize/data-views) to access your Elasticsearch data. Data views are created automatically in most cases when you ingest data. You can also [create one manually](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/find-and-organize/data-views) to select just the data that you want. Alternatively, you can use the [ES|QL query mode](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/visualize/esorql) to query your Elasticsearch data directly.
To build a pie chart:
<stepper>
  <step title="Access Lens">
    **Lens** is Kibana's main visualization editor. You can access it:
    - From a dashboard: On the **Dashboards** page, open or create the dashboard where you want to add a pie chart, then add a new visualization.
    - From the **Visualize library** page by creating a new visualization.
  </step>

  <step title="Set the visualization to Pie">
    New visualizations often start as **Bar** charts.Using the **Visualization type** dropdown, select **Pie**.
  </step>

  <step title="Define the data to show">
    1. Select the data view that contains your data.
    2. Configure the [**Slice by**](#slice-by-settings) dimension to define how the pie is divided into slices. Drag a categorical field to create slices based on its values.
    3. Configure the [**Metric**](#metric-settings) dimension to define the size of each slice. This determines the numerical value that each slice represents. Kibana automatically selects an appropriate aggregation function compatible with the selected field.
    Optionally:
    - Add additional **Slice by** dimensions to create nested slices (a multi-level or sunburst-style chart).
    - Enable [**Multiple metrics**](#multiple-metrics) in the layer settings to compare different measures within the same chart.
    The chart preview updates to show a pie divided into slices. Each slice represents a category value, and its size reflects the metric proportion. If you added multiple **Slice by** dimensions, inner and outer rings appear to show the hierarchy.
  </step>

  <step title="Customize the chart to follow best practices">
    Tweak the appearance of the chart to your needs. Consider the following best practices:
    <definitions>
      <definition term="Limit the number of slices">
        Keep your pie chart to a maximum of 6 slices. If you have more categories, consider [grouping smaller values into an "Other" category](#other-category) or using a different visualization type.
      </definition>
      <definition term="Order slices meaningfully">
        The largest slice should start at the 12 o'clock position and proceed clockwise in descending order. For categories with a natural order (such as satisfaction ratings), follow that order instead.
      </definition>
      <definition term="Use color purposefully">
        Apply colors to highlight important data or patterns. Use the [color mapping feature](/elastic/docs-builder/docs/3016/explore-analyze/visualize/lens#assign-colors-to-terms) to assign consistent colors to key categories across your dashboards.
      </definition>
      <definition term="Consider using a donut">
        The empty center of donut charts provides space to display additional information, such as a total or key metric. Refer to [Create a donut chart](#donut-chart) for instructions.
      </definition>
      <definition term="Label clearly">
        Keep labels inside or close to slices when possible. For charts with many small slices or long labels, use the legend instead.
      </definition>
    </definitions>
    Refer to [Pie chart settings](#pie-chart-settings) to find all configuration options for your pie chart.
  </step>

  <step title="Save the chart">
    - If you accessed Lens from a dashboard, select **Save and return** to save the visualization and add it to that dashboard, or select **Save to library** to add the visualization to the Visualize library and reuse it later.
    - If you accessed Lens from the Visualize library, select **Save**. A menu opens and lets you add the visualization to a dashboard and to the Visualize library.
  </step>
</stepper>


## Advanced pie chart scenarios


### Create a donut chart

Donut charts are pie charts with a hollow center. The empty space can provide a visual focal point and space for displaying related information.
1. Create a **Pie** chart visualization.
2. Configure your **Slice by** and **Metric** dimensions.
3. Select `brush` **Style**.
4. In **Appearance**, set **Donut hole** to **Small**, **Medium**, or **Large** depending on how much center space you want.

![Setting the donut hole size in Pie chart Style settings](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/pie-chart-donut.png "50%")

### Compare multiple metrics in a pie chart

By default, pie charts use a single metric with **Slice by** to split that metric by values in a categorical field. The **Multiple metrics** option lets you take a different approach: each slice represents a distinct metric you define, rather than values from your data.
This is useful when:
- You want to compare metrics that apply different filters to the same aggregation
- You need to show custom-defined categories that don't exist as values in a field
- You want to compare different calculations or formulas side by side


#### Example: Server resource consumption

Imagine your web logs data includes multiple numeric fields representing different resource types, such as `response_bytes`, `processing_time_ms`, and `memory_used_kb`. You want to visualize how each resource contributes to overall server load.
1. Create a **Pie** chart and remove any existing **Slice by** dimension.
2. Open **Layer settings**:
   - <applies-to>Elastic Cloud Serverless: Generally available</applies-to> <applies-to>Elastic Stack: Generally available since 9.3</applies-to> Select `app_management` **Layer settings**.
- <applies-to>Elastic Stack: Generally available from 9.0 to 9.2</applies-to> Select `boxes_vertical`, then select **Layer settings**.
3. Select **Multiple metrics**, then close the **Layer settings** menu.
4. Add metrics for each resource type:
   | Slice           | Metric configuration      |
   |-----------------|---------------------------|
   | Bandwidth       | `Sum(response_bytes)`     |
   | Processing time | `Sum(processing_time_ms)` |
   | Memory usage    | `Sum(memory_used_kb)`     |
   For each metric, select the **Metric** dimension and configure the field. Customize the **Name** to display meaningful labels in the legend.
5. Optionally, assign custom colors to each metric by selecting the metric and choosing a **Series color**.

![Pie chart with three slices showing different server resource metrics](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/pie-chart-multiple-metrics-example.png)
This example demonstrates the core value of multiple metrics: comparing different numeric fields that represent distinct concepts. Unlike **Slice by**, which splits a single metric by category values, multiple metrics lets you place fundamentally different measurements side by side.
<note>
  The Kibana sample data sets don't include multiple comparable numeric fields. To try this scenario, adapt the field names to match your own data.
</note>


### Group smaller values into a single slice

When you have many categories with small values, you can group them into an "Other" category to simplify the visualization.
1. In the **Slice by** configuration, select the field.
2. Use **Top values** to limit the number of slices displayed.
3. Expand **Advanced**.
4. Enable **Group other values as "Other"** to combine remaining values into a single slice.

<tip>
  Be careful when using "Other", as it could end up being the largest category, which might obscure the meaning of your chart. Consider whether a bar chart might be more appropriate for data with many categories.
</tip>


#### Example: Top hosts with remaining grouped as "Other"

This example uses the **Kibana Sample Data Logs** data set. If you haven't installed it yet, refer to [Sample data](https://www.elastic.co/elastic/docs-builder/docs/3016/manage-data/ingest/sample-data) for instructions.
1. Create a **Pie** chart using the **Kibana Sample Data Logs** data view.
2. In the **Slice by** dimension, select `host.keyword` with **Top values** set to **3**.
3. Expand **Advanced** and make sure that the **Group other values as "Other"** option is active.
4. Set the **Metric** to the **Count** function.

The resulting chart shows the 3 most common hosts, with all remaining hosts combined into a single "Other" slice. This keeps the chart readable while still accounting for the full data set.
![Pie chart showing top 3 hosts with remaining hosts grouped as Other](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/pie-chart-group-as-other.png)

## Pie chart settings

Customize your pie chart to display exactly the information you need, formatted the way you want.

### Slice by settings

The **Slice by** dimension defines how your pie is divided into segments. You can add up to 3 levels of slicing to create hierarchical visualizations.
<definitions>
  <definition term="Data">
    The **Slice by** dimension supports the following functions:
    - **Top values**: Create slices for the most common values in a field.
      - **Field**: Select the field to group by. You can add up to 4 fields to create multi-term slices. When multiple fields are selected, each slice represents a unique combination of values across those fields. You can reorder the fields by dragging them to change their priority.
    - **Number of values**: How many top values to display.
      - **Rank by**: Specifies the dimension the top values are ranked by. Available options:
      - **Count of records**: Rank by the number of documents containing each value. This is the default when a metric is defined.
      - **Alphabetical**: Rank by the term key alphabetically. This is the default when no metric is defined.
      - **Rarity**: Find terms that appear in very few documents, using a [rare terms aggregation](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3016/reference/aggregations/search-aggregations-bucket-rare-terms-aggregation). You can configure the **Max doc count** to set the maximum number of documents a term can appear in to be considered rare (default: 1, max: 100). Only available for non-numeric fields and single-field terms.
      - **Significance**: Find statistically unusual terms compared to the overall data set, using a [significant terms aggregation](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3016/reference/aggregations/search-aggregations-bucket-significantterms-aggregation). Only available for `keyword` fields and single-field terms.
      - **Custom**: Define a custom metric aggregation to rank by (for example, rank by the sum of a numeric field rather than by count).
      - **Rank direction**: Ascending or descending order. Disabled when **Rank by** is set to **Rarity** or **Significance**.
      - **Collapse by**: Aggregate values into a single number using `Sum`, `Average`, `Min`, or `Max`.
      <dropdown title="Advanced settings">
      Several advanced options allow you to refine the behavior of the breakdown:
      - **Include documents without the selected field**: Off by default.
      - **Group remaining values as "Other"**: On by default.
      - **Enable accuracy mode**: This option improves results for high-cardinality data, but increases the load on the Elasticsearch cluster.
      - **Include values**: Values from the breakdown dimension to always show a tile for.
      - **Exclude values**: Values from the breakdown dimension to always exclude from the displayed tiles.
      </dropdown>
    - **Date histogram**: Group data into time-based buckets (useful for showing time-based composition). Configure the time interval and how to handle date formatting.
      - **Field**: Select the date field to use for the time-based grouping.
      - **Include empty rows**: This option is on by default. Turn it off to exclude empty rows from the data.
      - **Bind to global time picker**: Associate the selected field to the Lens or dashboard main time selector.
      - **Minimum interval**: Define the time interval for aggregating the data. For example, `30s`, `20m`, `24h`, `2d`, `1w`, `1M`
      - **Drop partial intervals**: Exclude incomplete intervals from the data. This option is off by default.
      - **Collapse by**: Aggregate values into a single number using `Sum`, `Average`, `Min`, or `Max`.
    - **Intervals**: Create numeric ranges for continuous data. Useful for grouping numeric fields into buckets. You can define the interval granularity or specify custom ranges.
      - **Field**: Select the numeric field to create intervals from.
    - **Include empty rows**: Include intervals with no matching documents. On by default.
    - **Collapse by**: Aggregate values into a single number using `Sum`, `Average`, `Min`, or `Max`.
      <dropdown title="How does interval granularity work?">
      Interval granularity divides the field into evenly spaced intervals based on the minimum and maximum values for the field.The size of the interval is a "nice" value. When the granularity of the slider changes, the interval stays the same when the "nice" interval is the same. The minimum granularity is 1, and the maximum value is histogram:maxBars. To change the maximum granularity, go to Advanced settings.Intervals are incremented by 10, 5 or 2. For example, an interval can be `100` or `0.2`.
      </dropdown>
    - **Filters**: Define custom KQL filters to create specific slices. Each filter creates one slice in the chart.
      - **Collapse by**: Aggregate values into a single number using `Sum`, `Average`, `Min`, or `Max`.
  </definition>
  <definition term="Appearance">
    Configure slice-level options:
    - **Name**: Customize the legend label.
    - **Color mapping**: Select a color palette or assign specific colors to categories. Refer to [Assign colors to terms](/elastic/docs-builder/docs/3016/explore-analyze/visualize/lens#assign-colors-to-terms) for details.
  </definition>
</definitions>


### Metric settings

The **Metric** dimension defines the size of each slice.
<definitions>
  <definition term="Data">
    The main value that appears prominently in your chart. When you drag a field onto the chart, Kibana suggests a function based on the field type. You can change it and use aggregation functions like `Sum`, `Average`, `Count`, `Median`, and more, or create custom calculations with formulas. Refer to [Lens > Use formulas to perform math](/elastic/docs-builder/docs/3016/explore-analyze/visualize/lens#lens-formulas) for examples, or to the `documentation` **Formula reference** available from Lens.
    <dropdown title="Advanced settings">
      Depending on the data you defined, several options allow you to apply additional filtering to the data taken into account to compute the final value to show.Based on the type of visualization you're creating, only some of the following options can be available:
      - **Normalize by unit**: Normalize the metric values to show per unit of time.
      - **Filter by**: Specify a query.
      - **Reduced time range**: Reduce the time range specified on the dashboard's time filter by the specified duration.
      - **Time shift**: Shift the time range by the specified duration. This is useful if the value should use a different time range than the one selected on the dashboard.
      - **Hide zero values**: Don't show values equal to zero. This option is on by default.
    </dropdown>
  </definition>
  <definition term="Appearance">
    - **Name**: Customize the metric label displayed in tooltips and legends.
    - **Value format**: Control how numeric values are displayed (number, percent, bytes, and more).
    - **Series color**: When using multiple metrics without a **Slice by** dimension, use this option to assign a specific color to each metric.
  </definition>
</definitions>


### General layout

When creating or editing a visualization, you can customize several appearance options from the `brush` **Style** or ![Legend icon](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/kibana-legend-icon.svg) **Legend** menus.

#### Style settings

<definitions>
  <definition term="Appearance">
    Control the main visual aspects of the pie chart.
    <definitions>
      <definition term="Donut hole">
        Transform your pie chart into a donut by adding a center hole:
        - **None**: Standard pie chart with no hole (default).
        - **Small**: Small center hole.
        - **Medium**: Medium center hole.
        - **Large**: Large center hole for emphasis or to display additional information.
      </definition>
    </definitions>
  </definition>
  <definition term="Titles and text">
    Control slice labels and values.
    <definitions>
      <definition term="Slice labels">
        Control how labels appear on the slices:
        - **Hide**: Do not display labels on slices.
        - **Inside**: Display labels inside the slices.
        - **Auto**: Automatically position labels for optimal readability (default).
      </definition>
      <definition term="Slice values">
        Control what values appear on the slices (when labels are visible):
        - **Hide**: Do not display values.
        - **Integer**: Display the raw numeric value.
        - **Percentage**: Display the percentage of the total.
      </definition>
    </definitions>
    When displaying percentages, you can also configure the **Decimal places** (0-10) for precision.
  </definition>
</definitions>


#### Legend settings

Configure elements of your pie chart's legend:
<definitions>
  <definition term="Visibility">
    Specify whether to automatically show the legend or hide it:
    - **Auto**: Show the legend when there are multiple slices (default).
    - **Show**: Always show the legend.
    - **Hide**: Never show the legend.
  </definition>
  <definition term="Nested">
    When using multiple **Slice by** dimensions, enable this option to show the legend in a hierarchical format that reflects the slice hierarchy.
  </definition>
  <definition term="Label truncation">
    Choose whether to truncate long legend labels, and set a limit for how many lines to display.
  </definition>
  <definition term="Width">
    Set the width of the legend.
  </definition>
</definitions>


## Pie chart examples

The following examples show various configuration options for building impactful pie charts.
<definitions>
  <definition term="Website traffic by source">
    Visualize the distribution of traffic sources to your website:
    - Example based on: Kibana Sample Data Logs
    - Configuration: [**Multiple metrics**](#multiple-metrics)
    - **Metrics**: 4 metrics based on formulas
      - `count(kql='referer : *elastic*')`, named "Elastic website"
    - `count(kql='referer : *twitter*')`, named "Twitter/X"
    - `count(kql='referer : *facebook*')`, named "Facebook"
    - `count(kql='referer : *nytimes*')`, named "NY Times"
    - **Style**: Donut with medium hole
    - **Legend**: Show
  </definition>
</definitions>

![Donut chart with traffic by sources](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/pie-chart-example-traffic-by-source.png)
<definitions>
  <definition term="Revenue distribution by product category">
    Show how revenue is distributed across product categories:
    - Example based on: Kibana Sample Data eCommerce
    - **Slice by**: `category.keyword` (Top values, 6)
    - **Metric**: Sum of `taxful_total_price`
    - **Style**: Pie (no donut hole)
  </definition>
</definitions>

![Pie chart with revenue by product category](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/pie-chart-example-revenue-by-product-category.png)
<definitions>
  <definition term="Error distribution by type">
    Display the proportion of different error types in your application:
    - Example based on: Kibana Sample Data Logs
    - **Slice by**: `error.type` using **Filters**:
      - "Client Error": `response.keyword >= "400" AND response.keyword < "500"`
    - "Server Error": `response.keyword >= "500"`
    - "Success": `response.keyword >= "200" AND response.keyword < "400"`
    - **Metric**: `Count of records`
    - **Style**: Donut with large hole
    - **Color mapping**: Red for client errors, yellow for server errors, green for success
  </definition>
</definitions>

![Donut chart with distribution of errors by type](https://www.elastic.co/elastic/docs-builder/docs/3016/explore-analyze/images/pie-chart-example-response-distribution.png)