Angular State Timeline Chart
The state timeline shows how something's status changed over time. Each row is one thing you're tracking, like a service or a device. Each row is split into periods, such as days or hours, and each period is colored by the worst state it reached. One hour of Error in an otherwise good day still shows up, and the longer it lasted, the darker the color.
Status History
This example shows four made-up services over 30 days. You can see an outage, a slowdown, a device that was off for a day and a half, and a backup that failed two days in a row. Hover over a day, or tab to it, to see its details.
Last 30 days
import { PcacStateTimelineConfig } from '@pioneer-code/pioneer-charts';
const config: PcacStateTimelineConfig = {
...new PcacStateTimelineConfig(),
height: 112,
// Least to most severe: each day shows its worst state
states: [
{ key: 'ok', label: 'OK' },
{ key: 'warning', label: 'Warning' },
{ key: 'error', label: 'Error' },
],
data: [
{
key: 'API', value: null, hide: false,
data: [
// A day: 24 hours long, 21 of them OK and 3 in Error
{
key: 'Fri, Oct 30', value: 24, hide: false,
data: [
{ key: 'ok', value: 21, hide: false, data: [] },
{ key: 'error', value: 3, hide: false, data: [] },
],
},
// ...a period for each day, oldest first
],
},
// ...a row for each service or device
],
};The Data
data is a list of rows. Each row is a PcacData: its key is the row's name, and its data is the row's periods, oldest first. Each period has:
- key: the period's name, shown in the tooltip and read by screen readers, like
'Fri, Nov 20'or'2 PM'. - value: how long the period is, in any unit (hours, minutes, milliseconds).
- data: how much time the period spent in each state, in the same unit. Each entry's
keymatches a state'skey.
Any time not covered by a state is unknown, for example because the device was off. A period that's partly unknown is striped, and a period that's entirely unknown is plain gray, so missing data never looks like OK. If you leave out value, the period's length is the total of its states, and none of it is unknown.
Each period takes the color of its worst state. "Worst" follows the order of states, which you list from least to most severe. The color is lighter when that state lasted a short time and full strength when it lasted all of the period's known time. Every period in a row is the same width, even if their lengths differ.
// A 24-hour day with data for 15 hours: 12 OK and 3 in Error.
// It's drawn red (its worst state) and striped for the 9 unknown hours.
{
key: 'Thu, Nov 12', value: 24, hide: false,
data: [
{ key: 'ok', value: 12, hide: false, data: [] },
{ key: 'error', value: 3, hide: false, data: [] },
],
}One Row With a Custom Tooltip
A single service, sized to fit in a status card: rowLabels: false and 14px tall, with totals written underneath. It also uses a tooltip template to show each day's hours. In the template, $implicit is the period and parent is its row.
API
Last 30 days: 1 with errors, 1 with warnings
<pcac-state-timeline [config]="config">
<ng-template pcacTooltip let-day>
<b>{{ day.key }}</b><br />{{ hours(day) }}
</ng-template>
</pcac-state-timeline>
<p>Last 30 days: {{ errors }} with errors, {{ warnings }} with warnings</p>
// The config: one row, no label, 14px tall
{ ...new PcacStateTimelineConfig(), height: 14, rowLabels: false, states, data: [row] }Long Windows
When periods get narrow, the gap between them shrinks automatically: from 2px to 1px, and then to none if a period would otherwise be less than a pixel wide. This example fits 90 days into a narrow card.
Last 90 days
Colors
By default, the first state is pale green, the last is a strong red, and any states in between are amber. Good periods stay in the background, and problems stand out. The colors differ in lightness as well as hue, so people with red-green color blindness can still tell them apart. The tooltip and screen reader text also name each state in words.
To change a color for one chart, set color on that state. Pick colors that differ in lightness, too. To restyle every chart inside an element, for example on a dark page, set the CSS custom properties below. This site's dark theme does exactly that.
/* Your own stylesheet: any ancestor of the charts */
.status-panel {
--pcac-state-timeline-ok-color: #98c9b2;
--pcac-state-timeline-warning-color: #d97706;
--pcac-state-timeline-error-color: #bb2d3b;
--pcac-state-timeline-unknown-color: #e9ecef;
/* Lighter shades are mixed with this color: use your page's background */
--pcac-state-timeline-background-color: #fff;
--pcac-state-timeline-row-label-color: #495057;
}Markup
<pcac-state-timeline [config]="config" (periodClicked)="onClicked($event)" />
API
import { PcacStateTimeline, PcacStateTimelineConfig, PcacStateTimelineState } from '@pioneer-code/pioneer-charts';Configuration
| Name | Description |
|---|---|
| data | Collection of PcacData objects. |
| height | Height of chart component. Default is 24px. |
| ariaLabel | What the chart shows, for screen readers — e.g. 'Sales by month, 2026'. The chart is announced as a group with this name, and each bar, slice or point inside it by its own key and value (see Accessibility). When omitted, its type is used: 'Bar chart', 'Pie chart', 'Line chart' and so on. |
| heightFull | If true, height is treated as a minimum height and the chart grows to fill its container whenever that container is taller. Default is false.
|
| states | The states a period can be in, listed from least to most severe. Each has a key (matching the keys in the periods' data), an optional label for the tooltip and screen readers (defaults to the key), and an optional color (defaults to the theme's). |
| gap | Space between periods, in px. Default 2. It shrinks automatically when periods get narrow. |
| rowLabels | Show each row's key to its left. Default true. Labels use at most 40% of the width. |
The rows split the height evenly, with 4px between them. The default height fits one row, so set a larger one for more rows. Keyboard users can move between periods with the arrow keys. Screen readers announce each period's row, name and states, for example "Database, Fri, Nov 6: Error 50%, OK 50%" (see Accessibility).
Events
| Binding | Description | Payload |
|---|---|---|
| (periodClicked)="onClicked($event)" | Emitted when a period is clicked, or when Enter or Space is pressed on it. It emits the period. Give the period an id to match it to your own data (see Data Contract). | PcacData |