Pie Chart

A donut or pie for parts of a whole: the total in the centre, the hovered segment's value, percent labels on the segments and a legend that can list values and shares. Drawn as SVG, rendered on the server and themed by the design tokens.

Part of @tectra-ng/charts (npm install @tectra-ng/charts, also included in tectra-ng).

Features14APIThemingAccessibility

Basic

Pass pieData with series (values) and labels. Hover a segment: it moves out, its value and name appear in the centre, and the tooltip points at it from the outside.

Arrow keys move between values
Visits by source. Donut chart, 1 series, 5 values, total 10,000
CategoryValueShare
Search4,20042%
Direct2,60026%
Social1,80018%
Email9509.5%
Referral4504.5%

Legend variants

legendVariant: dot (the default), line, pill (tinted chips) or stat — the value of each segment in large type with its share under it.

Arrow keys move between values
Legend variants. Donut chart, 1 series, 4 values, total 90
CategoryValueShare
Salaries3842.2%
Infrastructure2426.7%
Marketing1617.8%
Office1213.3%

Pie

donutSize="0%" fills the hole — a classic pie. The percent labels sit in the middle of each slice; slices under 10° get none.

Arrow keys move between values
Budget split. Pie chart, 1 series, 5 values, total 100
CategoryValueShare
Salaries3838%
Infrastructure2424%
Marketing1616%
Office1212%
Other1010%

Ring

donutSize sets the hole ('65%' by default), segmentGap the card-coloured gap between segments in pixels and segmentRadius the rounding of their corners — large on a thin ring for soft capsule ends, 0 for sharp cuts. The rounding shrinks by itself where a segment is too narrow for it.

Arrow keys move between values
Hosts by status, thin ring. Donut chart, 1 series, 3 values, total 75
CategoryValueShare
Healthy6282.7%
Degraded912%
Down45.3%
Arrow keys move between values
Hosts by status, thick ring. Donut chart, 1 series, 3 values, total 75
CategoryValueShare
Healthy6282.7%
Degraded912%
Down45.3%

Half donut

startAngle and endAngle (degrees, 0 at the top, clockwise) draw a part of the circle — -90 to 90 is a half donut that fits a wide, low card.

Arrow keys move between values
Votes by answer. Donut chart, 1 series, 3 values, total 800
CategoryValueShare
Yes41251.5%
No26833.5%
Not sure12015%

Legend values

legendValues lists the value and the share of each segment; legendPosition="right" puts the legend beside the chart. Items still toggle their segment.

Arrow keys move between values
Budget split. Donut chart, 1 series, 5 values, total 100
CategoryValueShare
Salaries3838%
Infrastructure2424%
Marketing1616%
Office1212%
Other1010%

Own legend

For a small donut next to your own list, turn the legend off and build the rows with the txPieLegend pipe (or pieLegend()): it returns label, value, percent and the same color the chart uses.

Arrow keys move between values
Articles by tag. Donut chart, 1 series, 5 values, total 124
CategoryValueShare
Angular4838.7%
Design3125%
Accessibility2217.7%
Performance1411.3%
Testing97.3%
Angular4839%
Design3125%
Accessibility2218%
Performance1411%
Testing97%

Center

<ng-template txPieCenter let-center> draws the middle of the donut. The context has the hovered segment (label, value, color, hovered) or the total.

Arrow keys move between values
Storage used. Donut chart, 1 series, 4 values, total 364
CategoryValueShare
Video18450.5%
Photos9626.4%
Documents6116.8%
Apps236.3%

Total formatter

totalLabel keeps the total in the centre; totalFormatter formats it and the hovered value, tooltipFormatter formats the tooltip.

Arrow keys move between values
Spending by category. Donut chart, 1 series, 4 values, total 2,831.5
CategoryValueShare
Rent1,240.543.8%
Food860.2530.4%
Transport42014.8%
Fun310.7511%

Live

New pieData morphs the segments to their new angles; a legend item hides its segment and the rest close the gap. segmentClick and segmentToggle report what the user did.

Arrow keys move between values
Hours by activity. Donut chart, 1 series, 4 values, total 33
CategoryValueShare
Coding1442.4%
Meetings927.3%
Review618.2%
Learning412.1%

Click a segment or a legend item.

Loading and empty

loading shows a skeleton of the chart's size; no values, or only zeros, show "No data".

No data

Accessibility

Tab to the chart and use the arrow keys to walk the segments (Home / End to the ends, Escape to leave); each is announced with its value and share, and the tooltip follows. A summary and a hidden table with values and shares are there for screen readers.

Arrow keys move between values
Visitors by browser. Donut chart, 1 series, 4 values, total 100
CategoryValueShare
Chrome6464%
Safari1919%
Firefox1111%
Edge66%

Design tokens

dt sets the palette, the segment gap colour, the data labels and the centre texts of one chart.

Arrow keys move between values
Budget split. Donut chart, 1 series, 5 values, total 100
CategoryValueShare
Salaries3838%
Infrastructure2424%
Marketing1616%
Office1212%
Other1010%

Pass through

pt reaches the parts: segment, dataLabel, center, legend, legendItem, plot, tooltip and more.

Arrow keys move between values
Budget split. Donut chart, 1 series, 5 values, total 100
CategoryValueShare
Salaries3838%
Infrastructure2424%
Marketing1616%
Office1212%
Other1010%