Bar Chart

Implement vertical, horizontal, grouped, and stacked bar charts in your Nuxt application.

The BarChart component provides a flexible and customizable way to visualize categorical data as vertical or horizontal bars, supporting grouped, stacked, and combined layouts.

Basic Usage

Bar Chart

Stacked Horizontal Bar Chart

Grouped Bar Chart

Bar Chart

Stacked Bar Chart

Bar Chart

Props

PropTypeDefaultDescription
dataT[]RequiredArray of data points for the chart. Each element represents a data point.
heightnumberRequiredHeight of the chart in pixels.
categoriesRecord<string, BulletLegendItemInterface>RequiredSeries configuration: name and color for each data key.
stackedbooleanfalseIf true, displays stacked bars instead of grouped bars.
stackAndGroupedbooleanfalseIf true, enables both stacked and grouped bars.
yAxis(keyof T)[]RequiredArray of property keys from the data object to display on the y-axis.
xAxiskeyof TundefinedThe data key for the x-axis (required for stackAndGrouped or with valueLabel).
xLabelstringundefinedOptional label for the x-axis.
yLabelstringundefinedOptional label for the y-axis.
padding{ top: number; right: number; bottom: number; left: number; }undefinedOptional padding for the chart (top, right, bottom, left).
xFormatteraxisFormatterundefinedFormats x-axis labels. (tick, i, ticks) => string where tick can be a number or Date.
yFormatteraxisFormatterundefinedFormats y-axis labels. (tick, i, ticks) => string where tick can be a number or Date.
xNumTicksnumberundefinedDesired number of ticks on the x-axis.
yNumTicksnumberundefinedDesired number of ticks on the y-axis.
xExplicitTicks`(numberstringDate)`
minMaxTicksOnlybooleanfalseIf true, only show first and last ticks on the x-axis.
groupPaddingnumberundefinedPadding between groups of bars in pixels.
barPaddingnumber0Fractional padding between bars (0-1).
radiusboolean | number2Rounded corners for top bars (boolean or pixel value).
hideLegendbooleanfalseIf true, hides the chart legend.
hideTooltipbooleanfalseIf true, hides the chart tooltip.
legendPositionLegendPositionundefinedPosition of the legend (see LegendPosition).
legendStylestring | Record<string, string>undefinedCustom CSS style for the legend container.
orientationOrientation'vertical'Orientation of the bars (vertical or horizontal).
xDomainLinebooleanfalseShow domain (axis) line on the x-axis.
yDomainLinebooleanfalseShow domain (axis) line on the y-axis.
xTickLinebooleanfalseShow tick lines on the x-axis.
yTickLinebooleanfalseShow tick lines on the y-axis.
xGridLinebooleanfalseShow grid lines on the x-axis.
yGridLinebooleanfalseShow grid lines on the y-axis.
hideXAxisbooleanfalseIf true, hides the x-axis.
hideYAxisbooleanfalseIf true, hides the y-axis.
xAxisConfigAxisConfigundefinedAxis configuration for customizing the appearance of the x-axis.
yAxisConfigAxisConfigundefinedAxis configuration for customizing the appearance of the y-axis.
stackedGroupedSpacingnumberundefinedSpacing between stacked and grouped bars (only for stackAndGrouped).
valueLabelValueLabelundefinedConfiguration for value label display (see ValueLabel).

Data Format

The data should be an array of objects where each object represents a data point:

types.ts
interface ChartData {
  [key: string]: string | number
}

Categories Format

Categories define the visual appearance and metadata for each data series:

types.ts
interface Category {
  name: string
  color: string
}

interface Categories {
  [key: string]: Category
}