Animated Chart
abui/animated-chartFreeBlock
An animated column chart with spring physics, viewport-triggered animations, and support for dynamic data transitions.
Live preview
live · rendered by the registry
Rendered by abui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://abui.io/r/animated-chart.jsonSource
1"use client"23import * as React from "react"4import { useRef, useEffect, useMemo } from "react"5import { motion, useInView, useAnimationControls } from "motion/react"67import { cn } from "@/lib/utils"89interface ColumnData {10 title: string11 value: number12 /** String to prepend before the value (e.g., "$") */13 prependString?: string14 /** String to append after the value (e.g., "%") */15 appendString?: string16 /** Animation duration in seconds */17 animationDuration?: number18 /** Animation delay in seconds */19 animationDelay?: number20 /** ClassName applied to the animated column bar element */21 className?: string22 /** ClassName applied to the column's top border */23 topBorderClassName?: string24 /** ClassName applied to this column's title (overrides global titleClassName) */25 titleClassName?: string26 /** ClassName applied to this column's value (overrides global valueClassName) */27 valueClassName?: string28}2930interface AnimatedChartProps extends React.ComponentPropsWithoutRef<"div"> {31 columns: ColumnData[]32 maxValue: number33 /** ClassName applied to all column titles */34 titleClassName?: string35 /** ClassName applied to all column values */36 valueClassName?: string37 /** When true, columns animate from zero whenever data changes. Default: false */38 restartOnDataChange?: boolean39}4041interface AnimatedChartColumnProps extends React.ComponentPropsWithoutRef<"div"> {42 title: string43 value: number44 maxValue: number45 prependString?: string46 appendString?: string47 animationDuration: number48 animationDelay: number49 columnClassName?: string50 topBorderClassName?: string51 /** Global titleClassName from parent */52 globalTitleClassName?: string53 /** Global valueClassName from parent */54 globalValueClassName?: string55 /** Column-specific titleClassName (overrides global) */56 columnTitleClassName?: string57 /** Column-specific valueClassName (overrides global) */58 columnValueClassName?: string59 isInView: boolean60 isLast: boolean61 restartTrigger: number62}6364function AnimatedChartColumn({65 title,66 value,67 maxValue,68 prependString,69 appendString,70 animationDuration,71 animationDelay,72 columnClassName,73 topBorderClassName,74 globalTitleClassName,75 globalValueClassName,76 columnTitleClassName,77 columnValueClassName,78 isInView,79 isLast,80 restartTrigger,81 className,82 ...props83}: AnimatedChartColumnProps) {84 const heightPercentage = (value / maxValue) * 10085 const heightPercentageRef = useRef(heightPercentage)86// … truncated
What it pulls in
npm packages
Files it writes
More from abui
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Availabilityavailability | abui | Blocks | Free | 1 dep | |
| Calendar Yearcalendar-year | abui | Blocks | Free | 1 dep | |
| Scroll Reveal Content Ascroll-reveal-content-a | abui | Blocks | Free | 1 dep | |
| Timelinetimeline | abui | Blocks | Free | 3 deps |
