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
  f96d129d_d161_af19_642b_0d85d759afc1["ChartLegendContent()"]
  83a6d23c_094d_32b5_639b_1c48ba14cc85["chart.tsx"]
  f96d129d_d161_af19_642b_0d85d759afc1 -->|defined in| 83a6d23c_094d_32b5_639b_1c48ba14cc85
  445e2fb8_1ddb_b34b_bee3_820390170b64["useChart()"]
  f96d129d_d161_af19_642b_0d85d759afc1 -->|calls| 445e2fb8_1ddb_b34b_bee3_820390170b64
  51d65ab4_64e6_0f77_3a35_c9dc3766ae0c["getPayloadConfigFromPayload()"]
  f96d129d_d161_af19_642b_0d85d759afc1 -->|calls| 51d65ab4_64e6_0f77_3a35_c9dc3766ae0c
  style f96d129d_d161_af19_642b_0d85d759afc1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/examples/base/ui/chart.tsx lines 254–308

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/examples/base/ui/chart.tsx.
Where is ChartLegendContent() defined?
ChartLegendContent() is defined in apps/v4/examples/base/ui/chart.tsx at line 254.
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