shadcn.io is not affiliated with official shadcn/ui
Chart examples · Radar
A radar chart with a legend for React
A radar chart comparing two series with a legend below it.
Use it to compare two series on one radar and say which is which. Desktop and mobile are drawn on the same grid, and ChartLegend lists them with their colors under the chart.
Preview
Installation
FAQ
How is the legend placed under the chart?
RadarChart renders ChartLegend with content set to ChartLegendContent and className mt-8. That margin pushes the legend down. verticalAlign is unset, so the legend stays at the bottom.
What do the legend items say?
ChartLegendContent looks up each series dataKey in config. desktop is labeled Desktop with color var(--chart-1), and mobile is labeled Mobile with color var(--chart-2).
How are the two shapes drawn?
One Radar uses dataKey desktop, fill var(--color-desktop), and fillOpacity 0.6. The other uses dataKey mobile and fill var(--color-mobile). Both sit on a PolarGrid, with PolarAngleAxis dataKey set to month.
Why is the chart margin negative?
RadarChart sets margin to { top: -40, bottom: -10 }. That pulls the plot toward the legend so the square frame can hold both. ChartContainer is mx-auto aspect-square max-h-[250px].
Related
- A radar chart with iconsA radar chart whose legend shows an icon
- A radar chart with multiple dataA radar chart overlaying desktop and
- An area chart with a legendA stacked area chart of desktop and
- A multiple line chartA line chart comparing desktop and mobile
- A radar chartA radar chart plotting one series across
- A multiple bar chartA bar chart grouping desktop and mobile