Skip to content
InsightCharts

Search

Search guides and components

Chart tabs

One chart frame with a segmented control that switches between several views of the same data, morphing between views that share a chart type.

Use when
The same entities under two to five measures or scalings where each view changes the reading: total / per capita / change, absolute / share, linear / log. Give the frame a plain label as its title. Each view's subtitle names its measure.
Avoid when
Hiding the most important view behind a tab (show it first, or show both with small multiple grid); unrelated charts (give each its own figure); more than five views.

Preview

CO2 emissions of six large emitters, 2023

CO2 emissions from fossil fuels, billion tonnes, 2023

Source: Global Carbon Budget 2024 · Rounded, approximate figures for illustration

Composition

Built from

The pieces chart tabs renders or expects in its slots.

Atoms

2

Compares a value across categories with bars from a zero baseline.

Shows how one or more values change over time or another ordered dimension.

Used in

No template lists chart tabs in its composes. It still fits any slot that takes a component.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/chart-tabs

The CLI copies the source into your project and needs the @insightcharts registry in components.json; see installation. With the package, import it by name:

import { ChartTabs } from "insightcharts";

Examples

Tabs beside the title, a different chart per view

Solar supplied 11.1% of EU electricity in 2024

Solar and coal share of EU electricity generation, 2019 to 2024

Source: Ember · Figures are approximate, for illustration

Props

PropTypeDefaultDescription
chartInsightSpecThe base chart spec every view starts from: { type, data, ... }.
viewsrequired{ label, id?, props?, chart? }[]Two to five views. props are merged over chart; or give a view its own complete chart slot.
defaultViewstring | numberThe view shown first: an id, a label or an index.
viewstring | numberControlled active view.
onViewChange(id, index) => voidCalled when the reader switches view.
tabsLabelstring"Chart view"Accessible name of the tab list.
tabsPosition"right" | "below""right"Tabs beside the title or under it. Under 560px they always go underneath.
titlestringA plain label or fact that is true of every view.
subtitlestringWhat the views share; each view's own subtitle names its measure.
sourcestringShown under the chart as "Source: ...".
notestringMethod note or caveat.
childrenReactNodeExtra content under the chart.
themeThemeInputTheme override, passed on to the chart.
mode"auto" | "system" | "light" | "dark""auto"Colour mode.