Dashral Pro is hereSee pricing

Dashral

Combo ChartNew

Bars and lines on one chart, such as revenue as bars and margin as a line, with a second axis on the right for values of another kind. Plain SVG.

$ pnpm dlx shadcn@latest add @dashral/combo-chart
  • Revenue
  • Margin

Installation

$ pnpm dlx shadcn@latest add @dashral/combo-chart

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Or by its full URL: https://dashral.com/r/combo-chart.json

When to use

  • Two related measures over the same periods, one as bars and one as a line: revenue and margin, orders and a target.

When not to use

  • One kind of value only: Bar Chart or Line Chart.
  • Parts of a whole: Donut Chart.

Usage

Your rows, the column along the bottom (index), and each series as bars or a line; a line of another kind of value takes the right axis.

example.tsx
import { ComboChart } from "@/components/dashral/combo-chart"

const data = [
  { month: "Aug", revenue: 52400, margin: 0.34 },
  { month: "Sep", revenue: 58300, margin: 0.36 },
  { month: "Oct", revenue: 61700, margin: 0.35 },
]

export default function RevenueAndMargin() {
  return (
    <ComboChart
      data={data}
      index="month"
      series={[
        { key: "revenue", label: "Revenue" },
        { key: "margin", label: "Margin", type: "line", axis: "right" },
      ]}
      rightFormatOptions={{ style: "percent" }}
      aria-label="Revenue and margin by month"
    />
  )
}

Using the npm package? Import from @dashral/ui/components/combo-chart instead, here and in the examples; the rest is the same.

Examples

Orders against a target

A dashed line on the same axis as the bars, so a week above the goal reads at a glance.

  • Orders
  • Target

Revenue card

Two bar series side by side and a margin line; the range moves every mark and counts the total to its new sum.

Revenue

$308.2K

  • Revenue
  • Refunds
  • Margin

API reference

ComboChart

Also takes every prop of <div>(opens in a new tab).

PropTypeDefault
dataRecord<string, string | number>[]

The rows, in order along the x axis. Required.

—
indexstring

The key for the x axis: a label, or a timestamp or ISO date with timeFormat. Required.

—
series{ key, label, type?, axis?, color?, dashed? }[]

What to draw, in order. type: "bar" (the default) or "line"; axis: "right" reads a series against a second axis on the right (on the left in right-to-left). dashed is for lines. Required.

—
rightFormatOptionsIntl.NumberFormatOptions

How the right axis' values are written, e.g. { style: "percent" }.

—
alignZeroboolean

When the chart starts at zero, both axes put their zero on the same grid line, so a negative value on one (a negative margin) never floats above the other's baseline. false lets each axis fit its own values.

true
curve"smooth" | "linear" | "step"

How the lines bend; smooth never bends past a value it didn't have.

"smooth"
radiusnumber

Corner radius of a bar's end; the end on the axis stays square.

4
heightnumber

In pixels, axes included; the width follows the container.

260
formatOptionsIntl.NumberFormatOptions

How values are written in the tooltip, e.g. { style: "currency", currency: "USD" }; the axis writes them compactly.

—
timeFormatIntl.DateTimeFormatOptions

Reads the index as dates and writes them like this.

—
showLegendbooleanmore than one series
showGridboolean

Dashed lines at the axis values.

true
showYAxisboolean

The values along the left.

true
localestringthe LocaleProvider's
aria-labelstring

What the chart shows, e.g. “Revenue by month”.

"Trend from … to …"
classNames{ legend, tooltip }—

Keyboard

KeysAction
TabFocus the chart
←or→Read the previous or next point
HomeorEndThe first or last point
EscStop reading

Accessibility

  • A group named by your label (by default, how the first series went); the point you move to with the arrow keys is read out with every series' value.
  • The x axis runs left to right in every language, as on most charts; the legend and tooltip follow the page's direction.
  • The tooltip lists every series by name, so nothing depends on telling colors apart.
  • Values on the right axis are written with rightFormatOptions, in the tooltip and read out.

Motion

  • The bars grow up from the axis and the lines draw in from the left when it first shows; new data moves both to their new places. Instant with reduced motion.