shadcn.io is not affiliated with official shadcn/ui
About
Icons help when the series are things people recognize at a glance (devices, channels, teams) or when the legend has to work without telling colors apart. If a color key is enough, the Area Chart with Legend is lighter.
The bands are the stacked area's, mobile under desktop. The legend under the plot shows a trending-up icon for mobile and a trending-down one for desktop, and the tooltip uses the same icons in place of its color marks.
Installation
Usage
import { ChartAreaIcons } from "@/components/charts/chart-area-icons";<ChartAreaIcons />Customize
chartConfiggivesdesktoptheTrendingDownicon andmobiletheTrendingUpicon, fromlucide-react.<ChartLegend content={<ChartLegendContent />} />draws each icon in place of the color square.ChartTooltipContentreads the same icons, so they replace the line indicator in the tooltip.hideIcononChartLegendContentkeeps the squares even when the config has icons.
FAQ
How do I give a series an icon?
Import the icon from your framework's lucide package and set it as icon on the series' chartConfig entry, next to its label and color. The legend and the tooltip pick it up; nothing else changes.
Why does the tooltip show the icons too?
Both read icon from the same chartConfig, and ChartTooltipContent has no prop to skip it. Remove icon to go back to color marks, or pass ChartLegend a content of your own that draws the icons.
Can the icons take the series color?
The legend draws them in muted-foreground at size-3, so the label carries the meaning. To color one, set icon to a small component of your own that renders the lucide icon with its color set to var(--color-mobile).
API Reference
ChartContainer
configChartConfig
Each series by its data key: its label, an icon, and a color (or a * theme color per light and dark), read by the tooltip and legend and set * as --color-<key>.
initialDimension?{ height: number; width: number; }
The size it renders at before it's measured, so the first paint isn't * empty.
- Type
{ height: number; width: number; }- Default
INITIAL_DIMENSION
className?string
Merged with the part's classes.
ChartLegend
ChartLegendContent
<div>
hideIcon?boolean
Hides each series' icon (from config), leaving its color swatch.
- Default
false
nameKey?string
The key in each legend item's data to look its label up by in config. * Defaults to the item's dataKey.
className?string
Merged with the part's classes.
ChartStyle
<style>
configChartConfig
The chart config whose colors it writes as --color-<key> variables.
idstring
The element's id.
ChartTooltip
ChartTooltipContent
<div>
hideIndicator?boolean
Hides each item's color indicator.
- Default
false
hideLabel?boolean
Hides the tooltip's label, the hovered point's.
- Default
false
indicator?"dashed" | "dot" | "line"
The color indicator's shape: a dot, a line or dashed.
- Type
"dashed" | "dot" | "line"- Default
"dot"
labelFormatter?(label: any, payload: TooltipPayload) → React.ReactNode
Formats the tooltip's label; its value is untyped, as in recharts 3.8.
- Type
(label: any, payload: TooltipPayload) → React.ReactNode- Parameters
label– anypayload– TooltipPayload- Returns
React.ReactNode
labelKey?string
The key in the data to read the label from, looked up in config.
nameKey?string
The key in each item's data to look its name up by in config.
className?string
Merged with the part's classes.
Related
Area Chart with Legend
Area chartsStacked areas with a legend naming each series.
Radar Chart with Icons
Radar chartsTwo radar series with icons in their legend.
Chart Tooltip with Icons
TooltipsA tooltip with an icon beside each series.
Stacked Area Chart
Area chartsTwo series stacked into one total, each band its own color.
Pie Chart with Legend
Pie chartsA pie with a legend of its slices underneath.
Area Chart
Area chartsOne series as a smooth filled curve over six months.