Skip to main content
Urbicon UI
source

ChartFramebeta

Responsive SVG chart shell — measures its width, applies plot margins, and hands the drawable plot geometry to a child snippet. The building block under every cartesian chart.

Playground

Loading...
Loading syntax highlighting...

01 When to use

ChartFrame is the low-level shell every cartesian chart in the family is built on. It owns the parts that are tedious to get right — responsive width via a ResizeObserver, plot margins, the viewBox, and the accessible role="img" wrapper — and hands you the measured plot geometry so you only draw the marks.

Reach for it only when the chart you need isn't already in the family. For the common cases prefer the ready-made charts — they handle scales, axes, legends and tooltips for you:

  • LineChart / AreaChart — trends over a continuous axis
  • BarChart — categorical comparisons
  • DonutChart — part-to-whole
  • Sparkline — a tiny inline trend with no axes

Use ChartFrame directly for a bespoke mark type the family doesn't cover (a candlestick, a radial plot, a custom annotation layer) — you keep the responsive, accessible shell and own only the SVG inside it.

02 Examples

Custom marks

The core pattern: the `children` snippet receives the plot geometry — `width`, `height`, `innerWidth`, `innerHeight` and `margin`. Map your data onto `innerWidth`/`innerHeight` and draw raw SVG, styling strokes and fills with the design-token utilities (`stroke-primary`, `stroke-border-default`) so theming and dark mode flow automatically.
Loading...
Loading syntax highlighting...

Legend & accessible fallback

`ariaLabel` names the chart, the `legend` snippet renders HTML below the SVG, and the `fallback` snippet is rendered visually hidden for screen readers — a data table here, so the underlying numbers stay reachable.
Revenue (k€)
Daily revenue, Monday to Friday
DayRevenue (k€)
Mon12
Tue19
Wed15
Thu24
Fri21
Loading...
Loading syntax highlighting...

Fixed width (SSR-stable)

Omit `width` for responsive measurement (the common case). Set it to opt out — the SVG renders at exactly that width on the server with no layout shift, useful for emails, PDfs or snapshot tests.
Loading...
Loading syntax highlighting...

03 Accessibility

  • The SVG carries role="img" with your ariaLabel, so assistive tech announces the chart as a single named image rather than reading out every path and number.
  • Because role="img" hides the SVG internals, supply a fallback snippet — rendered visually hidden — when the detail matters. A data <table> is the most robust choice.
  • The legend snippet is ordinary HTML below the SVG, so its text is selectable and in the accessibility tree without extra work.
  • Always pass an ariaLabel. Without it the chart is an unlabelled image — fine only when an adjacent caption already conveys the same information.

API Reference

11 props

No matching properties

No matching properties

Installation

Import

Loading...
Loading syntax highlighting...