Skip to content

Configuration

A chart is fully described by a single ChartOptions object — it is serializable, type-safe, and works identically in Charts.create and chart.update.

A minimal working example:

ts
import { Charts } from 'grafit-charts';

const chart = Charts.create({
  container: document.getElementById('app')!, // where to render
  data: [
    { month: 'Jan', plan: 120, fact: 134 },
    { month: 'Feb', plan: 125, fact: 118 },
  ],
  series: [
    { type: 'bar', xField: 'month', yField: 'plan', name: 'Plan' },
    { type: 'line', xField: 'month', yField: 'fact', name: 'Actual' },
  ],
});

That is all you need: axes, legend, tooltips, highlighting and the entry animation are enabled by default.

Data and series

data is an array of flat objects. Series contain no data of their own — they reference fields via xField/yField (specialized series have their own fields: angleField, sizeField, openField…).

series is a discriminated union on the type field: after type: 'bar', TypeScript suggests only bar options and won't let you pass options that belong to other series. All 27 series types are listed in the “Series” section; their shared options are on the Common series options page.

Axes

If axes are not specified, the widget creates them itself: category at the bottom + number on the left (the other way around for horizontal bars; scatter/histogram request a numeric X axis; heatmap gets categorical axes with no lines or grid). An explicit axes block is needed when you want a different axis type, label formatting, crossLines, etc. — see Axes.

ts
axes: [
  { type: 'time', position: 'bottom', label: { format: '%d %b' } },
  { type: 'number', position: 'left', nice: true },
],

Size

Without width/height the chart tracks its container via ResizeObserver — size the container with CSS. Numeric width/height fix the size.

Titles, padding, background

OptionTypeDefaultDescription
title.textstringchart title
title.textAlign'left' | 'center' | 'right''center'horizontal alignment
title.fontSizePixels17title font size
title.colorColorValueforegroundcolor
title.position'top' | 'bottom''top'above or below the plot
title.spacingPixels8gap towards the plot
subtitle.textstringsubtitle (muted, same options)
padding.topPixels12outer chart padding
padding.rightPixels20
padding.bottomPixels12
padding.leftPixels20
background.fillColorValuetheme backgroundbackdrop fill
background.visiblebooleantruewhether to draw the background

All caption options with live examples: Title and subtitle.

Overlays and loading

OptionTypeDefaultDescription
loadingbooleanfalseshow the “Loading data…” overlay
overlays.loading.textstringfrom localeloading overlay text
overlays.noData.textstringfrom localetext shown when data is empty

Conventions

  • *Field / *Name — “data key / display name” pairs: *Field points to a field in data, *Name is shown in the legend and the tooltip.
  • { enabled } — every optional block (legend, tooltip, axis.label, series.marker, …) is toggled with this flag; a block without enabled: false is enabled.
  • format / formatter — value formatting as a string (',.2f', '.0%', '%d %b') or as a function; functions are isolated leaves — the rest of the object is JSON-serializable.
  • Mutations of the object you passed in are not tracked — update the chart via its methods.

Updating and instance methods

ts
await chart.updateDelta({ theme: 'dark' }); // targeted change
await chart.update(buildOptions(newData)); // full replacement
MethodDescription
update(options)full options replacement; the Promise resolves after rendering
updateDelta(patch)deep merge: objects are merged, arrays are replaced as a whole
getOptions()current options
getState() / setState(state)zoom and hidden series — see State
waitForUpdate()wait for a scheduled render
getImageDataURL(opts?)PNG/JPEG as a data URL
download(opts?)download an image ({ fileName?, fileFormat? })
destroy()release the DOM and subscriptions

All root-level blocks

BlockWhat it doesRead more
container, data, series, axeschart foundationabove on this page
width, heightfixed sizeSize
title, subtitletitlesTitles
padding, backgroundpadding and backgroundTitles
loading, overlaysoverlaysOverlays
themetheme name or objectThemes
legendlegendLegend
gradientLegendcolor scale for colorField seriesHeatmap
tooltiptooltips (modes, position, snapping)Tooltip
highlighthover highlighting and dimmingTooltip
crosshaircrosshairCrosshair
zoom, navigatorzoom and range barZoom
syncsynchronizing multiple chartsState
selectiondata selectionData selection
listenerschart eventsEvents
annotationslines/ranges/text on the chartAnnotations
animationentry and updatesState
initialStateinitial zoom/hidden seriesState
contextMenuright-click menuState
localeUI stringsAccessibility