"use client" import * as React from "react" import { Bar, BarChart, CartesianGrid, XAxis } from "recharts" import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/registry/new-york-v4/ui/card" import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "@/registry/new-york-v4/ui/chart" export const description = "An interactive bar chart" const chartData = [ { date: "2024-04-01", desktop: 222, mobile: 150 }, { date: "2024-04-02", desktop: 97, mobile: 180 }, { date: "2024-04-03", desktop: 167, mobile: 120 }, { date: "2024-04-04", desktop: 242, mobile: 260 }, { date: "2024-04-05", desktop: 373, mobile: 290 }, { date: "2024-04-06", desktop: 301, mobile: 340 }, { date: "2024-04-07", desktop: 245, mobile: 180 }, { date: "2024-04-08", desktop: 409, mobile: 320 }, { date: "2024-04-09", desktop: 59, mobile: 110 }, { date: "2024-04-10", desktop: 261, mobile: 190 }, { date: "2024-04-11", desktop: 327, mobile: 350 }, { date: "2024-04-12", desktop: 292, mobile: 210 }, { date: "2024-04-13", desktop: 342, mobile: 380 }, { date: "2024-04-14", desktop: 137, mobile: 220 }, { date: "2024-04-15", desktop: 120, mobile: 170 }, { date: "2024-04-16", desktop: 138, mobile: 190 }, { date: "2024-04-17", desktop: 446, mobile: 360 }, { date: "2024-04-18", desktop: 364, mobile: 410 }, { date: "2024-04-19", desktop: 243, mobile: 180 }, { date: "2024-04-20", desktop: 89, mobile: 150 }, { date: "2024-04-21", desktop: 137, mobile: 200 }, { date: "2024-04-22", desktop: 224, mobile: 170 }, { date: "2024-04-23", desktop: 138, mobile: 230 }, { date: "2024-04-24", desktop: 387, mobile: 290 }, { date: "2024-04-25", desktop: 215, mobile: 250 }, { date: "2024-04-26", desktop: 75, mobile: 130 }, { date: "2024-04-27", desktop: 383, mobile: 420 }, { date: "2024-04-28", desktop: 122, mobile: 180 }, { date: "2024-04-29", desktop: 315, mobile: 240 }, { date: "2024-04-30", desktop: 454, mobile: 380 }, ] const chartConfig = { views: { label: "Page Views", }, desktop: { label: "Desktop", color: "var(--chart-2)", }, mobile: { label: "Mobile", color: "var(--chart-1)", }, } satisfies ChartConfig export function ChartDemo() { const [activeChart, setActiveChart] = React.useState("desktop") const total = React.useMemo( () => ({ desktop: chartData.reduce((acc, curr) => acc + curr.desktop, 0), mobile: chartData.reduce((acc, curr) => acc + curr.mobile, 0), }), [] ) return (
Bar Chart - Interactive Showing total visitors for the last 3 months
{["desktop", "mobile"].map((key) => { const chart = key as keyof typeof chartConfig return ( ) })}
{ const date = new Date(value) return date.toLocaleDateString("en-US", { month: "short", day: "numeric", }) }} /> { return new Date(value).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", }) }} /> } />
) }