MDK Logo
UI Kitreact-devkitComponentsCoreCharts

DoughnutChart

DoughnutChart – Presentational Chart.js doughnut chart with custom HTML legend matching the MDK design.

DoughnutChart – Presentational Chart.js doughnut chart with custom HTML legend matching the MDK design.

import { DoughnutChart } from "@tetherto/mdk-react-devkit";
PropStatusTypeDefaultDescription
dataRequiredDoughnutChartDataset[]Array of labelled slices
unitOptionalstring | undefinedUnit suffix shown in tooltips
optionsOptional_DeepPartialObject<CoreChartOptions<"doughnut"> & ElementChartOptions<"doughnut"> & PluginChartOptions<"doughnut"> & DatasetChartOptions<"doughnut"> & ScaleChartOptions<"doughnut"> & DoughnutControllerChartOptions> | undefinedChart.js options – merged with defaults
cutoutOptionalstring | undefinedDoughnut cutout percentage (default: '75%')
borderWidthOptionalnumber | undefinedBorder width between segments (default: 4)
heightOptionalnumber | undefinedChart height in pixels
legendPositionOptionalPosition | undefinedWhere to place the legend relative to the chart (default: 'top')
tooltipOptionalChartTooltipConfig | undefinedCustom HTML tooltip configuration. When provided, replaces the default doughnut tooltip (which shows label, value with unit, and percentage). Use `valueFormatter` to replicate the percentage display if needed.
formatValueOptional((value: number) => string) | undefinedFormats slice values in the built-in legend and default tooltip (default: raw number).
classNameOptionalstring | undefined

Usage

A Chart.js doughnut chart with a custom HTML legend, slice toggle, and percentage display.

Notes

  • Clicking a legend item toggles the corresponding slice on the chart and dims the legend button.
  • When the data reference changes (labels change), all hidden states reset automatically.

Example

/** * Runnable example for DoughnutChart. */import { DoughnutChart } from '@tetherto/mdk-react-devkit'const deviceStatusData = [  { label: 'Online', value: 142, color: '#34C759' },  { label: 'Offline', value: 23, color: '#FF3B30' },  { label: 'Maintenance', value: 8, color: '#FF9500' },]const hashDistributionData = [  { label: 'Foundry EU', value: 450 },  { label: 'AntPool', value: 320 },  { label: 'F2Pool', value: 180 },  { label: 'Other', value: 50 },]export const DoughnutChartExample = () => (  <div className="mdk-example-row">    <DoughnutChart data={deviceStatusData} unit="devices" legendPosition="right" />    <DoughnutChart data={hashDistributionData} unit="TH/s" height={200} legendPosition="bottom" />  </div>)