Usage
Compose <Legend /> inside the chart root. Its entries read their labels, icons, and colors from ChartConfig. Select an entry to focus its series and select it again to clear the focus.
import { ChartcnLineChart } from "@/components/chart/line-chart";
<ChartcnLineChart data={data} config={chartConfig} xDataKey="month">
<ChartcnLineChart.Legend variant="circle" align="right" />
<ChartcnLineChart.Line dataKey="desktop" />
<ChartcnLineChart.Line dataKey="mobile" />
</ChartcnLineChart>;Variants
Control the legend indicator with the variant prop.
Square
variant='square'
JanFebMarAprMayJunJulAugSepOctNovDec
Circle
variant='circle'
JanFebMarAprMayJunJulAugSepOctNovDec
Circle Outline
variant='circle-outline'
JanFebMarAprMayJunJulAugSepOctNovDec
Rounded Square (Default)
variant='rounded-square'
JanFebMarAprMayJunJulAugSepOctNovDec
Rounded Square Outline
variant='rounded-square-outline'
JanFebMarAprMayJunJulAugSepOctNovDec
Vertical Bar
variant='vertical-bar'
JanFebMarAprMayJunJulAugSepOctNovDec
Horizontal Bar
variant='horizontal-bar'
JanFebMarAprMayJunJulAugSepOctNovDec
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "square" | "circle" | "circle-outline" | "rounded-square" | "rounded-square-outline" | "vertical-bar" | "horizontal-bar" | "rounded-square" | Style of the legend indicator. |
align | "left" | "center" | "right" | "right" | Horizontal alignment of the legend entries. |
position | "top" | "right" | "bottom" | "left" | "top" | Placement around the chart plot. |
hideIcon | boolean | false | Hides the indicator while retaining labels. |