Funnel Chart
A series as stages, top to bottom, each as wide as its value and narrowing to the next, in its category's color. Names and colors come from the chart's config; the keyboard moves through the stages, and the tooltip says their values.
Installation
It has its own entry point, @semantic-components/ui/charts, built on d3-scale d3-shape — an optional peer of ui: install it where you use the component.
ts
import { ScChart, ScChartPlot, ScChartFunnel } from '@semantic-components/ui/charts';Usage
import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScChart, type ScChartConfig, ScChartFunnel, ScChartLabels, ScChartLegend, ScChartLegendIndicator, ScChartLegendItem, ScChartPlot, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipPortal, ScChartTooltipProvider, ScChartTooltipValue,} from '@semantic-components/ui/charts';
@Component({ selector: 'app-funnel-chart-usage-demo', imports: [ ScChart, ScChartPlot, ScChartFunnel, ScChartLabels, ScChartTooltip, ScChartTooltipPortal, ScChartTooltipProvider, ScChartLegend, DecimalPipe, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipValue, ScChartLegendItem, ScChartLegendIndicator, ], template: ` <div scChart class="mx-auto aspect-video max-h-72" [config]="config" [data]="data" > <svg scChartPlot categoryKey="stage" aria-label="Visitors at each step to a purchase" > <g scChartFunnel key="visitors"> <g scChartLabels position="inside" class="fill-background" /> </g> </svg> <div scChartTooltipProvider> <ng-template scChartTooltipPortal> <div scChartTooltip #tooltip="scChartTooltip"> @for (item of tooltip.payload(); track item.dataKey) { <div scChartTooltipItem [item]="item"> <span scChartTooltipIndicator></span> <span scChartTooltipName>{{ item.name }}</span> <span scChartTooltipValue>{{ item.value | number }}</span> </div> } </div> </ng-template> </div> <div scChartLegend #legend="scChartLegend" class="flex-wrap"> @for (item of legend.payload(); track item.dataKey) { <div scChartLegendItem [item]="item"> <span scChartLegendIndicator></span> {{ item.name }} </div> } </div> </div> `, host: { class: 'block w-full max-w-xl' }, encapsulation: ViewEncapsulation.None,})export class FunnelChartUsageDemo { private readonly data = [ { stage: 'visit', visitors: 1200 }, { stage: 'signup', visitors: 860 }, { stage: 'trial', visitors: 540 }, { stage: 'paid', visitors: 280 }, ]; private readonly config: ScChartConfig = { visitors: { label: 'Visitors' }, visit: { label: 'Visit', color: 'var(--chart-2)' }, signup: { label: 'Sign up', color: 'var(--chart-3)' }, trial: { label: 'Trial', color: 'var(--chart-4)' }, paid: { label: 'Paid', color: 'var(--chart-5)' }, };}Anatomy
A chart (its rows and config), its plot with the series, and the tooltip and legend you write from their state.
import { ScChart, ScChartPlot, ScChartFunnel, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipPortal, ScChartTooltipProvider, ScChartTooltipValue } from '@semantic-components/ui/charts';<div scChart [config]="…" [data]="…"> <svg scChartPlot categoryKey="…" aria-label="…"> <g scChartFunnel key="…" /> </svg> <div scChartTooltipProvider> <ng-template scChartTooltipPortal> <div scChartTooltip #tooltip="scChartTooltip"> <div scChartTooltipItem [item]="…"> <span scChartTooltipIndicator></span> <span scChartTooltipName>…</span> <span scChartTooltipValue>…</span> </div> </div> </ng-template> </div></div>Accessibility
- The plot is one tab stop, a group named by its aria-label: the arrow keys, Home and End move through its stages; Escape closes the tooltip.
- As the keyboard moves, screen readers hear what the tooltip says, through the CDK's LiveAnnouncer (politely).
- Right to left, with the app following the direction (charts.followDirection), it is mirrored — symmetric, so only its arrows — and ← goes to the next.
- With reduced motion (prefers-reduced-motion), it appears and changes at once.
Examples
Labels
import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScChart, type ScChartConfig, ScChartFunnel, ScChartLabels, ScChartPlot, ScChartTooltip, ScChartTooltipIndicator,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScChart, type ScChartConfig, ScChartFunnel, ScChartLabels, ScChartPlot, ScChartTooltip, ScChartTooltipIndicator,API reference
The series' inputs. The chart, its plot, axes, tooltip and legend are on the Chart page.
| Input | Type | Default | Description |
|---|---|---|---|
key | string (required) | — | each stage's value |
gap | number | 2 | the space between stages, in px |
cornerRadius | number | — | its stages' corners' rounding, in px — unset, the style's (--sc-chart-bar-radius, as the bars'; square in Lyra and Sera) |
isAnimationActive | boolean | true | its stages grow out of their centers when it appears (Recharts' entrance) |
animationBegin | number | 400 | the wait before it starts, in ms |
animationDuration | number | 1500 | how long it lasts, in ms |
animationEasing | ease, ease-in, ease-out, ease-in-out, linear | ease | |
animationMatchBy | 'index' (by position, stretched), 'append' (the first with the first) or (row, index) => key | 'append' | how its shapes before and after a change are paired (Recharts') |
class | string | '' | Merged over its own classes. |