suiss/ui ยท Chart
Bar Chart
Ten bar charts for comparing values across categories, from a single series to stacked, grouped, horizontal, negative and range bars.
Bar Chart is an open-source chart from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Bar charts compare a value across categories or periods. Start with the default for one series, group or stack bars when there are two, turn them horizontal for long category names, and use the negative or range variants when a value can drop below zero or spans a low and a high.
Each chart is built on the Chart and Card components.
Every variant below is its own registry item, so you can add only the ones you need. Each one renders the same design on React, React Native, SwiftUI and Jetpack Compose.
Default
A single series of rounded vertical bars, one per month.
The plain bar chart: one series of rounded vertical bars with a month axis and a tooltip. Start from it whenever you compare a handful of discrete values.
Replace chartData, point each dataKey at your fields and set the label and color in chartConfig. Use radius for corner rounding and maxBarSize to cap bar width on wide containers. Focus the chart and use the arrow keys to move the tooltip between bars.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Web preview
The baseline bar chart inside a Card: one rounded bar per month, a month axis, a dashed horizontal grid and a tooltip without a label. Start here and add series, stacking or labels as needed.
Replace chartData with your records and change each dataKey to match your fields. Set the bar color with fill and the series label in chartConfig. The component takes no props.
Installation
-
Target iOS 17 or later.
-
Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Active
A week of step counts where clicking a bar selects it, dims the others and updates the header.
A week of step counts where one bar is selected at a time: the chosen day stays solid, the rest dim, and the header shows its value. Use it when a bar chart doubles as a picker for the detail shown above it.
Replace chartData and rename steps in the data, the Bar and chartConfig. The selected state sets the first selected bar, and the opacity of the dimmed bars sets the contrast. There is no tooltip: keyboard users move between bars with the arrow keys and select with Return or Space, and the header value is announced through a live region.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Seven bars, one per day, with the selected bar at full opacity and the others dimmed. The BarChart reports the touched bar through onActiveIndexChange, which updates local state and the header. The header is a live region, so screen readers announce the new step count. The bars set isAnimationActive={false} and draw without the enter animation.
Replace chartData with your daily values and update the day and steps keys to match. The initial selection is set by the useState default. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Horizontal
Horizontal bars with category names on the left and a distinct color for each category.
Horizontal bars with category names down the left and a different color per category. Choose it over vertical bars when labels are long or when you are ranking items.
Give each record a category key, a value and a fill that points at its color variable, and add a label and color for each key to chartConfig. The left axis reads its text from those labels and sizes itself to the longest one, and barSize sets the bar thickness. Focus the chart and use the arrow keys to move the tooltip between bars.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A BarChart with layout="vertical", so categories run down a YAxis and bars extend to the right, which leaves room for longer names. Each bar gets its color from chartConfig through a Cell, and the axis labels come from the same config.
Replace chartData with your categories and values, and add a matching entry with a label and color to chartConfig for each category. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Hourly
Twenty-four thin bars of screen time per hour, with a dashed line marking the hourly average.
A screen-time card with 24 thin hourly bars, a total in the header and a dashed line at the hourly average. Use it for any day-at-a-glance metric with many small periods.
Replace the 24 values in chartData; the total and the average line are computed from them. Change the axis ticks to label other hours, and update the minute unit in the axis, tooltip and header if you measure something else. With 24 narrow bars the tooltip is the most reliable readout; focus the chart and use the arrow keys to step through the hours.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Thin bars show minutes for each hour of the day, with ticks every six hours and a value axis in minutes on the right. A ReferenceLine marks the hourly average, and the header shows the day's total in hours and minutes. The tooltip formats the hour and the minutes.
Replace the 24 values in chartData with your hourly minutes; the total and average are calculated from it. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Interactive
A screen-time report with stacked category bars, a week and day toggle, selectable days and a most-used apps list.
A full screen-time report: stacked category bars per day, a Week and Day toggle, selectable days, per-category totals and a most-used apps list that all update together. Use it as a reference for building a drill-down dashboard on top of a bar chart.
Replace USAGE with your per-day category totals and APPS with your item breakdown, and rename the categories in CATEGORIES and chartConfig. The hourly Day view is generated from the daily totals for the demo, and the comparison line is a fixed string until a day is selected. Click, tap or press Return on a bar to select a day, and select it again to clear it; taps that move like a scroll are ignored. Day view shows Sunday when no day is selected, and the header announces changes through a live region.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Bars stack social, productivity and entertainment time. A ToggleGroup switches between a weekly view and an hourly view of one day. In the week view, touching a bar selects that day through onActiveIndexChange, dims the other days and updates the headline, comparison text, category totals and the most used apps list below. A dashed line marks the weekly average. The bars set isAnimationActive={false}, so they draw without the enter animation and switch views instantly.
Replace USAGE with daily minutes per category and APPS with your apps and their share of each category. The hourly view is generated from PROFILE, so swap hourly() for real data. The component takes no props.
Installation
The CLI also adds what it builds on: Card, Chart, Text, Toggle Group.
Follow the manual steps under Default and copy this variant's source instead.
Usage
Labeled
A single bar series with each value printed above its bar and no grid lines.
A single bar series with each value printed above its bar and no grid lines. Use it when exact numbers matter and there are few enough bars for the labels to fit.
Replace chartData, point each dataKey at your fields and set the label and color in chartConfig. The position prop on LabelList moves the labels, for example inside the bar; raise the chart's top margin if larger labels get clipped. Focus the chart and use the arrow keys to move the tooltip between bars.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
One rounded bar per month with a LabelList placed at the top of each bar, so values are readable without touching the chart. There is no grid; a month axis and a tooltip remain.
Replace chartData with your records and change each dataKey to match your fields. Change position and offset on the LabelList to move the labels. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Multiple
Two series drawn as grouped bars side by side for each month.
Two series drawn as grouped bars side by side for each month. Pick it over the stacked variant when readers need to compare the series directly rather than see their total.
Replace chartData and rename the series keys in the data, the two Bar elements and chartConfig, and add a Bar for another series. barGap sets the space between bars in a group. Beyond three series or a dozen categories, consider stacked bars or a line chart. Focus the chart and use the arrow keys to move the tooltip between months.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Two Bar series sit next to each other in every month, separated by a small barGap. The tooltip lists both values with a dashed indicator.
Replace chartData with your records and change each dataKey to match your fields. Add a Bar and a chartConfig entry for each extra series. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Negative
Monthly cash flow bars that turn green above zero and red below it, with a zero baseline.
Monthly cash flow where bars rise green above a zero line and drop red below it. Use it for any value that can be negative, such as profit, net change or deltas against a target.
Replace chartData and rename flow in the data, the bar and chartConfig. Each Cell picks its color from the sign of the value, so change the two colors there, and interval on the axis sets how many month labels show. Because colors are set per bar, the tooltip has no swatch, so keep the zero line to show the direction without color. Focus the chart and use the arrow keys to move the tooltip between months.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
One bar per month, colored per value through a Cell: green when the flow is positive and red when it is negative. A ReferenceLine at zero anchors the bars, and the month axis shows every other label.
Replace chartData with your months and signed flow values. Change the colors in the Cell fill expression. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Range
A weather forecast where each horizontal pill spans the day's low and high on a shared gradient scale.
A weather-app forecast where each horizontal pill spans a day's low to high temperature against a shared scale, with a colored gradient fill and the high on the right. Use floating range bars like these whenever each item has a minimum and a maximum.
Give each record a label, a low and a high; the chart derives the two-value range from them. Set the hidden value axis domain to cover your full range so pills line up across rows, and edit the gradient stops in the defs block to change the colors. The gradient runs across each pill, not the whole scale. Only the high is printed beside the bars; the low is in the tooltip.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A horizontal BarChart whose range values are [low, high] pairs, so each bar floats between the two temperatures. Bars use a teal-to-orange gradient over a full-width track, day names sit on the left and highs on the right. The tooltip shows the range in degrees.
Replace chartData with your days and low and high values; the range pair is derived from them. Adjust the hidden XAxis domain to fit your temperature range. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Stacked
Two series stacked into one bar per month, with a legend below the plot.
Two series stacked into one bar per month, with a legend under the plot. Use it when the total per month matters as well as how each series contributes to it.
Replace chartData and rename the series keys in the data, both Bar elements and chartConfig; the legend reads labels and colors from the config. Every bar in the stack needs the same stackId, and the first one sits at the bottom. If you add a series, move the rounded top corners via radius to the top bar. Focus the chart and use the arrow keys to move the tooltip between months.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Desktop and mobile bars share a stackId, so each column shows both parts and their total. Only the outer corners are rounded, and a legend below the plot names both series.
Replace chartData with your records and change each dataKey to match your fields. Add, rename or recolor series in chartConfig and add a Bar for each. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.