Date-Time Category

Free

Area and line series on a date-time category axis, with day / month / year zoom levels. Labels take the application locale; a bare YYYY-MM-DD is read as a calendar day in local time rather than as UTC midnight. Pure SVG.

</>sv-datetime-category-chart chartdatetimetime-serieslocale
import { SvDateTimeCategoryChartComponent } from '@styloviz/charts';

Demo & usage

Basic usage

Usage example — open the gallery for the full interactive demo.

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Month zoom

example.htmlAngular
<sv-datetime-category-chart [categories]="days" [series]="series" [options]="{ zoom: 'month' }" />

A report pinned to one language

example.htmlAngular
<sv-datetime-category-chart [categories]="days" [series]="series" locale="de-DE" />

When to use

  • A series whose x-axis is dates and whose labels should read as dates.
  • When the axis needs to switch between daily, monthly and yearly granularity.
  • For a plain ordered axis with no date semantics, the Line Chart is simpler — it never parses a date at all.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
categoriesstring[][]ISO date strings for the X axis, one per data point. A bare `YYYY-MM-DD` is read as a local calendar day; labels are formatted per `options.zoom` and `locale`.
seriesDateTimeSeries[][]Line series; `data` holds one value per category. The area under a line is filled per the series' `fill`, else `options.showArea` (on by default).
titlestring''Chart title rendered above the plot; also used as the plot's accessible name.
heightnumber320Chart height in pixels.
optionsDateTimeCategoryOptions{}Display options: grid, legend, area fill (`showArea`, default true; a series' own `fill` wins), date-label `zoom` (`'day'` | `'month'` | `'year'`, default `'month'`) and animation duration.
localestringinject(LOCALE_ID)BCP 47 locale for the date labels on the x-axis. Defaults to the application's `LOCALE_ID` — the same value `DatePipe` uses — so an app that has configured its locale gets matching axis labels without doing anything here. Override per chart for a report that must read in one fixed language whoever opens it. Only the LABELS are localised. The `categories` themselves stay ISO strings, because they are also the join key for the series and a localised key would differ between two readers looking at the same dashboard.
customClassstring''Extra CSS classes applied to the root wrapper.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
categoryHoverDateTimeCategoryEventEmitted when a category is hovered or keyboard-focused.
categorySelectDateTimeCategoryEventEmitted when a category is clicked or activated via keyboard (Enter/Space).

<sv-datetime-category-chart-pro>

Also in this family — SvDateTimeCategoryChartProComponent from @styloviz-pro/charts.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the series are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No data to plot'Copy for the empty state.
filteredbooleanfalseWhether a filter, not an absence of data, is why the chart is empty.
categoriesstring[][]ISO date strings for the X axis, one per data point. A bare `YYYY-MM-DD` is read as a local calendar day; labels are formatted per `options.zoom` and `locale`.
seriesDateTimeSeries[][]Line series; `data` holds one value per category. The area under a line is filled per the series' `fill`, else `options.showArea` (on by default).
titlestring''Chart title rendered above the plot; also used as the plot's accessible name.
heightnumber320Chart height in pixels.
optionsDateTimeCategoryOptions{}Display options: grid, legend, area fill (`showArea`, default true; a series' own `fill` wins), date-label `zoom` (`'day'` | `'month'` | `'year'`, default `'month'`) and animation duration.
localestringinject(LOCALE_ID)BCP 47 locale for the date labels on the x-axis. Defaults to the application's `LOCALE_ID` — the same value `DatePipe` uses — so an app that has configured its locale gets matching axis labels without doing anything here. Override per chart for a report that must read in one fixed language whoever opens it. Only the LABELS are localised. The `categories` themselves stay ISO strings, because they are also the join key for the series and a localised key would differ between two readers looking at the same dashboard.
customClassstring''Extra CSS classes applied to the root wrapper.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
categoryHoverDateTimeCategoryEventEmitted when a category is hovered or keyboard-focused.
categorySelectDateTimeCategoryEventEmitted when a category is clicked or activated via keyboard (Enter/Space).

Wire it to your API

This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.

Template

Bound to the names this component actually exposes.

usage.htmlAngular
<sv-datetime-category-chart
  [series]="data.items()"
  [loading]="data.loading()"
  [error]="data.error()"
  [filtered]="data.filtered()"
  (retry)="data.reload()"
/>

Host class

Drive the three async inputs from your own fetch.

host.component.tsTypeScript
// This component reports its state but does not emit a query, so drive
// it from your own fetch and bind the three async inputs.
readonly items = signal<Row[]>([]);
readonly loading = signal(false);
readonly error = signal<SvDataError | null>(null);

async load(): Promise<void> {
  this.loading.set(true);
  this.error.set(null);
  try {
    this.items.set(await this.api.fetchRows());
  } catch (e) {
    this.error.set(toSvDataError(e));
  } finally {
    this.loading.set(false);
  }
}
  • This component does not emit a query, so it renders what you give it. Fetch on your own trigger and bind `series`, `loading` and `error`.
  • Set `filtered` when a search or filter is active. It is the difference between "you have no orders" and "no orders match this filter" — telling a customer with 4,000 orders the first one reads as a bug.
  • Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.

Full walkthrough: Connecting to a backend.

Customization & theming

  • Day, month and year zoom levels.
  • Per-chart locale override, defaulting to the app's LOCALE_ID.
  • Area or line rendering per series, with the usual grid and legend switches.

Best practices

  • Do: Keep the categories as ISO strings. They are the join key for the series as well as the source of the labels, and a localised key would differ between two people looking at the same dashboard.
  • Do: Let the locale come from the app. It defaults to LOCALE_ID — the same value DatePipe resolves — so a correctly configured application gets matching labels everywhere. Set it per chart only for a report that must read in one fixed language whoever opens it.
  • Tip: A bare YYYY-MM-DD is a calendar day, and this chart reads it as one in local time. ECMA-262 requires the date-only form to parse as UTC midnight, which is why a naive implementation labels a daily axis a day early for everyone west of Greenwich.

Accessibility

  • The axis label, the tooltip and the accessible name are formatted once from one function, so the three cannot disagree about what day a column is.
  • An unparseable category falls back to the raw string the host sent rather than printing "Invalid Date" down the whole axis.

Feedback on Date-Time Category

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.