Create

General

Chart

Experimental
Copy page View as Markdown Open in ChatGPT Open in Claude

Beautiful charts built with Apache ECharts. Copy and paste into your apps.

Usage#

app.component.ts
import { WdsChartComponent } from '@wds/angular/chart';

Examples#

Default#

Bar chart (the default type). config, data and the formatters are properties (in HTML set them from a script); series and x-key are attributes. Each series gets its name and color from config. The chart needs the echarts package: pnpm add echarts.

Horizontal#

horizontal turns the bars sideways, grid="none" hides the grid lines and value-labels writes the values next to the bars. With one series there is no legend: the chart label names it.

Stacked#

stacked puts the series on top of each other. tooltip sets the series indicator in the tooltip: dot (default), line or dashed.

Percentage#

stack-offset="expand" shows each stack as shares of 100%. y-axis shows the value axis labels.

Line#

type="line". curve is linear, smooth or step; value-labels puts the last value at the end of each line.

Area#

type="area" with gradient fills and a stack.

Series options#

Instead of a key, a series can be a WdsChartSeries object with its own curve, showSymbol, color, stack or fillOpacity.

Bars and a line#

A series with type: 'line' is drawn as a line on a bar chart.

Donut#

In pie and radial the categories are the rows (x-key) and the value is the first series; config names and colors the categories (or fill in a row). inner-radius makes a donut, pad-angle separates the slices, and center-value with center-label fill the middle.

Radar#

type="radar": one polygon per series, radar-shape="circle" for a round grid.

Radial#

type="radial": one ring per category; a full ring is the largest value. hide-track hides the ring background.

Custom colors#

By default series get the --wds-chart-1…5 tokens in a fixed order, so a series keeps its color when another one is hidden. color in config sets any CSS color, and theme sets separate colors for light and dark backgrounds.

Interactive#

zoom adds zooming (wheel, gesture and a slider), wds-chart-click returns the clicked point, and show-table shows the data as a table. Changing type redraws the chart with the same data.

AreaLineBarTable

Clicked: none

API References#

wds-chart#

A chart built on Apache ECharts: bar, line, area, pie, radar, radial. Series colors are the --wds-chart-1…5 tokens (in a fixed order); config sets names and colors. The legend toggles series, the tooltip shows every series at a point, and the data is also in a table (always for screen readers, on screen with show-table). Requires the echarts package (an optional dependency of @wds/core, loaded only by @wds/core/chart).

Attributes

AttributeTypeDefaultDescription
typeWdsChartType'bar'Chart type.
seriesWdsChartSeriesInput[]Series keys (series="desktop, mobile") or full WdsChartSeries objects. In pie/radial the first series is the value.
x-key.xKeystring''Key of the category in a row (the X axis, the slice name).
stackedbooleanfalseStacks bars or areas.
stack-offset.stackOffsetWdsChartStackOffset'none'expand: the stack as a percentage share (0–100%).
horizontalbooleanfalseHorizontal bars.
gridWdsChartGrid'horizontal'Grid lines.
hide-x-axis.hideXAxisbooleanfalseHides the category axis labels.
y-axis.yAxisbooleanfalseShows the value axis labels.
curveWdsChartCurve'linear'Line shape of line/area (a series can override it).
gradientbooleanfalseA gradient instead of a solid area fill.
value-labels.valueLabelsbooleanfalseValues next to bars, at the end of lines and next to slices.
legendWdsChartLegend'auto'Legend: auto (from 2 series), top, bottom, none.
tooltipWdsChartTooltipIndicator | 'none''dot'Series indicator in the tooltip; none turns the tooltip off.
inner-radius.innerRadiusstring | undefinedInner radius of pie (donut) and radial, e.g. 60%.
outer-radius.outerRadiusstring | undefinedOuter radius of pie and radial.
start-angle.startAnglenumber | undefinedStart angle of pie/radial in degrees (default 90, i.e. 12 o'clock).
end-angle.endAnglenumber | undefinedEnd angle of pie/radial in degrees.
pad-angle.padAnglenumber0Gap between pie slices in degrees.
center-value.centerValuestring''Large value in the center of a donut or radial chart.
center-label.centerLabelstring''Caption under the center value.
radar-shape.radarShape'polygon' | 'circle''polygon'Shape of the radar grid.
hide-track.hideTrackbooleanfalseHides the background track of radial rings.
zoombooleanfalseAxis zoom (wheel or gesture, and a slider under the chart).
disable-animation.disableAnimationbooleanfalseTurns animation off (it is also off with prefers-reduced-motion).
renderer'svg' | 'canvas''svg'svg (sharp text, print) or canvas (many points).
labelstring''Chart name for screen readers and the table caption.
show-table.showTablebooleanfalseShows the data table under the chart.
localestring | undefinedLocale for number formatting (default: the document language).

Properties

PropertyDescription
configWdsChartConfigNames and colors of the series (or of the categories in pie/radial).
dataWdsChartDatum[]Data rows.
xFormatter(value: string) => string | undefinedCategory label (axis, tooltip, table).
yFormatter(value: number) => string | undefinedValue axis label.
valueFormatter(value: number, key: string) => string | undefinedValue in the tooltip, labels and table.
optionRecord<string, unknown> | undefinedExtra ECharts options merged over the generated ones (e.g. markLine).

Events

EventDescription
wds-chart-clickCustomEvent<WdsChartClickDetail>Click on a bar, point or slice.
wds-legend-changeCustomEvent<WdsChartLegendChangeDetail>A series is hidden or shown from the legend.

Methods

MethodDescription
getInstance()The ECharts instance (after the first draw), e.g. for dispatchAction.
resize()Fits the chart to its container (it also does this on its own when the size changes).

CSS parts (::part)

PartDescription
plotThe drawing area.
legendThe legend.
tableThe data table.

CSS custom properties

PropertyDescription
--wds-chart-heightChart height (by default from the aspect ratio).
--wds-chart-aspect-ratioAspect ratio when no height is set (default 16 / 9).

Accessibility#

Screen reader#

The element has role="figure" and label as its accessible name. The drawing itself is hidden from screen readers (aria-hidden); instead the data is in a table with the label as its caption, visually hidden unless show-table is set.

The legend is a list of toggle buttons with aria-pressed; a hidden series stays in the table. The legend name and the fallback table caption are built in and are in Polish for now (Legenda, Dane wykresu).

The tooltip and the center value of a donut are visual only; the same values are in the table.

Keyboard support#

KeyFunction
TabMoves focus through the legend buttons.
EnterSpaceHides or shows the series (or category) of the focused legend button.
Footer