File size: 2,226 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 57 58 59 60 61 62 63 64 65 66 67 68 |
"use client"
import { Chart, useChart } from "@chakra-ui/charts"
import { Box, For, Heading, SimpleGrid } from "@chakra-ui/react"
import { Area, AreaChart, CartesianGrid, Tooltip, XAxis } from "recharts"
export const AreaChartWithNulls = () => {
const chart = useChart({
data: [
{ sales: 186, month: "January" },
{ sales: null, month: "February" },
{ sales: 190, month: "March" },
{ sales: 195, month: "May" },
{ sales: null, month: "June" },
{ sales: 175, month: "August" },
{ sales: 180, month: "October" },
{ sales: 185, month: "November" },
{ sales: 300, month: "December" },
],
series: [{ name: "sales", color: "teal.solid" }],
})
return (
<SimpleGrid gap="10" minChildWidth="400px">
<For each={["false", "true"]}>
{(connectNulls) => (
<Box key={connectNulls.toString()}>
<Heading size="md" mb="4">
{`<Area connectNulls={${connectNulls.toString()}} />`}
</Heading>
<Chart.Root maxH="sm" chart={chart}>
<AreaChart 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)}
/>
<Tooltip
cursor={false}
animationDuration={100}
content={<Chart.Tooltip />}
/>
{chart.series.map((item) => (
<Area
key={item.name}
isAnimationActive={false}
dataKey={chart.key(item.name)}
fill={chart.color(item.color)}
fillOpacity={0.2}
connectNulls={connectNulls === "true"}
stroke={chart.color(item.color)}
stackId="a"
/>
))}
</AreaChart>
</Chart.Root>
</Box>
)}
</For>
</SimpleGrid>
)
}
|