1. Components
  2. Donut Chart

Components

Donut Chart

A donut chart displays quantitative information through a circle-like visualization.

donut variant

pie variant

   

Import DonutChart

Tremor exports one component to create a donut chart.

import { DonutChart } from "@tremor/react";

Usage example

The example below shows a composition of a Card and Title with the DonutChart component.

Sales

import { Card, Title, DonutChart } from "@tremor/react";

const cities = [
  {
    name: "New York",
    sales: 9800,
  },
  {
    name: "London",
    sales: 4567,
  },
  {
    name: "Hong Kong",
    sales: 3908,
  },
  {
    name: "San Francisco",
    sales: 2400,
  },
  {
    name: "Singapore",
    sales: 1908,
  },
  {
    name: "Zurich",
    sales: 1398,
  },
];

const valueFormatter = (number: number) =>
  `$ ${Intl.NumberFormat("us").format(number).toString()}`;

export default DonutChart = () => (
  <Card className="max-w-lg">
    <Title>Sales</Title>
    <DonutChart
      className="mt-6"
      data={cities}
      category="sales"
      index="name"
      valueFormatter={valueFormatter}
      colors={["slate", "violet", "indigo", "rose", "cyan", "amber"]}
    />
  </Card>
);

API Reference: DonutChart

client component

data
Description
The source data, in which each entry is a dictionary.
Type
any[]
Default
Values
categoryoptional
Description
Sets the name of the key containing the quantitative chart values.
Type
string
Default
value
Values
index
Description
Sets the key to map the data to the axis.
Type
string
Default
Values
colorsoptional
Description
Change the default colors. When using Typescript, import the Color type provided by tremor.
Type
Color[]
Default
Values
E.g. ['blue', 'indigo'].
valueFormatteroptional
Description
Controls the text formatting for the y-axis values. When using Typescript, import the ValueFormatter type provided by tremor.
Type
ValueFormatter
Default
Values
showAnimationoptional
Description
Sets an animation to the chart when it is loaded.
Type
boolean
Default
true
Values
true, false
showTooltipoptional
Description
Controls the visibility of the tooltip.
Type
boolean
Default
true
Values
true, false
variant
Description
Controls the type of the chart.
Type
string
Default
donut
Values
donut, pie
showLabeloptional
Description
Controls the visibility of the text element displayed in the center of the donut chart.
Type
boolean
Default
false
Values
true, false
labeloptional
Description
Sets the text element which is displayed in the center of the donut chart. If fill is set to true, the label is not displayed.
Type
string
Default
Values
noDataTextoptional
Description
The displayed text when the data is empty.
Type
string
Default
No Data
Values