-
-
Notifications
You must be signed in to change notification settings - Fork 645
docs(charts): add more area charts #1666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| <script setup lang="ts"> | ||
| import type { | ||
| ChartConfig, | ||
| } from "@/registry/new-york-v4/ui/chart" | ||
| // import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts" | ||
| import { VisArea, VisAxis, VisXYContainer } from "@unovis/vue" | ||
| import { TrendingUp } from "lucide-vue-next" | ||
|
|
||
| import { | ||
| Card, | ||
| CardContent, | ||
| CardDescription, | ||
| CardFooter, | ||
| CardHeader, | ||
| CardTitle, | ||
| } from "@/registry/new-york-v4/ui/card" | ||
| import { | ||
| ChartContainer, | ||
| ChartCrosshair, | ||
| ChartLegendContent, | ||
| ChartTooltip, | ||
| ChartTooltipContent, | ||
| componentToString, | ||
| } from "@/registry/new-york-v4/ui/chart" | ||
|
|
||
| const description = "An area chart with axes" | ||
|
|
||
| const chartData = [ | ||
| { month: 1, monthLabel: "January", desktop: 186 }, | ||
| { month: 2, monthLabel: "February", desktop: 305 }, | ||
| { month: 3, monthLabel: "March", desktop: 237 }, | ||
| { month: 4, monthLabel: "April", desktop: 73 }, | ||
| { month: 5, monthLabel: "May", desktop: 209 }, | ||
| { month: 6, monthLabel: "June", desktop: 214 }, | ||
| ] | ||
|
|
||
| type Data = typeof chartData[number] | ||
|
|
||
| const chartConfig = { | ||
| desktop: { | ||
| label: "Desktop", | ||
| color: "var(--chart-1)", | ||
| }, | ||
| } satisfies ChartConfig | ||
| </script> | ||
|
|
||
| <template> | ||
| <Card> | ||
| <CardHeader> | ||
| <CardTitle>Area Chart</CardTitle> | ||
| <CardDescription> | ||
| Showing total visitors for the last 6 months | ||
| </CardDescription> | ||
| </CardHeader> | ||
| <CardContent> | ||
| <ChartContainer :config="chartConfig"> | ||
| <VisXYContainer :data="chartData" :margin="{ top: 10, bottom: 10 }"> | ||
| <VisArea | ||
| :x="(d: Data) => d.month" | ||
| :y="[(d: Data) => d.desktop]" | ||
| :color="chartConfig.desktop.color" | ||
| :opacity="0.4" | ||
| :line="true" | ||
| :line-width="1" | ||
| /> | ||
| <VisAxis | ||
| type="x" | ||
| :x="(d: Data) => d.month" | ||
| :tick-line="false" | ||
| :domain-line="false" | ||
| :grid-line="false" | ||
| :num-ticks="6" | ||
| :tick-format="(d: number, index: number) => { | ||
| return chartData[index].monthLabel.slice(0, 3) | ||
| }" | ||
| /> | ||
| <VisAxis | ||
| type="y" | ||
| :num-ticks="3" | ||
| :tick-line="false" | ||
| :domain-line="false" | ||
| :tick-format="(d: number, index: number) => ''" | ||
| /> | ||
| <ChartTooltip /> | ||
| <ChartCrosshair | ||
| :template="componentToString(chartConfig, ChartTooltipContent, { labelKey: 'monthLabel', indicator: 'line' })" | ||
| :color="chartConfig.desktop.color" | ||
| /> | ||
| </VisXYContainer> | ||
|
|
||
| <ChartLegendContent /> | ||
| </ChartContainer> | ||
| </CardContent> | ||
| <CardFooter> | ||
| <div class="flex w-full items-start gap-2 text-sm"> | ||
| <div class="grid gap-2"> | ||
| <div class="flex items-center gap-2 leading-none font-medium"> | ||
| Trending up by 5.2% this month <TrendingUp class="h-4 w-4" /> | ||
| </div> | ||
| <div class="text-muted-foreground flex items-center gap-2 leading-none"> | ||
| January - June 2024 | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </CardFooter> | ||
| </Card> | ||
| </template> | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||||||||||
| <script setup lang="ts"> | ||||||||||||||
| import type { | ||||||||||||||
| ChartConfig, | ||||||||||||||
| } from "@/registry/new-york-v4/ui/chart" | ||||||||||||||
| // import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts" | ||||||||||||||
| import { VisArea, VisAxis, VisXYContainer } from "@unovis/vue" | ||||||||||||||
| import { TrendingUp } from "lucide-vue-next" | ||||||||||||||
|
|
||||||||||||||
| import { | ||||||||||||||
| Card, | ||||||||||||||
| CardContent, | ||||||||||||||
| CardDescription, | ||||||||||||||
| CardFooter, | ||||||||||||||
| CardHeader, | ||||||||||||||
| CardTitle, | ||||||||||||||
| } from "@/registry/new-york-v4/ui/card" | ||||||||||||||
| import { | ||||||||||||||
| ChartContainer, | ||||||||||||||
| ChartCrosshair, | ||||||||||||||
| ChartLegendContent, | ||||||||||||||
| ChartTooltip, | ||||||||||||||
| ChartTooltipContent, | ||||||||||||||
| componentToString, | ||||||||||||||
| } from "@/registry/new-york-v4/ui/chart" | ||||||||||||||
|
|
||||||||||||||
| const description = "An area chart with axes" | ||||||||||||||
|
|
||||||||||||||
| const chartData = [ | ||||||||||||||
| { month: 1, monthLabel: "January", desktop: 186, mobile: 80 }, | ||||||||||||||
| { month: 2, monthLabel: "February", desktop: 305, mobile: 200 }, | ||||||||||||||
| { month: 3, monthLabel: "March", desktop: 237, mobile: 120 }, | ||||||||||||||
| { month: 4, monthLabel: "April", desktop: 73, mobile: 190 }, | ||||||||||||||
| { month: 5, monthLabel: "May", desktop: 209, mobile: 130 }, | ||||||||||||||
| { month: 6, monthLabel: "June", desktop: 214, mobile: 140 }, | ||||||||||||||
| ] | ||||||||||||||
|
|
||||||||||||||
| type Data = typeof chartData[number] | ||||||||||||||
|
|
||||||||||||||
| const chartConfig = { | ||||||||||||||
| mobile: { | ||||||||||||||
| label: "Mobile", | ||||||||||||||
| color: "var(--chart-2)", | ||||||||||||||
| }, | ||||||||||||||
| desktop: { | ||||||||||||||
| label: "Desktop", | ||||||||||||||
| color: "var(--chart-1)", | ||||||||||||||
| }, | ||||||||||||||
| } satisfies ChartConfig | ||||||||||||||
| </script> | ||||||||||||||
|
|
||||||||||||||
| <template> | ||||||||||||||
| <Card> | ||||||||||||||
| <CardHeader> | ||||||||||||||
| <CardTitle>Area Chart - Legend</CardTitle> | ||||||||||||||
| <CardDescription> | ||||||||||||||
| Showing total visitors for the last 6 months | ||||||||||||||
| </CardDescription> | ||||||||||||||
| </CardHeader> | ||||||||||||||
| <CardContent> | ||||||||||||||
| <ChartContainer :config="chartConfig"> | ||||||||||||||
| <VisXYContainer :data="chartData" :margin="{ top: 10, bottom: 10 }"> | ||||||||||||||
| <VisArea | ||||||||||||||
| :x="(d: Data) => d.month" | ||||||||||||||
| :y="[(d: Data) => d.mobile, (d: Data) => d.desktop]" | ||||||||||||||
| :color="(d: Data, i: number) => [chartConfig.mobile.color, chartConfig.desktop.color][i]" | ||||||||||||||
| :opacity="0.4" | ||||||||||||||
| :line="true" | ||||||||||||||
| :line-width="1" | ||||||||||||||
| /> | ||||||||||||||
| <VisAxis | ||||||||||||||
| type="x" | ||||||||||||||
| :x="(d: Data) => d.month" | ||||||||||||||
| :tick-line="false" | ||||||||||||||
| :domain-line="false" | ||||||||||||||
| :grid-line="false" | ||||||||||||||
| :num-ticks="6" | ||||||||||||||
| :tick-format="(d: number, index: number) => { | ||||||||||||||
| return chartData[index].monthLabel.slice(0, 3) | ||||||||||||||
| }" | ||||||||||||||
|
Comment on lines
+77
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add defensive check for array index access. Same potential out-of-bounds issue as other chart files when Unovis passes unexpected index values. π‘οΈ Suggested defensive fix :tick-format="(d: number, index: number) => {
- return chartData[index].monthLabel.slice(0, 3)
+ return chartData[index]?.monthLabel?.slice(0, 3) ?? ''
}"π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||
| /> | ||||||||||||||
| <VisAxis | ||||||||||||||
| type="y" | ||||||||||||||
| :num-ticks="3" | ||||||||||||||
| :tick-line="false" | ||||||||||||||
| :domain-line="false" | ||||||||||||||
| :tick-format="(d: number, index: number) => ''" | ||||||||||||||
| /> | ||||||||||||||
| <ChartTooltip /> | ||||||||||||||
| <ChartCrosshair | ||||||||||||||
| :template="componentToString(chartConfig, ChartTooltipContent, { labelKey: 'monthLabel', indicator: 'line' })" | ||||||||||||||
| :color="(d: Data, i: number) => [chartConfig.mobile.color, chartConfig.desktop.color][i % 2]" | ||||||||||||||
| /> | ||||||||||||||
| </VisXYContainer> | ||||||||||||||
|
|
||||||||||||||
| <ChartLegendContent /> | ||||||||||||||
| </ChartContainer> | ||||||||||||||
| </CardContent> | ||||||||||||||
| <CardFooter> | ||||||||||||||
| <div class="flex w-full items-start gap-2 text-sm"> | ||||||||||||||
| <div class="grid gap-2"> | ||||||||||||||
| <div class="flex items-center gap-2 leading-none font-medium"> | ||||||||||||||
| Trending up by 5.2% this month <TrendingUp class="h-4 w-4" /> | ||||||||||||||
| </div> | ||||||||||||||
| <div class="text-muted-foreground flex items-center gap-2 leading-none"> | ||||||||||||||
| January - June 2024 | ||||||||||||||
| </div> | ||||||||||||||
| </div> | ||||||||||||||
| </div> | ||||||||||||||
| </CardFooter> | ||||||||||||||
| </Card> | ||||||||||||||
| </template> | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add defensive check for array index access.
π‘οΈ Suggested defensive fix
:tick-format="(d: number, index: number) => { - return chartData[index].monthLabel.slice(0, 3) + return chartData[index]?.monthLabel?.slice(0, 3) ?? '' }"π Committable suggestion
π€ Prompt for AI Agents