Home / Function/ ChartLegendContent() — ui Function Reference

ChartLegendContent() — ui Function Reference

Architecture documentation for the ChartLegendContent() function in chart.tsx from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  d627143c_2403_93cc_b475_f3c964a334f2["ChartLegendContent()"]
  bca50faa_8d6b_703f_dfd2_c4cbfa71c486["chart.tsx"]
  d627143c_2403_93cc_b475_f3c964a334f2 -->|defined in| bca50faa_8d6b_703f_dfd2_c4cbfa71c486
  0c80dc08_73ee_e661_7de0_f8ea1e4e6156["useChart()"]
  d627143c_2403_93cc_b475_f3c964a334f2 -->|calls| 0c80dc08_73ee_e661_7de0_f8ea1e4e6156
  422aa192_5d49_751c_ba2c_7d8886325ec4["getPayloadConfigFromPayload()"]
  d627143c_2403_93cc_b475_f3c964a334f2 -->|calls| 422aa192_5d49_751c_ba2c_7d8886325ec4
  style d627143c_2403_93cc_b475_f3c964a334f2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/registry/bases/radix/ui/chart.tsx lines 252–306

function ChartLegendContent({
  className,
  hideIcon = false,
  payload,
  verticalAlign = "bottom",
  nameKey,
}: React.ComponentProps<"div"> &
  Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
    hideIcon?: boolean
    nameKey?: string
  }) {
  const { config } = useChart()

  if (!payload?.length) {
    return null
  }

  return (
    <div
      className={cn(
        "flex items-center justify-center gap-4",
        verticalAlign === "top" ? "pb-3" : "pt-3",
        className
      )}
    >
      {payload
        .filter((item) => item.type !== "none")
        .map((item) => {
          const key = `${nameKey || item.dataKey || "value"}`
          const itemConfig = getPayloadConfigFromPayload(config, item, key)

          return (
            <div
              key={item.value}
              className={cn(
                "[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
              )}
            >
              {itemConfig?.icon && !hideIcon ? (
                <itemConfig.icon />
              ) : (
                <div
                  className="h-2 w-2 shrink-0 rounded-[2px]"
                  style={{
                    backgroundColor: item.color,
                  }}
                />
              )}
              {itemConfig?.label}
            </div>
          )
        })}
    </div>
  )
}

Subdomains

Frequently Asked Questions

What does ChartLegendContent() do?
ChartLegendContent() is a function in the ui codebase, defined in apps/v4/registry/bases/radix/ui/chart.tsx.
Where is ChartLegendContent() defined?
ChartLegendContent() is defined in apps/v4/registry/bases/radix/ui/chart.tsx at line 252.
What does ChartLegendContent() call?
ChartLegendContent() calls 2 function(s): getPayloadConfigFromPayload, useChart.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free