Bar

Alpha

A bar chart compares quantities across categories with rectangular bars.

Preview ​

Installation ​

npx sigma-ui@latest add chart-bar

Setup ​

Charts need the Unovis color variables from the Charts installation.

Usage ​

vue
<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

PropType Default
datarequired

The source data, in which each entry is a dictionary.

T[]-
categoriesrequired

Select the categories from your data. Used to populate the legend and toolip.

Extract<keyof T, string>[]-
indexrequired

Sets the key to map the data to the axis.

Extract<keyof T, string>-
colors

Change the default colors.

string[]-
config

Config-driven series colors. Keys match category names and set --color-<key> and --chart-N.

ChartConfig-
margin

Margin of each the container

Spacing{ top: 0, bottom: 0, left: 0, right: 0 }
filterOpacity

Change the opacity of the non-selected field

number0.2
xFormatter

Function to format X label

((tick: number | Date, i: number, ticks: number[] | Date[]) => string)-
yFormatter

Function to format Y label

((tick: number | Date, i: number, ticks: number[] | Date[]) => string)-
showXAxis

Controls the visibility of the X axis.

booleantrue
showYAxis

Controls the visibility of the Y axis.

booleantrue
showTooltip

Controls the visibility of tooltip.

booleantrue
showLegend

Controls the visibility of legend.

booleantrue
showGridLine

Controls the visibility of gridline.

booleantrue
customTooltip

Render custom tooltip component.

Component-
type

Change the type of the chart

"stacked" | "grouped""grouped"
roundedCorners

Rounded bar corners

number0

Events

EventPayload
legendItemClick

Emitted when a legend item is clicked, with the item and its index.

[d: BulletLegendItemInterface, i: number]

Slots

SlotScope
default

The 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.

KeyDescription
TabMoves focus past the chart. Bars are not individually focusable.
Edit this page on GitHub