Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

A mixed bar chart for React

Horizontal bars, one per browser, each filled with that browser's own color. Names come from the chart config.

Horizontal bars, one per browser, each filled with that browser's color. The names come from the chart config. The value axis is hidden.

Use it when each category should be recognized by its own color, not one shared series color. A long ranking with more columns belongs in a Table. In React, Base UI maps each browser color to a variable. The row order is the bar order.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Anatomy

Chart anatomy: container, grid, axis, bar, tooltip, legend

Usage

<div className="w-full max-w-xl rounded-md border bg-background p-4">
  <ChartContainer config={chartConfig}>
    <BarChart
      accessibilityLayer
      data={chartData}
      layout="vertical"
      margin={{
        left: 0,
      }}
    >
      <YAxis
        axisLine={false}
        dataKey="browser"
        tickFormatter={formatBrowser}
        tickLine={false}
        tickMargin={10}
        type="category"
      />
      <XAxis dataKey="visitors" hide type="number" />
      <ChartTooltip
        content={<ChartTooltipContent hideLabel />}
        cursor={false}
      />
      <Bar dataKey="visitors" radius={5} />
    </BarChart>
  </ChartContainer>
</div>

FAQ

How does each bar get a different color?

Each row sets fill to a variable such as var(--color-chrome). config maps chrome, safari, firefox, edge, and other to --chart-1 through --chart-5. Bar sets dataKey to visitors and radius to 5, and leaves fill to the row.

What makes the bars horizontal?

BarChart sets layout to vertical and margin to { left: 0 }. YAxis is type category with dataKey browser. XAxis is type number with dataKey visitors and hide.

How do the ticks get names like Chrome?

YAxis sets tickFormatter to formatBrowser, which returns chartConfig[value].label, or the raw key when that label is missing. axisLine and tickLine are false, and tickMargin is 10.

What does the tooltip show?

ChartTooltipContent sets hideLabel, and cursor is false. The name comes from the browser key in config, and the value is visitors. config also labels visitors as Visitors.

Can I reach the bars from the keyboard?

Yes. BarChart sets accessibilityLayer. The browser labels in config are the same strings formatBrowser prints on the axis.

What order are the bars in?

The rows run Chrome 275, Safari 200, Firefox 187, Edge 173, and Other 90. With layout vertical, that array order is the category order down the chart.

API Reference

Chart

Sets config={chartConfig} and hideLabel. The rest is on the Chart page.