Skip to content
ONIWC
iwc 0.1.0

chart element

A bar or line chart drawn on the server as inline SVG.

Renders

<figure> with an inline <svg> chart

Required

chart (kind, x, y) and data.

Native apps

Web, and server-driven native apps

Syntax

chart element
{ "type": "chart" }

An element lives in a screen's sections, another element's elements, a layout slot or a component root.

Properties

PropertyTypeDescription
chartobject
  • currency: string — ISO code for format currency
  • format: "number" | "currency" | "percent" — how values are written in labels
  • height: integer
  • kind: "bar" | "line"
  • scale: number — multiply each value for display, e.g. 0.01 to show cents as currency units
  • x: string — identifiers use letters, digits and '_' and do not start with a digit
  • y: string — identifiers use letters, digits and '_' and do not start with a digit
dataobject
  • aggregate: object — summarise in the database: one record per group with its measures; sort by a group or measure name
  • as: string — identifiers use letters, digits and '_' and do not start with a digit
  • cache: duration (500ms, 6s…) — durations look like 500ms, 30s, 5m, 1h or 7d
  • columns: array of string
  • filter: object {name: string | number | boolean | null | object}
  • include: object {name: object} — related records loaded with each record, one query per include: {"category": {}} or {"reviews": {"source": "DATABASE.reviews", "on": "product"}}
  • items: array of any — inline records for STATIC sources
  • limit: integer (1–500)
  • live: boolean — re-render when the underlying records change (server push)
  • mode: "list" | "single"
  • paginate: object
  • query: object {name: string | number | boolean | null | object} — API sources: query values passed to the api (literals or {param|query|props} references)
  • refresh: duration (500ms, 6s…) — durations look like 500ms, 30s, 5m, 1h or 7d
  • required: boolean — page data: when nothing matches, the page answers 404
  • search: object
  • sort: object
  • source: string — sources are DATABASE.<schema>, API.<name>, STATIC, USER, STATE.<store>.<list> or an expression giving a list ("=product.images")

Plus the properties every element accepts: id, className, style, responsive, states, animation, visible, ariaLabel, attributes and more.

Example

chart example
{
  "type": "chart",
  "chart": { "kind": "bar", "x": "name", "y": "stock", "height": 200 },
  "data": {
    "source": "DATABASE.products",
    "columns": ["name", "stock"],
    "sort": { "field": "name" }
  }
}

chart.scale multiplies values for display and chart.format/chart.currency write them — "scale": 0.01, "format": "currency" shows amounts stored in cents. No JavaScript is shipped for charts.

Expected output

The HTML IWC rendered for the example above (inside the page's content wrapper). Class names such as i807b63fc are generated per element for its scoped CSS.

Rendered HTML
<div class="iwc-page ipage" id="iwc-content">
  <figure class="iwc-chart ice41618b">
    <svg class="iwc-chart" viewBox="0 0 640 200" role="img" aria-label="bar chart"><line x1="32.0" x2="608.0" y1="32.0" y2="32.0" stroke="currentColor" stroke-opacity=".15" stroke-dasharray="3 3"/><text x="32.0" y="26.0" font-size="10" fill="currentColor" fill-opacity=".7">40</text><rect x="60.8" y="127.2" width="134.4" height="40.8" rx="3" fill="var(--color-primary,#2563eb)"><title>Desk Lamp: 12</title></rect><text x="128.0" y="189.3" font-size="11" text-anchor="middle" fill="currentColor">Desk Lamp</text><rect x="252.8" y="144.2" width="134.4" height="23.8" rx="3" fill="var(--color-primary,#2563eb)"><title>Dot Notebook: 7</title></rect><text x="320.0" y="189.3" font-size="11" text-anchor="middle" fill="currentColor">Dot Notebook</text><rect x="444.8" y="32.0" width="134.4" height="136.0" rx="3" fill="var(--color-primary,#2563eb)"><title>Stoneware Mug: 40</title></rect><text x="512.0" y="189.3" font-size="11" text-anchor="middle" fill="currentColor">Stoneware Mug</text></svg>
  </figure>
</div>

Data, conditions & styling

  • Conditional rendering: "visible": {"auth": "signed-in"}, {"roles": ["admin"]} or an expression such as "=product.stock > 0". Decided on the server: hidden elements are never sent.
  • Data binding: bind takes text from data (name, user.name, props.title, params.slug, state.cart.count); binds binds attributes. Containers become data-driven with data + item. See data binding.
  • Styling: className for your stylesheets, style for CSS in JSON, states for hover/focus/active, animation for entrance motion. See the style property reference.
  • Responsive behaviour: responsive applies CSS at or below a breakpoint ({"mobile": {"padding": "12px"}}); grids also take responsiveColumns.