# Chart (`<z-chart>`)

> ApexCharts wrapper configured through a JSON config script, with loading/error states and live option/series updates.

- **Kind:** hwc
- **Category:** data
- **Inherits:** `Hwc`, `Base`

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `loading` | `boolean` | `false` | — | Defers chart initialization until set back to false; shows the loading state meanwhile. |
| `width` | `string` | `'100%'` | — | Chart width passed to ApexCharts (default `100%`). |
| `height` | `string` | `'auto'` | — | Chart height passed to ApexCharts (default `auto`). |

### Inherited from `Hwc`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `i18n` | `string` | `''` | `Hwc` | Per-instance text overrides as `key: text` pairs, merged over the global `z-i18n` script and the built-in defaults. |
| `floating` | `string` | `''` | `Hwc` | Floating UI placement options (for example `offset` and `shiftPadding`) parsed as `key: value` pairs. |
| `force-prevent-rerender` | `boolean` | `false` | `Hwc` | Skips re-rendering after the first render; an existing `data-host-inner` child is adopted as the rendered DOM. |
| `template` | `string` | `''` | `Hwc` | Selector or id of an external element or `<template>` whose inner content is cloned in place of an inline `template[data-fn="template"]` child. |

### Inherited from `Base`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `cls` | `string` | `''` | `Base` | Adds classes to named parts as `key: classes` pairs; a plain string targets the default part. |
| `stl` | `string` | `''` | `Base` | Adds inline styles to named parts as `key: styles` pairs; a plain string targets the default part. |

## Styling Parts (`cls` / `stl`)

Default `cls` target: `host-inner`. Default `stl` target: `host-inner`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `chart` | `z-chart` | ✓ | ✓ | The chart container (default `z-chart`). |
| `error` | `sr-only` | ✓ | ✓ | Error announcement region (default `sr-only`). |
| `host-inner` | — | ✓ | ✓ | Rendered root wrapper; the default `cls`/`stl` target. |
| `loading` | `sr-only` | ✓ | ✓ | Loading announcement region (default `sr-only`). |

## Reference inventories

- [Accessibility (4 ARIA parts)](https://next.0build.dev/docs/components/chart/accessibility.md)

## i18n Keys

| Key | Default | Description |
| --- | --- | --- |
| `chart-label` | `Chart` | Accessible label of the chart region. |
| `error-message` | `Failed to load chart. Please try again.` | Error announcement text. |
| `loading-message` | `Loading chart...` | Loading announcement text. |
| `no-data-message` | `No data available` | Text shown when there is no data. |

## Methods

| Method | Params | Returns | Description |
| --- | --- | --- | --- |
| `getChartInstance()` | — | `ApexCharts \| null` | Returns the underlying ApexCharts instance (or null). |
| `updateChart()` | `options: object`, `redrawPaths?: boolean = true`, `animate?: boolean = true` | `Promise<void>` | Calls ApexCharts `updateOptions` with the given options, redraw paths, and animation flags. |
| `updateSeries()` | `newSeries: ApexAxisChartSeries \| ApexNonAxisChartSeries`, `animate?: boolean = true` | `Promise<void>` | Calls ApexCharts `updateSeries` with new series data and an animation flag. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-chart-container` | — | `descendant` | `marker` | Marks the element ApexCharts renders into. |
| `data-error` | — | `descendant` | `marker` | Set when initialization or updates fail. |
| `data-host-inner` | — | `descendant` | `config` | Marks the rendered inner wrapper so `force-prevent-rerender` can adopt server-rendered DOM without re-rendering. |
| `data-loading` | — | `descendant` | `marker` | Set while the chart is loading. |
| `data-reactive` | — | `descendant` | `config` | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
| `data-rendered` | — | `descendant` | `marker` | Set after the chart has rendered. |

## Child Content

- `<script data-fn="config">` — JSON configuration script parsed by the base class (i18n, cls, stl, floating).

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `config` | Marks the script as configuration (value: `config`). |
  | `data-reactive` | — | `boolean` | Re-parses the configuration when the script mutates. |

- `<select data-fn="data-source">` — Hidden select parsed into grouped option data by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `data-source` | Marks the select as the data source (value: `data-source`). |
  | `data-reactive` | — | `boolean` | Re-parses the options when the select mutates. |

  - `<optgroup>` — Groups options under a label.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `label` | ✓ | `string` | Group header text; also the default group key. |
    | `disabled` | — | `boolean` | Disables every option in the group. |
    | `data-key` | — | `string` | Overrides the group key used in the parsed data. |
    | `data-keywords` | — | `comma-separated string` | Comma-separated keywords stored with the group's data. |

    - `<option>` — One option entry within the group.

      | Attribute | Required | Type | Description |
      | --- | --- | --- | --- |
      | `value` | — | `string` | Value carried by this option in the parsed data. |
      | `disabled` | — | `boolean` | Makes the option non-selectable. |
      | `selected` | — | `boolean` | Marks the option as initially selected. |
      | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated; searched alongside the label and value. |

  - `<option>` — One ungrouped option entry.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `value` | — | `string` | Value carried by this option in the parsed data. |
    | `disabled` | — | `boolean` | Makes the option non-selectable. |
    | `selected` | — | `boolean` | Marks the option as initially selected. |
    | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated. |

- `<template data-fn="icons">` — Instance-level icon repository.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `icons` | Marks the template as an icon source (value: `icons`). |
  | `data-reactive` | — | `boolean` | Re-parses the icons when the template mutates. |

  - `<*>` — One icon element.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `data-key` | ✓ | `string` | Icon key referenced by `$icons`. |

- `<template data-fn="template">` — Deferred content template mounted by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `template` | Marks the template for deferred mounting (value: `template`). |
  | `data-reactive` | — | `boolean` | Re-parses the template when it mutates. |

## Notes

- Configuration comes from the shared config script under the `apexCharts` key; changing it live updates the chart.
- ApexCharts is an optional dependency loaded by the chart pack; without a valid config the error state shows.
- There is no kit CSS layer for charts — style via ApexCharts options or the `chart` part.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)
