Usage 2.15+
The Chart component is built on top of TanStack Charts and renders an SVG on the server.
TanStack Charts is an optional peer dependency, install it first:
pnpm add @tanstack/charts
yarn add @tanstack/charts
npm install @tanstack/charts
bun add @tanstack/charts
Data
Use the data prop to pass an array of objects, the index prop to set the key used for the x axis and the categories prop to set the series, each with the key of its values and an optional label and color.
<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
['desktop', 'mobile'], when they read well as names.aria-label prop to name the chart for assistive technologies.Type
Use the type prop to change the type of chart. Defaults to line.
donut, each row of data is a slice. The index sets its label and the first key of categories its value.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="donut"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="donut"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Stacked
Use the stacked prop to stack the series on top of each other.
type is area or bar.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="bar"
stacked
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="bar"
stacked
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Curve
Use the curve prop to change the shape of the line between values. Defaults to linear.
type is line or area.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="line"
curve="monotone"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="line"
curve="monotone"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Colors
Use the colors prop to set the color of each series with air-* colors (air-primary, air-primary-success, air-primary-alert, air-primary-warning, air-primary-copilot, air-secondary-no-accent) or any CSS color.
categories order, or the data order with donut. A color set on a category takes precedence. When there are more series than colors, they repeat as lighter tints.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:colors="{
'0': 'air-primary-success',
'1': '#8b5cf6'
}"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:colors="{
'0': 'air-primary-success',
'1': '#8b5cf6'
}"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
--b24ui-chart-* CSS variables, which you can customize in your main.css file.Points
Use the points prop to draw a dot at each value.
type is line.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
points
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
points
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Grid
Use the grid prop to toggle the horizontal grid lines. Defaults to true.
<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:grid="false"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:grid="false"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Axis
Use the x-axis and y-axis props to toggle each axis. Both default to true.
<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:x-axis="false"
:y-axis="false"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:x-axis="false"
:y-axis="false"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Axis labels
Use the x-label and y-label props to display a title along each axis.
<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
x-label="Month"
y-label="Visitors"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
x-label="Month"
y-label="Visitors"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Legend
Use the legend prop to toggle the legend.
donut.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Tooltip
Use the tooltip prop to customize or hide the Tooltip displayed on the focused values. Defaults to true.
<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:tooltip="false"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:tooltip="false"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Thickness
Use the thickness prop to set the width of the ring in pixels. Defaults to 24.
type is donut.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="donut"
:thickness="12"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
type="donut"
:thickness="12"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Size
Use the height prop to set the height of the chart in pixels. Defaults to 300.
aspect-ratio prop to derive the height from the width, or the width prop to set a fixed width.aspect-ratio, the chart rendered on the server is displayed right away.<script setup lang="ts">
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:height="200"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ChartData } from '@bitrix24/b24ui-nuxt'
const data = ref<ChartData[]>([
{
month: 'January',
desktop: 186,
mobile: 80
},
{
month: 'February',
desktop: 305,
mobile: 200
},
{
month: 'March',
desktop: 237,
mobile: 120
},
{
month: 'April',
desktop: 73,
mobile: 190
},
{
month: 'May',
desktop: 209,
mobile: 130
},
{
month: 'June',
desktop: 214,
mobile: 140
}
])
</script>
<template>
<B24Chart
:height="200"
:data="data"
index="month"
:categories="{
'0': {
key: 'desktop',
label: 'Desktop'
},
'1': {
key: 'mobile',
label: 'Mobile'
}
}"
/>
</template>
Examples
With formatted values
Use the format prop to format the values on the y axis and in the tooltip.
With a chart definition
Use the definition prop to pass a complete TanStack Charts definition when the other props are not enough.
--b24ui-chart-* CSS variables. Colors set in the definition are kept.tooltip, it is displayed in place of the tooltip prop.d3-* packages need them installed in your project.With center slot
Use the #center slot to display content in the middle of a donut chart.
With tooltip slot
Use the #tooltip slot to replace the tooltip content. It receives the title, the rows with their label, value and color, and the focused points.
API
Props
Slots
Emits
Theme
export default {
slots: {
root: 'relative w-full text-(length:--ui-font-size-xs) text-muted **:data-reka-popper-content-wrapper:pointer-events-none [--ts-chart-tooltip-background:var(--ui-color-bg-content-inapp)] [--ts-chart-tooltip-color:var(--ui-color-base-8)] [--ts-chart-tooltip-border:1px_solid_var(--ui-color-bg-content-inapp)] [--ts-chart-tooltip-border-radius:var(--ui-border-radius-md)] [--ts-chart-tooltip-shadow:var(--popup-window-box-shadow)] [--ts-chart-tooltip-padding:6px_10px] [--ts-chart-tooltip-font:inherit]',
base: 'opacity-0 in-data-measured:opacity-100 transition-opacity duration-150 [&_.ts-chart]:rounded-(--ui-border-radius-xs) [&_.ts-chart]:outline-0 [&_.ts-chart]:outline-(--ui-color-design-outline-focused-stroke) [&_.ts-chart:focus-visible]:outline-2',
tooltip: 'flex-col items-stretch justify-start gap-[4px] h-auto min-h-0 min-w-32 py-[6px] px-[10px] pointer-events-none',
tooltipTitle: 'font-(--ui-font-weight-medium)',
tooltipRow: 'flex items-center gap-[6px] opacity-75 data-[active=true]:opacity-100',
tooltipIndicator: 'size-2 shrink-0 rounded-full',
tooltipLabel: 'truncate',
tooltipValue: 'ms-auto ps-4 font-(--ui-font-weight-medium) tabular-nums',
center: 'absolute inset-0 flex flex-col items-center justify-center pointer-events-none opacity-0 in-data-measured:opacity-100 transition-opacity duration-150'
},
variants: {
type: {
line: '',
area: '',
bar: '',
donut: ''
}
}
}