feat: bar and donut examples
This commit is contained in:
parent
6ac1d40bf2
commit
5e04e49327
|
|
@ -41,6 +41,6 @@ We can turn the chart into sparkline chart by hiding axis, gridline and legends.
|
||||||
|
|
||||||
### Custom Tooltip
|
### Custom Tooltip
|
||||||
|
|
||||||
If you want to render custom tooltip, you can easily pass in a custom component. Refer to prop definition [here](http://localhost:5173/docs/charts/guide.html#custom-tooltip).
|
If you want to render custom tooltip, you can easily pass in a custom component. Refer to prop definition [here](/docs/charts/guide.html#custom-tooltip).
|
||||||
|
|
||||||
<ComponentPreview name="AreaChartCustomTooltip" />
|
<ComponentPreview name="AreaChartCustomTooltip" />
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,24 @@ Follow the [guide](/docs/charts/guide.html#installation) to complete the setup.
|
||||||
|
|
||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
<!-- @include: @/content/meta/BarChart.md -->
|
<!-- @include: @/content/meta/BarChart.md -->
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
### Stacked
|
||||||
|
|
||||||
|
You can stack the bar chart by settings prop `type` to `stacked`.
|
||||||
|
|
||||||
|
<ComponentPreview name="BarChartStacked" />
|
||||||
|
|
||||||
|
### Rounded
|
||||||
|
|
||||||
|
<ComponentPreview name="BarChartRounded" />
|
||||||
|
|
||||||
|
### Custom Tooltip
|
||||||
|
|
||||||
|
If you want to render custom tooltip, you can easily pass in a custom component. Refer to prop definition [here](/docs/charts/guide.html#custom-tooltip).
|
||||||
|
|
||||||
|
<ComponentPreview name="BarChartCustomTooltip" />
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,26 @@ Follow the [guide](/docs/charts/guide.html#installation) to complete the setup.
|
||||||
|
|
||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
<!-- @include: @/content/meta/DonutChart.md -->
|
<!-- @include: @/content/meta/DonutChart.md -->
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
### Pie Chart
|
||||||
|
|
||||||
|
If you want to render pie chart instead, pass `type` as `pie`.
|
||||||
|
|
||||||
|
<ComponentPreview name="DonutChartPie" />
|
||||||
|
|
||||||
|
### Color
|
||||||
|
|
||||||
|
We generate colors automatically based on the primary and secondary color and assigned them accordingly. Feel free to pass in your own array of colors.
|
||||||
|
|
||||||
|
<ComponentPreview name="DonutChartColor" />
|
||||||
|
|
||||||
|
### Custom Tooltip
|
||||||
|
|
||||||
|
If you want to render custom tooltip, you can easily pass in a custom component. Refer to prop definition [here](/docs/charts/guide.html#custom-tooltip).
|
||||||
|
|
||||||
|
<ComponentPreview name="DonutChartCustomTooltip" />
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ Follow the [guide](/docs/charts/guide.html#installation) to complete the setup.
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
<!-- @include: @/content/meta/AreaChart.md -->
|
<!-- @include: @/content/meta/LineChart.md -->
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|
@ -41,6 +41,6 @@ We can turn the chart into sparkline chart by hiding axis, gridline and legends.
|
||||||
|
|
||||||
### Custom Tooltip
|
### Custom Tooltip
|
||||||
|
|
||||||
If you want to render custom tooltip, you can easily pass in a custom component. Refer to prop definition [here](http://localhost:5173/docs/charts/guide.html#custom-tooltip).
|
If you want to render custom tooltip, you can easily pass in a custom component. Refer to prop definition [here](/docs/charts/guide.html#custom-tooltip).
|
||||||
|
|
||||||
<ComponentPreview name="LineChartCustomTooltip" />
|
<ComponentPreview name="LineChartCustomTooltip" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import CustomChartTooltip from './CustomChartTooltip.vue'
|
||||||
|
import { BarChart } from '@/lib/registry/default/ui/chart-bar'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jul', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BarChart
|
||||||
|
:data="data"
|
||||||
|
index="name"
|
||||||
|
:categories="['total', 'predicted']"
|
||||||
|
:y-formatter="(tick, i) => {
|
||||||
|
return typeof tick === 'number'
|
||||||
|
? `$ ${new Intl.NumberFormat('us').format(tick).toString()}`
|
||||||
|
: ''
|
||||||
|
}"
|
||||||
|
:custom-tooltip="CustomChartTooltip"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { BarChart } from '@/lib/registry/default/ui/chart-bar'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jul', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BarChart
|
||||||
|
index="name"
|
||||||
|
:data="data"
|
||||||
|
:categories="['total', 'predicted']"
|
||||||
|
:y-formatter="(tick, i) => {
|
||||||
|
return typeof tick === 'number'
|
||||||
|
? `$ ${new Intl.NumberFormat('us').format(tick).toString()}`
|
||||||
|
: ''
|
||||||
|
}"
|
||||||
|
:rounded-corners="4"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { BarChart } from '@/lib/registry/default/ui/chart-bar'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jul', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BarChart
|
||||||
|
index="name"
|
||||||
|
:data="data"
|
||||||
|
:categories="['total', 'predicted']"
|
||||||
|
:y-formatter="(tick, i) => {
|
||||||
|
return typeof tick === 'number'
|
||||||
|
? `$ ${new Intl.NumberFormat('us').format(tick).toString()}`
|
||||||
|
: ''
|
||||||
|
}"
|
||||||
|
:type="'stacked'"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { DonutChart } from '@/lib/registry/new-york/ui/chart-donut'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
|
||||||
|
const valueFormatter = (tick: number | Date) => typeof tick === 'number' ? `$ ${new Intl.NumberFormat('us').format(tick).toString()}` : ''
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<DonutChart
|
||||||
|
index="name"
|
||||||
|
:category="'total'"
|
||||||
|
:data="data"
|
||||||
|
:value-formatter="valueFormatter"
|
||||||
|
:colors="['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import CustomChartTooltip from './CustomChartTooltip.vue'
|
||||||
|
import { DonutChart } from '@/lib/registry/default/ui/chart-donut'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<DonutChart
|
||||||
|
index="name"
|
||||||
|
:category="'total'"
|
||||||
|
:data="data"
|
||||||
|
:custom-tooltip="CustomChartTooltip"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
21
apps/www/src/lib/registry/default/example/DonutChartPie.vue
Normal file
21
apps/www/src/lib/registry/default/example/DonutChartPie.vue
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { DonutChart } from '@/lib/registry/default/ui/chart-donut'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<DonutChart
|
||||||
|
index="name"
|
||||||
|
:category="'total'"
|
||||||
|
:data="data"
|
||||||
|
:type="'pie'"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -33,7 +33,6 @@ const props = withDefaults(defineProps<BaseChartProps<T> & {
|
||||||
showLegend: true,
|
showLegend: true,
|
||||||
showGridLine: true,
|
showGridLine: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const emits = defineEmits<{
|
const emits = defineEmits<{
|
||||||
legendItemClick: [d: BulletLegendItemInterface, i: number]
|
legendItemClick: [d: BulletLegendItemInterface, i: number]
|
||||||
}>()
|
}>()
|
||||||
|
|
@ -61,14 +60,14 @@ const selectorsBar = computed(() => props.type === 'grouped' ? GroupedBar.select
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="cn('w-full h-[400px] flex flex-col items-end', $attrs.class ?? '')">
|
<div :class="cn('w-full h-[400px] flex flex-col items-end', $attrs.class ?? '')">
|
||||||
<ChartLegend v-if="showLegend" v-model:items="legendItems" :custom-tooltip="customTooltip" @legend-item-click="handleLegendItemClick" />
|
<ChartLegend v-if="showLegend" v-model:items="legendItems" @legend-item-click="handleLegendItemClick" />
|
||||||
|
|
||||||
<VisXYContainer
|
<VisXYContainer
|
||||||
:data="data"
|
:data="data"
|
||||||
:style="{ height: isMounted ? '100%' : 'auto' }"
|
:style="{ height: isMounted ? '100%' : 'auto' }"
|
||||||
:margin="margin"
|
:margin="margin"
|
||||||
>
|
>
|
||||||
<ChartCrosshair v-if="showTooltip" :colors="colors" :items="legendItems" :index="index" />
|
<ChartCrosshair v-if="showTooltip" :colors="colors" :items="legendItems" :custom-tooltip="customTooltip" :index="index" />
|
||||||
|
|
||||||
<VisBarComponent
|
<VisBarComponent
|
||||||
:x="(d: Data, i: number) => i"
|
:x="(d: Data, i: number) => i"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts" generic="T extends Record<string, any>">
|
<script setup lang="ts" generic="T extends Record<string, any>">
|
||||||
import { VisDonut, VisSingleContainer } from '@unovis/vue'
|
import { VisDonut, VisSingleContainer } from '@unovis/vue'
|
||||||
import { Donut } from '@unovis/ts'
|
import { Donut } from '@unovis/ts'
|
||||||
import { type DefineComponent, computed, ref } from 'vue'
|
import { type Component, computed, ref } from 'vue'
|
||||||
import { useMounted } from '@vueuse/core'
|
import { useMounted } from '@vueuse/core'
|
||||||
import { type BaseChartProps, ChartSingleTooltip, defaultColors } from '@/lib/registry/default/ui/chart'
|
import { type BaseChartProps, ChartSingleTooltip, defaultColors } from '@/lib/registry/default/ui/chart'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
@ -27,7 +27,7 @@ const props = withDefaults(defineProps<Pick<BaseChartProps<T>, 'data' | 'colors'
|
||||||
/**
|
/**
|
||||||
* Render custom tooltip component.
|
* Render custom tooltip component.
|
||||||
*/
|
*/
|
||||||
customTooltip?: DefineComponent
|
customTooltip?: Component
|
||||||
}>(), {
|
}>(), {
|
||||||
margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
||||||
sortFunction: () => undefined,
|
sortFunction: () => undefined,
|
||||||
|
|
@ -75,7 +75,7 @@ const totalValue = computed(() => props.data.reduce((prev, curr) => {
|
||||||
:color="colors"
|
:color="colors"
|
||||||
:arc-width="type === 'donut' ? 20 : 0"
|
:arc-width="type === 'donut' ? 20 : 0"
|
||||||
:show-background="false"
|
:show-background="false"
|
||||||
:central-label="valueFormatter(totalValue)"
|
:central-label="type === 'donut' ? valueFormatter(totalValue) : ''"
|
||||||
:events="{
|
:events="{
|
||||||
[Donut.selectors.segment]: {
|
[Donut.selectors.segment]: {
|
||||||
click: (d: Data, ev: PointerEvent, i: number, elements: HTMLElement[]) => {
|
click: (d: Data, ev: PointerEvent, i: number, elements: HTMLElement[]) => {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import CustomChartTooltip from './CustomChartTooltip.vue'
|
||||||
|
import { BarChart } from '@/lib/registry/new-york/ui/chart-bar'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jul', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BarChart
|
||||||
|
:data="data"
|
||||||
|
index="name"
|
||||||
|
:categories="['total', 'predicted']"
|
||||||
|
:y-formatter="(tick, i) => {
|
||||||
|
return typeof tick === 'number'
|
||||||
|
? `$ ${new Intl.NumberFormat('us').format(tick).toString()}`
|
||||||
|
: ''
|
||||||
|
}"
|
||||||
|
:custom-tooltip="CustomChartTooltip"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { BarChart } from '@/lib/registry/new-york/ui/chart-bar'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jul', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BarChart
|
||||||
|
index="name"
|
||||||
|
:data="data"
|
||||||
|
:categories="['total', 'predicted']"
|
||||||
|
:y-formatter="(tick, i) => {
|
||||||
|
return typeof tick === 'number'
|
||||||
|
? `$ ${new Intl.NumberFormat('us').format(tick).toString()}`
|
||||||
|
: ''
|
||||||
|
}"
|
||||||
|
:rounded-corners="4"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { BarChart } from '@/lib/registry/new-york/ui/chart-bar'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jul', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BarChart
|
||||||
|
index="name"
|
||||||
|
:data="data"
|
||||||
|
:categories="['total', 'predicted']"
|
||||||
|
:y-formatter="(tick, i) => {
|
||||||
|
return typeof tick === 'number'
|
||||||
|
? `$ ${new Intl.NumberFormat('us').format(tick).toString()}`
|
||||||
|
: ''
|
||||||
|
}"
|
||||||
|
:type="'stacked'"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { DonutChart } from '@/lib/registry/new-york/ui/chart-donut'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
|
||||||
|
const valueFormatter = (tick: number | Date) => typeof tick === 'number' ? `$ ${new Intl.NumberFormat('us').format(tick).toString()}` : ''
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<DonutChart
|
||||||
|
index="name"
|
||||||
|
:category="'total'"
|
||||||
|
:data="data"
|
||||||
|
:value-formatter="valueFormatter"
|
||||||
|
:colors="['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import CustomChartTooltip from './CustomChartTooltip.vue'
|
||||||
|
import { DonutChart } from '@/lib/registry/new-york/ui/chart-donut'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<DonutChart
|
||||||
|
index="name"
|
||||||
|
:category="'total'"
|
||||||
|
:data="data"
|
||||||
|
:custom-tooltip="CustomChartTooltip"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
21
apps/www/src/lib/registry/new-york/example/DonutChartPie.vue
Normal file
21
apps/www/src/lib/registry/new-york/example/DonutChartPie.vue
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { DonutChart } from '@/lib/registry/new-york/ui/chart-donut'
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Apr', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'May', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
{ name: 'Jun', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<DonutChart
|
||||||
|
index="name"
|
||||||
|
:category="'total'"
|
||||||
|
:data="data"
|
||||||
|
:type="'pie'"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -61,14 +61,14 @@ const selectorsBar = computed(() => props.type === 'grouped' ? GroupedBar.select
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="cn('w-full h-[400px] flex flex-col items-end', $attrs.class ?? '')">
|
<div :class="cn('w-full h-[400px] flex flex-col items-end', $attrs.class ?? '')">
|
||||||
<ChartLegend v-if="showLegend" v-model:items="legendItems" :custom-tooltip="customTooltip" @legend-item-click="handleLegendItemClick" />
|
<ChartLegend v-if="showLegend" v-model:items="legendItems" @legend-item-click="handleLegendItemClick" />
|
||||||
|
|
||||||
<VisXYContainer
|
<VisXYContainer
|
||||||
:data="data"
|
:data="data"
|
||||||
:style="{ height: isMounted ? '100%' : 'auto' }"
|
:style="{ height: isMounted ? '100%' : 'auto' }"
|
||||||
:margin="margin"
|
:margin="margin"
|
||||||
>
|
>
|
||||||
<ChartCrosshair v-if="showTooltip" :colors="colors" :items="legendItems" :index="index" />
|
<ChartCrosshair v-if="showTooltip" :colors="colors" :items="legendItems" :custom-tooltip="customTooltip" :index="index" />
|
||||||
|
|
||||||
<VisBarComponent
|
<VisBarComponent
|
||||||
:x="(d: Data, i: number) => i"
|
:x="(d: Data, i: number) => i"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts" generic="T extends Record<string, any>">
|
<script setup lang="ts" generic="T extends Record<string, any>">
|
||||||
import { VisDonut, VisSingleContainer } from '@unovis/vue'
|
import { VisDonut, VisSingleContainer } from '@unovis/vue'
|
||||||
import { Donut } from '@unovis/ts'
|
import { Donut } from '@unovis/ts'
|
||||||
import { type DefineComponent, computed, ref } from 'vue'
|
import { type Component, computed, ref } from 'vue'
|
||||||
import { useMounted } from '@vueuse/core'
|
import { useMounted } from '@vueuse/core'
|
||||||
import { type BaseChartProps, ChartSingleTooltip, defaultColors } from '@/lib/registry/new-york/ui/chart'
|
import { type BaseChartProps, ChartSingleTooltip, defaultColors } from '@/lib/registry/new-york/ui/chart'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
@ -27,7 +27,7 @@ const props = withDefaults(defineProps<Pick<BaseChartProps<T>, 'data' | 'colors'
|
||||||
/**
|
/**
|
||||||
* Render custom tooltip component.
|
* Render custom tooltip component.
|
||||||
*/
|
*/
|
||||||
customTooltip?: DefineComponent
|
customTooltip?: Component
|
||||||
}>(), {
|
}>(), {
|
||||||
margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
||||||
sortFunction: () => undefined,
|
sortFunction: () => undefined,
|
||||||
|
|
@ -75,7 +75,7 @@ const totalValue = computed(() => props.data.reduce((prev, curr) => {
|
||||||
:color="colors"
|
:color="colors"
|
||||||
:arc-width="type === 'donut' ? 20 : 0"
|
:arc-width="type === 'donut' ? 20 : 0"
|
||||||
:show-background="false"
|
:show-background="false"
|
||||||
:central-label="valueFormatter(totalValue)"
|
:central-label="type === 'donut' ? valueFormatter(totalValue) : ''"
|
||||||
:events="{
|
:events="{
|
||||||
[Donut.selectors.segment]: {
|
[Donut.selectors.segment]: {
|
||||||
click: (d: Data, ev: PointerEvent, i: number, elements: HTMLElement[]) => {
|
click: (d: Data, ev: PointerEvent, i: number, elements: HTMLElement[]) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user