{
"name": "donut-chart",
"snippet": null,
"examples": [
{
"name": "donut-chart-basic",
"content": "\"use client\"\nexport const DonutChartBasic = () => {\n const chart = useChart({\n data: [\n { name: \"windows\", value: 400, color: \"blue.solid\" },\n { name: \"mac\", value: 300, color: \"orange.solid\" },\n { name: \"linux\", value: 300, color: \"pink.solid\" },\n { name: \"other\", value: 200, color: \"green.solid\" },\n ],\n })\n\n return (\n \n \n }\n />\n \n {chart.data.map((item) => {\n return | \n })}\n \n \n \n )\n}\n",
"hasSnippet": false,
"importPaths": [
"import { Chart, useChart } from \"@chakra-ui/charts\"",
"import { Cell, Pie, PieChart, Tooltip } from \"recharts\""
],
"importPath": "import { DonutChart } from \"@chakra-ui/react\"",
"npmDependencies": [
"@chakra-ui/charts",
"recharts"
]
},
{
"name": "donut-chart-with-angle-padding",
"content": "\"use client\"\nexport const DonutChartWithAnglePadding = () => {\n const chart = useChart({\n data: [\n { name: \"windows\", value: 400, color: \"blue.solid\" },\n { name: \"mac\", value: 300, color: \"orange.solid\" },\n { name: \"linux\", value: 300, color: \"pink.solid\" },\n ],\n })\n\n return (\n \n \n }\n />\n \n {chart.data.map((item) => (\n | \n ))}\n \n \n \n )\n}\n",
"hasSnippet": false,
"importPaths": [
"import { Chart, useChart } from \"@chakra-ui/charts\"",
"import { Cell, Pie, PieChart, Tooltip } from \"recharts\""
],
"importPath": "import { DonutChart } from \"@chakra-ui/react\"",
"npmDependencies": [
"@chakra-ui/charts",
"recharts"
]
},
{
"name": "donut-chart-with-centered-text",
"content": "\"use client\"\nexport const DonutChartWithCenteredText = () => {\n const chart = useChart({\n data: [\n { name: \"windows\", value: 400, color: \"blue.solid\" },\n { name: \"mac\", value: 300, color: \"orange.solid\" },\n { name: \"linux\", value: 300, color: \"pink.solid\" },\n { name: \"other\", value: 200, color: \"green.solid\" },\n ],\n })\n\n return (\n \n \n }\n />\n \n \n \n \n )\n}\n",
"hasSnippet": false,
"importPaths": [
"import { Chart, useChart } from \"@chakra-ui/charts\"",
"import { Cell, Label, Pie, PieChart, Tooltip } from \"recharts\""
],
"importPath": "import { DonutChart } from \"@chakra-ui/react\"",
"npmDependencies": [
"@chakra-ui/charts",
"recharts"
]
},
{
"name": "donut-chart-with-detached-segment",
"content": "\"use client\"\nexport const DonutChartWithDetachedSegment = () => {\n const chart = useChart({\n data: [\n { name: \"windows\", value: 400, color: \"blue.solid\" },\n { name: \"mac\", value: 300, color: \"orange.solid\" },\n { name: \"linux\", value: 300, color: \"pink.solid\" },\n { name: \"other\", value: 200, color: \"green.solid\" },\n ],\n })\n\n return (\n \n \n }\n />\n }\n strokeWidth={5}\n >\n {chart.data.map((item) => (\n | \n ))}\n \n \n \n )\n}\n",
"hasSnippet": false,
"importPaths": [
"import { Chart, useChart } from \"@chakra-ui/charts\"",
"import { Cell, Pie, PieChart, Sector, Tooltip } from \"recharts\""
],
"importPath": "import { DonutChart } from \"@chakra-ui/react\"",
"npmDependencies": [
"@chakra-ui/charts",
"recharts"
]
},
{
"name": "donut-chart-with-other-label",
"content": "\"use client\"\n\ninterface DataItem {\n name: string\n value: number\n color: string\n}\n\nconst rawData: DataItem[] = [\n { name: \"windows\", value: 400, color: \"blue.solid\" },\n { name: \"mac\", value: 300, color: \"orange.solid\" },\n { name: \"linux\", value: 150, color: \"pink.solid\" },\n { name: \"chrome\", value: 80, color: \"purple.solid\" },\n { name: \"firefox\", value: 60, color: \"red.solid\" },\n { name: \"safari\", value: 40, color: \"yellow.solid\" },\n { name: \"edge\", value: 30, color: \"cyan.solid\" },\n { name: \"opera\", value: 20, color: \"teal.solid\" },\n]\n\nconst threshold = 100\n\n// Group items with value < 100 into \"Other\"\nconst data = rawData.reduce((acc, item) => {\n if (item.value >= threshold) {\n acc.push(item)\n } else {\n const otherIndex = acc.findIndex((i) => i.name === \"Other\")\n if (otherIndex === -1) {\n acc.push({ name: \"Other\", value: item.value, color: \"gray.emphasized\" })\n } else {\n acc[otherIndex].value += item.value\n }\n }\n return acc\n}, [])\n\nexport const DonutChartWithOtherLabel = () => {\n const chart = useChart({ data: data })\n\n const label = (entry: DataItem) => {\n const percent = chart.getValuePercent(\"value\", entry.value)\n return `${entry.name} (${percent.toFixed(1)}%)`\n }\n\n return (\n \n \n }\n />\n \n {chart.data.map((item) => (\n | \n ))}\n \n \n \n )\n}\n",
"hasSnippet": false,
"importPaths": [
"import { Chart, useChart } from \"@chakra-ui/charts\"",
"import { Cell, Pie, PieChart, Tooltip } from \"recharts\""
],
"importPath": "import { DonutChart } from \"@chakra-ui/react\"",
"npmDependencies": [
"@chakra-ui/charts",
"recharts"
]
},
{
"name": "donut-chart-with-point-label",
"content": "\"use client\"\nexport const DonutChartWithPointLabel = () => {\n const chart = useChart({\n data: [\n { name: \"windows\", value: 400, color: \"blue.solid\" },\n { name: \"mac\", value: 300, color: \"orange.solid\" },\n { name: \"linux\", value: 300, color: \"pink.solid\" },\n { name: \"other\", value: 200, color: \"green.solid\" },\n ],\n })\n\n return (\n \n \n }\n />\n \n {chart.data.map((item) => (\n | \n ))}\n \n \n \n )\n}\n",
"hasSnippet": false,
"importPaths": [
"import { Chart, useChart } from \"@chakra-ui/charts\"",
"import { Cell, Pie, PieChart, Tooltip } from \"recharts\""
],
"importPath": "import { DonutChart } from \"@chakra-ui/react\"",
"npmDependencies": [
"@chakra-ui/charts",
"recharts"
]
},
{
"name": "donut-chart-with-start-and-end-angle",
"content": "\"use client\"\nexport const DonutChartWithStartAndEndAngle = () => {\n const chart = useChart({\n data: [\n { name: \"windows\", value: 400, color: \"blue.solid\" },\n { name: \"mac\", value: 300, color: \"orange.solid\" },\n { name: \"linux\", value: 300, color: \"pink.solid\" },\n { name: \"other\", value: 200, color: \"green.solid\" },\n ],\n })\n\n return (\n \n \n }\n />\n \n {chart.data.map((item) => (\n | \n ))}\n \n \n \n )\n}\n",
"hasSnippet": false,
"importPaths": [
"import { Chart, useChart } from \"@chakra-ui/charts\"",
"import { Cell, Pie, PieChart, Tooltip } from \"recharts\""
],
"importPath": "import { DonutChart } from \"@chakra-ui/react\"",
"npmDependencies": [
"@chakra-ui/charts",
"recharts"
]
}
]
}