Momentum Chart
zenincharts/momentum-chartFreeComponent
Displays a metric’s value, change, and trend to highlight momentum over time.
Live preview
live · rendered by the registry
Rendered by zenincharts on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://charts.zenin.design/r/momentum-chart.jsonSource
1"use client";2import { HugeiconsIcon } from "@hugeicons/react";3import { DotPattern } from "./dot-pattern";4import { ArrowUpRight01Icon } from "@hugeicons/core-free-icons";5import { Area, AreaChart, ResponsiveContainer, XAxis } from "recharts";6import { useSpring, motion, useTransform } from "motion/react";7import { useEffect } from "react";89const momentumData = [10 { day: "Mon", value: 90000 },11 { day: "Tue", value: 140000 },12 { day: "Wed", value: 175000 },13 { day: "Thu", value: 150000 },14 { day: "Fri", value: 110000 },15 { day: "Sat", value: 200000 },16 { day: "Sun", value: 264802.43 },17];1819export const MomentumChart = () => {20 const lastPrice = momentumData[momentumData.length - 1];21 const priceSpring = useSpring(lastPrice.value, {22 damping: 20,23 stiffness: 300,24 });2526 const basePrice = momentumData[0].value;27 const delta = useTransform(priceSpring, (v) => v - basePrice);28 const percentage = useTransform(priceSpring, (v) => {29 const change = v - basePrice;30 return (change / basePrice) * 100;31 });3233 const formattedPrice = useTransform(priceSpring, (v) =>34 v.toLocaleString("en-US", {35 minimumFractionDigits: 2,36 maximumFractionDigits: 2,37 }),38 );39 const formattedDelta = useTransform(delta, (v) => {40 const sign = v >= 0 ? "+" : "-";41 return `${sign} $${Math.abs(v).toLocaleString("en-US", {42 minimumFractionDigits: 2,43 maximumFractionDigits: 2,44 })}`;45 });4647 const formattedPercentage = useTransform(percentage, (v) => {48 const sign = v >= 0 ? "+" : "-";49 return `(${sign}${Math.abs(v).toFixed(2)}%)`;50 });5152 const isPositive = useTransform(delta, (v) => v >= 0);53 const deltaColor = useTransform(isPositive, (v) =>54 v ? "#60a5fa" : "#f87171",55 );5657 const previousWeekClose = momentumData[0].value;58 const weekComparison = useTransform(priceSpring, (v) => {59 const change = v - previousWeekClose;60 return (change / previousWeekClose) * 100;61 });62 const weekSentence = useTransform(weekComparison, (v) => {63 const sign = v >= 0 ? "+" : "-";64 const word = v >= 0 ? "More" : "Less";6566 return `${sign}${Math.abs(v).toFixed(2)}% ${word} than last week`;67 });6869 useEffect(() => {70 priceSpring.set(lastPrice.value);71 }, [lastPrice.value]);7273 return (74// … truncated
What it pulls in
npm packages
Files it writes
More from zenincharts
All 4 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Crypto Price Chartcrypto-price-chart | zenincharts | Components | Free | 4 deps · 2 files | |
| Members Growth Chartmembers-growth-chart | zenincharts | Components | Free | 4 deps · 2 files | |
| Revenue Trends Chartrevenue-trends | zenincharts | Components | Free | 1 dep |
