FunnelChart
Examples
A horizontal funnel chart built entirely from pure SVG. Each stage bar height is proportional to its value relative to the maximum stage, with trapezoidal connectors showing the transition between stages.
Basic — E-commerce Checkout Funnel
Custom Stage Colors
Warm Palette
Custom Value Format (show only value)
Without Value Labels
Wider Slope Connectors
No Hover Expansion
Events
Empty State
No funnel data available.
Custom Aspect Ratio (4:3)
Many Stages with Long Names
Non-finite stage value — degrades to a zero-height bar, not NaN
"Product View" has no reading this period (NaN). safeValue() treats it
as a zero contribution at maxValue and barHeight alike, so it renders at
the 2px floor with a "0" label — every other stage keeps its correct bar height and label instead
of the NaN reaching maxValue and collapsing the whole funnel. See docs/CHART_INPUT_POLICY.md for the full input-shape table.
Documentation
A horizontal funnel chart built entirely from pure SVG — no external charting library required. Each stage renders as a rectangle whose height is proportional to its value relative to the maximum stage, and consecutive stages are joined by trapezoidal connector polygons that visually convey the drop-off between steps. Supports per-stage color overrides, custom value-and-percentage labels, hover expansion, click/hover events, and full CSS-variable theming.
Usage
<script>
import { FunnelChart } from '@juspay/svelte-ui-components';
const stages = [
{ category: 'Visit', value: 12000 },
{ category: 'Product View', value: 8400 },
{ category: 'Add to Cart', value: 4200 },
{ category: 'Checkout', value: 2100 },
{ category: 'Purchase', value: 980 }
];
</script>
<FunnelChart data={stages} />
Custom Stage Colors
<FunnelChart
data={stages}
stageColors={['#8EE3F6', '#79E2E9', '#82DEE4', '#87E3D3', '#78CDBE']}
connectorColor="#BDFFFB"
/>
Custom Value Format
<FunnelChart data={stages} valueFormat={(value) => value.toLocaleString()} />
Hide Value Labels
<FunnelChart data={stages} showValueLabels={false} />
Wider Connectors
<FunnelChart data={stages} slopeWidth={24} />
Disable Hover Expansion
<FunnelChart data={stages} onHoverExpand={0} />
Events
<FunnelChart
data={stages}
onstageclick={({ index, stage }) => console.log('clicked', stage.category, index)}
onstagehover={(event) => console.log('hovered', event?.stage.category ?? 'none')}
/>
Empty State
<FunnelChart data={[]}>
{#snippet empty()}
<p>No funnel data available.</p>
{/snippet}
</FunnelChart>
Keyboard access
Every stage bar is a focusable role="button" element that mirrors pointer hover on
focus and fires its click event on Enter/Space — the same family-wide keyboard/
tooltip contract shared with BarChart, DualAxisBarChart, PieChart and SankeyChart. See
PieChart's "Keyboard access" and "Synchronized legend recipe" sections
for the full contract.
Invalid values
A stage value that is not a real number (NaN, Infinity, -Infinity)
contributes 0. The stage is still drawn — a funnel stage is a fixed
structural column with its own category label, not a sample that can be
omitted — so it renders at the minimum bar height, and its label and
accessible name read 0 rather than NaN.
Every other stage keeps its correct proportional height.
NaN and Infinity failed differently here before this was enforced, which
is the clearest illustration of why the guard tests Number.isFinite rather
than Number.isNaN:
| Value | Pre-enforcement result |
|---|---|
NaN |
One bar with height="NaN", unpainted; adjacent connector polygons malformed |
Infinity |
Infinity > max is true, so every bar collapsed to the 2px floor |
In both cases the affected bar kept tabindex="0", role="button" and an
accessible name reading literally "Product View: NaN | NaN%". See
Chart Input Policy.
Known edge case.
isEmptytestsvalue === 0, andNaN !== 0, so a dataset in which every stage is non-finite is not treated as empty: it renders all bars at the minimum height instead of theemptysnippet. This is pinned by a test as current behaviour, not endorsed as correct.
Chart name and description
Pass ariaLabel to identify the chart's purpose and ariaDescription for its takeaway,
units or reading instructions. Both belong to the drawing itself, so its points are
reached in a named group. Without an explicit name the chart derives one from its data.
A drawing with no marks is a named image with no point Tab stops.
<FunnelChart
{...chartProps}
ariaLabel="Checkout conversion"
ariaDescription="Values are available on each data control."
/>
The web component uses chart-aria-label and chart-aria-description, or JS properties
chartAriaLabel / chartAriaDescription. These aliases preserve the host's native
ariaLabel / ariaDescription accessors. The description resolves in the same shadow
root as the drawing, with an instance-scoped ID.
<sui-funnel-chart
chart-aria-label="Checkout conversion"
chart-aria-description="Values are available on each data control."
></sui-funnel-chart>
A supplied empty snippet replaces the drawing and keeps its own semantics, including
any actions the consumer puts in it.
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
| data | FunnelStage[] |
Yes | – | Ordered array of { category, value } stage objects. Stages are rendered left-to-right; the tallest bar corresponds to the maximum value. |
| stageColors | string[] |
No | chart palette | Fill color for each stage bar, index-matched to data. Unspecified entries fall back to the shared chart palette. |
| connectorColor | string |
No | light-dark(#BDFFFB, #164e4a) |
Fill color for the trapezoidal connector shapes between consecutive stages. The default resolves per color scheme via CSS light-dark(). |
| slopeWidth | number |
No | 10 |
Horizontal width (SVG units) of each slope connector. Larger values produce steeper visual drops. |
| onHoverExpand | number |
No | 10 |
Extra vertical pixels added symmetrically to the hovered stage bar. Set to 0 to disable. |
| radius | number |
No | 4 |
Corner radius on each stage bar in pixels. |
| maxHeight | number |
No | 420 |
Upper bound (px) on the rendered chart height. |
| minHeight | number |
No | 0 |
Lower bound (px) on the rendered chart height. |
| showValueLabels | boolean |
No | true |
Whether to render the value and percentage label centred inside each stage bar. |
| valueFormat | (value: number, max: number) => string |
No | "<value> | <pct>%" |
Custom formatter for in-bar labels. Receives the stage value and the maximum value across all stages. |
| aspectRatio | number |
No | 16 / 9 |
Width-to-height ratio passed to ChartContainer. Controls the chart's height relative to its container width. |
| ariaLabel | string |
No | Derived from data | Accessible name of the drawing. |
| ariaDescription | string |
No | — | Longer description scoped to this drawing instance. |
| testId | string |
No | – | Value for the data-pw attribute on the chart root element. |
| classes | string |
No | – | CSS class string applied to the chart root element. Useful for scoping CSS-variable overrides. |
| empty | Snippet |
No | – | Content rendered when data is empty or all values are zero. |
| tooltipPortal | boolean |
No | false |
Render the tooltip into the chart's own root (shadow root, or document.body) with position: fixed, clamped to the viewport, so scroll/overflow ancestors never clip it. |
Events
| Event | Type | Description |
|---|---|---|
| onstageclick | (event: { index: number; stage: FunnelStage }) => void |
Fires when the user clicks a stage bar. Receives the index and stage data. |
| onstagehover | (event: { index: number; stage: FunnelStage } | null) => void |
Fires on stage hover and leave. Receives null when the pointer leaves. |
CSS Variables
Override these custom properties to theme the component.
| Variable | Default | CSS Property | Description |
|---|---|---|---|
--chart-background |
transparent |
background | Background color of the chart container. |
--chart-font-family |
inherit |
font-family | Font family for all chart text. |
--chart-transition-duration |
0.2s |
transition | Duration of hover and expand transitions. |
--chart-tooltip-background |
rgba(0,0,0,0.85) |
background | Background of the default tooltip. |
--chart-tooltip-color |
#fff |
color | Text color of the default tooltip. |
--chart-tooltip-font-size |
12px |
font-size | Font size of tooltip content. |
--chart-tooltip-padding |
8px 12px |
padding | Inner padding of the tooltip. |
--chart-tooltip-border-radius |
4px |
border-radius | Border radius of the tooltip. |
--chart-tooltip-shadow |
0 2px 8px rgba(0,0,0,0.2) |
box-shadow | Shadow on the tooltip. |
--chart-empty-padding |
32px 24px |
padding | Padding around the empty state content. |
--chart-axis-label-color |
light-dark(#333, #e5e7eb) |
outline | Focus outline colour on a keyboard-focused stage bar. |
--chart-empty-color |
#9ca3af |
color | Text color of the empty state. |
--funnel-chart-connector-color |
light-dark(#BDFFFB, #164e4a) |
fill | Default fill for trapezoidal connector shapes. |
--funnel-chart-label-color |
#666 |
fill | Color of the category labels above each stage bar. |
--funnel-chart-label-font-size |
11px |
font-size | Font size of category labels. |
--funnel-chart-value-color |
auto (contrast) | fill | Overrides the automatic per-stage contrast color of the value/percentage labels inside bars. |
--funnel-chart-value-font-size |
11px |
font-size | Font size of in-bar value labels. |
--funnel-chart-bar-hover-opacity |
1 |
opacity | Opacity of the hovered stage bar. |
--funnel-chart-bar-dimmed-opacity |
0.35 |
opacity | Opacity of non-hovered bars when another stage is hovered. |
--chart-transition-easing |
ease |
transition | Easing curve of hover and expand transitions. Falls back through --motion-easing. |
Dark mode
Chart colors resolve through CSS light-dark(). Set color-scheme on the chart's ancestor (or :root) so the correct side is chosen:
:root {
color-scheme: light;
}
[data-theme='dark'] {
color-scheme: dark;
}
Every --chart-* / component token can still be overridden per theme; overrides always win over the built-in light-dark() fallbacks.
Type Reference
type FunnelStage = {
value: number;
category: string;
};
Web Component
sui-funnel-chart is registered by the web-component bundle. FunnelChart
portals its tooltip via tooltipPortal, and a portalled node keeps its
shadow-scoped styles because ChartTooltip resolves the portal destination
from the node's own root (getRootNode()) instead of hardcoding
document.body.
<script type="module" src="@juspay/svelte-ui-components/wc"></script>
<sui-funnel-chart show-value-labels connector-color="#BDFFFB" slope-width="24"></sui-funnel-chart>
<script>
const chart = document.querySelector('sui-funnel-chart');
chart.data = [
{ category: 'Visit', value: 12000 },
{ category: 'Product View', value: 8400 },
{ category: 'Add to Cart', value: 4200 },
{ category: 'Checkout', value: 2100 },
{ category: 'Purchase', value: 980 }
];
chart.valueFormat = (value) => value.toLocaleString();
chart.onstageclick = ({ index, stage }) => console.log('clicked', stage.category, index);
</script>
Scalar props are kebab-case attributes, coerced to their declared type:
connector-color, slope-width, on-hover-expand, show-value-labels,
aspect-ratio, max-height, min-height, radius, tooltip-portal, test-id,
classes. Booleans are presence-based, so show-value-labels is on by default and
adding show-value-labels="false" does not turn it off — remove the attribute
instead.
Everything else is a JS property, because arrays, objects and functions cannot cross the HTML-attribute boundary:
const chart = document.querySelector('sui-funnel-chart');
chart.data = stages;
chart.stageColors = ['#8EE3F6', '#79E2E9', '#82DEE4', '#87E3D3', '#78CDBE'];
chart.valueFormat = (value, max) => `${value} of ${max}`;
chart.onstageclick = ({ index, stage }) => console.log(index, stage.category);
chart.onstagehover = (event) => console.log(event?.stage.category ?? 'none');
Assigning onstageclick and onstagehover as properties, as above, still works
exactly as shown. Each also dispatches a same-named DOM event with detail set to
the same argument the property callback receives (null for onstagehover when
the pointer leaves a stage), so addEventListener works too:
chart.addEventListener('stageclick', (e) => console.log(e.detail.index, e.detail.stage.category));
chart.addEventListener('stagehover', (e) => console.log(e.detail?.stage.category ?? 'none'));
Slots
| Slot | Replaces |
|---|---|
empty |
The empty state shown when data is empty or every stage's value is zero. |
Supply it only when you mean to: with no empty slot the component falls through
to its own chart frame, and an empty slot would replace that frame with a blank box.
Svelte-only: unlike
SankeyChartandPieChart,FunnelCharthas notooltipSnippet(or any other tooltip-customizing prop) — it always rendersChartTooltip's built-in markup. There is no parameterized snippet here for a<slot>to drop the arguments of, and nothing for a Web Component consumer to lose by using<sui-funnel-chart>instead of the Svelte component.