Skip to main content

Top-level Chart Component

Overview​

The whole @elastic/charts library starts with the Chart component.

Props​

size​

Sets the size of the chart.

Examples:

  • 200 - Sets width and height to 200px
  • '90%' - Sets width and height to 90% of parent
  • ['100%', 200] - Sets width to 100% of parent and height to 200px
  • { width: '100%', height: 200 } - Sets width to 100% of parent and height to 200px

id​

  • Type: id?: string
  • Default: a random UUID via uuid

A unique id to indetify the chart. Used to renerate individual chart state.

title​

  • Type: title?: string

Top-level title of the chart.

description​

  • Type: description?: string

Top-level description of the chart.

children​

  • Type: children?: ReactNode

The children specs defining the chart.

In @elastic/charts we configure the chart using a react component api, we call these configuration components specs. Theses specs are applied as children of the Chart element.

While technically children are optional, passing no children will simply return an empty chart.

className​

  • Type: className?: string

Adds className to .echChartContent element for custom styling.

warning

Careful adding too many styles, as this can lead to unexpected apperance and behaviour of the chart.

renderer​

  • Type: renderer?: 'svg' | 'canvas'
  • Default: 'canvas'

The drawing backend of the chart. canvas draws into a bitmap, svg emits vector elements into an <svg> of the same size. Both share the layout and the drawing code, so switching never moves anything; the output differs only by antialiasing and sub-pixel text placement.

Use svg when the chart has up to a few thousand marks and you want crisp output under browser zoom or CSS scaling, an inspectable DOM, or vector printing. Keep canvas for dense data, such as a heatmap with many cells or a line chart with thousands of points: every SVG mark is a DOM element.

XY (bar, line, area, bubble), partition (sunburst, treemap, mosaic, waffle, icicle, flame layouts), heatmap, goal, bullet and timeslip charts support both. The flame chart draws on canvas and WebGL regardless of this option; metric and wordcloud are DOM and SVG regardless. Hover animations on svg run as CSS transitions, and getPNGSnapshot works with either backend.

One limitation: a texture whose path is a Path2D object cannot be drawn on svg, since a Path2D cannot be read back; such a series falls back to its plain fill and a warning is logged. Give texture paths as SVG path data strings to use them with either backend.