Skip to content
Calm motion: animations on this site only fade, with no movement

Bar chart ​

Bars for categories, side by side or stacked

Compares amounts across categories, for example plays by month. Use one series for one amount, more series for parts that you compare. For a trend over time, use the line chart. For parts of one whole, use the donut chart.

Basic
PlaysThousands, by month
Plays by month
CategoryWebApp
Jun12k18k
Jul15k22k
Aug11k26k
Sep18k31k
Oct21k29k
Nov24k35k
  • Web
  • App
  • data is a list of rows. x names the field with the category, and each item of series ({ key, label, color }) names a field with a number.
  • Bars grow from zero, so a negative value goes below the zero line. stacked puts the series on each other: the positive parts go up and the negative parts go down.
  • horizontal turns the chart: the categories go down the start edge and the bars grow to the side. Use it for long category names.
  • The value axis has round steps (1, 2, 2.5, or 5 × a power of ten) that cover the data. A hover on a bar shows its category, series, and value.
  • Colors go through the chart colors in order, in the same order as the legend of BlessChart. Set color on a series to a token name or any CSS color.
  • Put the chart in a BlessChart with height="auto" for a title, a description, and a legend.
  • The chart draws at the width of its container, measured in the browser, and height sets the height (default 280).
  • The chart is hidden from screen readers, and a table of the values is read in its place. label names the table. format sets the text of a value. Change the name of the first column with labels or a label pack: category.
  • The chart is drawn as plain SVG. There is no chart library to install.

Usage ​

ts
import { BlessBarChart, type BlessChartSeries } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
data*BlessChartRow[]—one row for each category
x*string—the field of a row that names its category
series*BlessChartSeries[]—one bar for each series in each category
horizontalboolean—bars that grow to the side, with the categories down the start edge
stackedboolean—the series on top of each other, not side by side
heightnumber280
format((v: number) => string)—text for one value, for example `(v) => v + " ms"`
labelstring"Chart"names the chart and its table for screen readers
labelsPartial<{ category: string; }>—

Released under the MIT License. Character names and artwork belong to their owners.