Home / Function/ ChartTooltipContent() — ui Function Reference

ChartTooltipContent() — ui Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  d279979c_0355_0f08_c1b1_30ae2d627846["ChartTooltipContent()"]
  4f126d71_ecf3_d37f_a804_0d9b0ac0f9a9["chart.tsx"]
  d279979c_0355_0f08_c1b1_30ae2d627846 -->|defined in| 4f126d71_ecf3_d37f_a804_0d9b0ac0f9a9
  6862488e_a650_d784_a293_18ec9134f013["useChart()"]
  d279979c_0355_0f08_c1b1_30ae2d627846 -->|calls| 6862488e_a650_d784_a293_18ec9134f013
  7e18f420_c680_d688_87f0_6b124e597d5b["getPayloadConfigFromPayload()"]
  d279979c_0355_0f08_c1b1_30ae2d627846 -->|calls| 7e18f420_c680_d688_87f0_6b124e597d5b
  style d279979c_0355_0f08_c1b1_30ae2d627846 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/examples/radix/ui/chart.tsx lines 106–250

function ChartTooltipContent({
  active,
  payload,
  className,
  indicator = "dot",
  hideLabel = false,
  hideIndicator = false,
  label,
  labelFormatter,
  labelClassName,
  formatter,
  color,
  nameKey,
  labelKey,
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
  React.ComponentProps<"div"> & {
    hideLabel?: boolean
    hideIndicator?: boolean
    indicator?: "line" | "dot" | "dashed"
    nameKey?: string
    labelKey?: string
  }) {
  const { config } = useChart()

  const tooltipLabel = React.useMemo(() => {
    if (hideLabel || !payload?.length) {
      return null
    }

    const [item] = payload
    const key = `${labelKey || item?.dataKey || item?.name || "value"}`
    const itemConfig = getPayloadConfigFromPayload(config, item, key)
    const value =
      !labelKey && typeof label === "string"
        ? config[label as keyof typeof config]?.label || label
        : itemConfig?.label

    if (labelFormatter) {
      return (
        <div className={cn("font-medium", labelClassName)}>
          {labelFormatter(value, payload)}
        </div>
      )
    }

    if (!value) {
      return null
    }

    return <div className={cn("font-medium", labelClassName)}>{value}</div>
  }, [
    label,
    labelFormatter,
    payload,
    hideLabel,
    labelClassName,
    config,
    labelKey,
  ])

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

  const nestLabel = payload.length === 1 && indicator !== "dot"

  return (
    <div
      className={cn(
        "border-border/50 bg-background grid min-w-32 items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
        className
      )}
    >
      {!nestLabel ? tooltipLabel : null}
      <div className="grid gap-1.5">
        {payload
          .filter((item) => item.type !== "none")
          .map((item, index) => {
            const key = `${nameKey || item.name || item.dataKey || "value"}`
            const itemConfig = getPayloadConfigFromPayload(config, item, key)
            const indicatorColor = color || item.payload.fill || item.color

Subdomains

Frequently Asked Questions

What does ChartTooltipContent() do?
ChartTooltipContent() is a function in the ui codebase, defined in apps/v4/examples/radix/ui/chart.tsx.
Where is ChartTooltipContent() defined?
ChartTooltipContent() is defined in apps/v4/examples/radix/ui/chart.tsx at line 106.
What does ChartTooltipContent() call?
ChartTooltipContent() 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