Skip to content
HooksPro

useChartAnimation

The draw-in animation props every WunderUI chart passes to its Recharts series.

Returns , , and for a Recharts series. The series draw in once on mount and then stop animating, so a resize or new data does not replay the draw-in. Under reduced motion they never animate.

See alsoLine Chart

Import

tsx
import { useChartAnimation } from "@wunderui/react"

Comes with WunderUI Core and Pro, in the package from your plan. See the plans.

Signature

ts
useChartAnimation(animate?: boolean, appear?: ChartAppearState | undefined): { isAnimationActive: boolean; animationDuration: number; animationEasing: "ease-out"; animationBegin: number; }

Parameters

ParameterTypeDefault
animate?booleantrue
appear?ChartAppearState | undefined—

Returns

FieldType
isAnimationActiveboolean
animationDurationnumber
animationEasing"ease-out"
animationBeginnumber

Examples

A custom Recharts series

tsx
import { Line, LineChart } from "recharts"
import { useChartAnimation } from "@wunderui/react"

export function TrendLine({ data }: { data: { day: string; value: number }[] }) {
  const animation = useChartAnimation()
  return (
    <LineChart width={320} height={120} data={data}>
      <Line dataKey="value" stroke="var(--chart-1)" dot={false} {...animation} />
    </LineChart>
  )
}

Notes

  • Use it only in a custom chart built from Recharts parts; the WunderUI charts already call it.
  • Pass to switch the draw-in off, for example in a table of many small charts.
  • With , pass its as the second argument: the series then animate exactly while the appear sequence runs.