recharts-legend
evilcharts/recharts-legendFreeComponent
EvilCharts publishes no description for this item.
Install it
npx shadcn@latest add https://evilcharts.com/r/recharts-legend.jsonSource
1import { getPayloadConfigFromPayload, getColorsCount, useChart } from "@/registry/ui/recharts-chart";2import * as RechartsPrimitive from "recharts";3import { cn } from "@/lib/utils";4import * as React from "react";56type ChartLegendVariant =7 | "square"8 | "circle"9 | "circle-outline"10 | "rounded-square"11 | "rounded-square-outline"12 | "vertical-bar"13 | "horizontal-bar";1415function ChartLegendContent({16 className,17 hideIcon = false,18 nameKey,19 payload,20 verticalAlign,21 align = "right",22 selected,23 onSelectChange,24 isClickable,25 variant = "rounded-square",26}: React.ComponentProps<"div"> & {27 hideIcon?: boolean;28 nameKey?: string;29 selected?: string | null;30 isClickable?: boolean;31 onSelectChange?: (selected: string | null) => void;32 variant?: ChartLegendVariant;33} & RechartsPrimitive.DefaultLegendContentProps) {34 const { config } = useChart();3536 if (!payload?.length) {37 return null;38 }3940 return (41 <div42 className={cn(43 "flex items-center gap-4 select-none",44 align === "left" && "justify-start",45 align === "center" && "justify-center",46 align === "right" && "justify-end",47 verticalAlign === "top" ? "pb-4" : "pt-4",48 className,49 )}50 >51 {payload52 .filter((item) => item.type !== "none")53 .map((item) => {54 // For pie charts, item.value contains the sector name (e.g., "chrome")55 // For radial charts, the name is in item.payload[nameKey]56 // For other charts, item.dataKey contains the series name (e.g., "desktop")57 const payloadName =58 nameKey && item.payload59 ? (item.payload as Record<string, unknown>)[nameKey]60 : undefined;61 const key = `${payloadName ?? item.value ?? item.dataKey ?? "value"}`;62 const itemConfig = getPayloadConfigFromPayload(config, item, key);63 const isSelected = selected === null || selected === key;6465 // Get colors count for this item to determine gradient vs solid66 const colorsCount = itemConfig ? getColorsCount(itemConfig) : 1;6768 return (69 <div70 key={key}71 className={cn(72 "[&>svg]:text-muted-foreground flex items-center gap-1.5 transition-opacity [&>svg]:h-3 [&>svg]:w-3",73 !isSelected && "opacity-30",74 isClickable && "cursor-pointer",75 )}76 onClick={() => {77 if (!isClickable) return;7879// … truncated
What it pulls in
npm packages
Files it writes
More from EvilCharts
All 271 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| echarts-area-chartecharts-area-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-bar-chartecharts-bar-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-brushecharts-brush | EvilCharts | Components | Free | 1 dep | |
| echarts-chartecharts-chart | EvilCharts | Components | Free | 1 dep | |
| echarts-composed-chartecharts-composed-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-dotecharts-dot | EvilCharts | Components | Free | 1 dep | |
| echarts-legendecharts-legend | EvilCharts | Components | Free | no deps | |
| echarts-line-chartecharts-line-chart | EvilCharts | Components | Free | 2 deps |
