File size: 1,585 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
"use client"
import { Chart, useChart } from "@chakra-ui/charts"
import { Bar, BarChart, CartesianGrid, Tooltip, XAxis, YAxis } from "recharts"
export const BarChartWithFormatter = () => {
const chart = useChart({
data: [
{ sales: 63000, month: "June" },
{ sales: 72000, month: "July" },
{ sales: 85000, month: "August" },
{ sales: 79000, month: "September" },
{ sales: 90000, month: "October" },
{ sales: 95000, month: "November" },
{ sales: 88000, month: "December" },
],
series: [{ name: "sales", color: "teal.solid" }],
})
return (
<Chart.Root maxH="sm" chart={chart}>
<BarChart data={chart.data}>
<CartesianGrid stroke={chart.color("border.muted")} vertical={false} />
<XAxis
axisLine={false}
tickLine={false}
dataKey={chart.key("month")}
tickFormatter={(value) => value.slice(0, 3)}
/>
<YAxis
axisLine={false}
tickLine={false}
tickFormatter={chart.formatNumber({
style: "currency",
currency: "USD",
notation: "compact",
})}
/>
<Tooltip
cursor={{ fill: chart.color("bg.muted") }}
animationDuration={0}
content={<Chart.Tooltip />}
/>
{chart.series.map((item) => (
<Bar
isAnimationActive={false}
key={item.name}
dataKey={chart.key(item.name)}
fill={chart.color(item.color)}
/>
))}
</BarChart>
</Chart.Root>
)
}
|