Bar
AlphaA bar chart compares quantities across categories with rectangular bars.
Preview
Installation
npx sigma-ui@latest add chart-barSetup
Charts need the Unovis color variables from the Charts installation.
Usage
<script setup lang="ts">
import { BarChart } from '@/components/ui/chart-bar';
const data = [
{ name: 'Jan', total: 1200 },
{ name: 'Feb', total: 1600 },
];
</script>
<template>
<BarChart
:data="data"
index="name"
:categories="['total']"
/>
</template>Set type to stacked to stack the series. roundedCorners rounds the bar corners, in pixels.
Examples
Stacked
Rounded
Custom tooltip
Pass a component to customTooltip. It receives title and data. See the Charts page for the prop shape.
API Reference
BarChart
Props
| Prop | Type | Default |
|---|---|---|
datarequiredThe source data, in which each entry is a dictionary. | T[] | - |
categoriesrequiredSelect the categories from your data. Used to populate the legend and toolip. | Extract<keyof T, string>[] | - |
indexrequiredSets the key to map the data to the axis. | Extract<keyof T, string> | - |
colorsChange the default colors. | string[] | - |
configConfig-driven series colors. Keys match category names and set --color-<key> and --chart-N. | ChartConfig | - |
marginMargin of each the container | Spacing | { top: 0, bottom: 0, left: 0, right: 0 } |
filterOpacityChange the opacity of the non-selected field | number | 0.2 |
xFormatterFunction to format X label | ((tick: number | Date, i: number, ticks: number[] | Date[]) => string) | - |
yFormatterFunction to format Y label | ((tick: number | Date, i: number, ticks: number[] | Date[]) => string) | - |
showXAxisControls the visibility of the X axis. | boolean | true |
showYAxisControls the visibility of the Y axis. | boolean | true |
showTooltipControls the visibility of tooltip. | boolean | true |
showLegendControls the visibility of legend. | boolean | true |
showGridLineControls the visibility of gridline. | boolean | true |
customTooltipRender custom tooltip component. | Component | - |
typeChange the type of the chart | "stacked" | "grouped" | "grouped" |
roundedCornersRounded bar corners | number | 0 |
Events
| Event | Payload |
|---|---|
legendItemClickEmitted when a legend item is clicked, with the item and its index. | [d: BulletLegendItemInterface, i: number] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
The chart is an SVG graphic. Hovering a bar shows a tooltip. Give the surrounding section a heading or caption that states what the chart measures, and provide the same numbers in a table when the exact values matter.
| Key | Description |
|---|---|
| Tab | Moves focus past the chart. Bars are not individually focusable. |