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).
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.
| Category | Value | Share |
|---|---|---|
| Search | 4,200 | 42% |
| Direct | 2,600 | 26% |
| Social | 1,800 | 18% |
| 950 | 9.5% | |
| Referral | 450 | 4.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.
| Category | Value | Share |
|---|---|---|
| Salaries | 38 | 42.2% |
| Infrastructure | 24 | 26.7% |
| Marketing | 16 | 17.8% |
| Office | 12 | 13.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.
| Category | Value | Share |
|---|---|---|
| Salaries | 38 | 38% |
| Infrastructure | 24 | 24% |
| Marketing | 16 | 16% |
| Office | 12 | 12% |
| Other | 10 | 10% |
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.
| Category | Value | Share |
|---|---|---|
| Healthy | 62 | 82.7% |
| Degraded | 9 | 12% |
| Down | 4 | 5.3% |
| Category | Value | Share |
|---|---|---|
| Healthy | 62 | 82.7% |
| Degraded | 9 | 12% |
| Down | 4 | 5.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.
| Category | Value | Share |
|---|---|---|
| Yes | 412 | 51.5% |
| No | 268 | 33.5% |
| Not sure | 120 | 15% |
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.
| Category | Value | Share |
|---|---|---|
| Salaries | 38 | 38% |
| Infrastructure | 24 | 24% |
| Marketing | 16 | 16% |
| Office | 12 | 12% |
| Other | 10 | 10% |
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.
| Category | Value | Share |
|---|---|---|
| Angular | 48 | 38.7% |
| Design | 31 | 25% |
| Accessibility | 22 | 17.7% |
| Performance | 14 | 11.3% |
| Testing | 9 | 7.3% |
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.
| Category | Value | Share |
|---|---|---|
| Video | 184 | 50.5% |
| Photos | 96 | 26.4% |
| Documents | 61 | 16.8% |
| Apps | 23 | 6.3% |
Total formatter
totalLabel keeps the total in the centre; totalFormatter formats it and the hovered value, tooltipFormatter formats the tooltip.
| Category | Value | Share |
|---|---|---|
| Rent | 1,240.5 | 43.8% |
| Food | 860.25 | 30.4% |
| Transport | 420 | 14.8% |
| Fun | 310.75 | 11% |
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.
| Category | Value | Share |
|---|---|---|
| Coding | 14 | 42.4% |
| Meetings | 9 | 27.3% |
| Review | 6 | 18.2% |
| Learning | 4 | 12.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".
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.
| Category | Value | Share |
|---|---|---|
| Chrome | 64 | 64% |
| Safari | 19 | 19% |
| Firefox | 11 | 11% |
| Edge | 6 | 6% |
Design tokens
dt sets the palette, the segment gap colour, the data labels and the centre texts of one chart.
| Category | Value | Share |
|---|---|---|
| Salaries | 38 | 38% |
| Infrastructure | 24 | 24% |
| Marketing | 16 | 16% |
| Office | 12 | 12% |
| Other | 10 | 10% |
Pass through
pt reaches the parts: segment, dataLabel, center, legend, legendItem, plot, tooltip and more.
| Category | Value | Share |
|---|---|---|
| Salaries | 38 | 38% |
| Infrastructure | 24 | 24% |
| Marketing | 16 | 16% |
| Office | 12 | 12% |
| Other | 10 | 10% |