Skip to content

Area

The area under a line; filled from zero (or from the previous series in a stack).

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Website Visitors' },
    subtitle: { text: 'thousands per month' },
    series: [{ type: 'area', xField: 'month', yField: 'visitors', name: 'Visitors' }],
    legend: { enabled: false },
  };
}
ts
export function getData() {
  return [
    { month: 'Jan', visitors: 310 },
    { month: 'Feb', visitors: 345 },
    { month: 'Mar', visitors: 410 },
    { month: 'Apr', visitors: 388 },
    { month: 'May', visitors: 462 },
    { month: 'Jun', visitors: 520 },
    { month: 'Jul', visitors: 498 },
    { month: 'Aug', visitors: 545 },
  ];
}

Value labels

label — same as for line: placement top/bottom/left/right, formatter, font:

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Area with Value Labels' },
    series: [
      {
        type: 'area',
        xField: 'week',
        yField: 'signups',
        name: 'Signups',
        fillOpacity: 0.25,
        marker: { enabled: true },
        label: { enabled: true, placement: 'top', fontWeight: 'bold' },
      },
    ],
    legend: { enabled: false },
  };
}
ts
export function getData() {
  return [
    { week: 'W1', signups: 120 },
    { week: 'W2', signups: 168 },
    { week: 'W3', signups: 145 },
    { week: 'W4', signups: 210 },
    { week: 'W5', signups: 198 },
    { week: 'W6', signups: 256 },
  ];
}

Stacking

stacked: true stacks areas on top of each other; the order of series in the array is the bottom-to-top order.

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Requests by Channel' },
    series: [
      { type: 'area', xField: 'month', yField: 'web', name: 'Web', stacked: true },
      { type: 'area', xField: 'month', yField: 'app', name: 'App', stacked: true },
      { type: 'area', xField: 'month', yField: 'api', name: 'API', stacked: true },
    ],
  };
}
ts
export function getData() {
  return [
    { month: 'Jan', app: 120, web: 180, api: 60 },
    { month: 'Feb', app: 132, web: 174, api: 72 },
    { month: 'Mar', app: 151, web: 192, api: 81 },
    { month: 'Apr', app: 168, web: 188, api: 95 },
    { month: 'May', app: 190, web: 201, api: 108 },
    { month: 'Jun', app: 214, web: 196, api: 121 },
  ];
}

Overlapping areas

Without stacking, with fillOpacity configured:

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Overlapping Areas' },
    subtitle: { text: 'fillOpacity + shared tooltip' },
    series: [
      { type: 'area', xField: 'hour', yField: 'desktop', name: 'Desktop', fillOpacity: 0.35 },
      { type: 'area', xField: 'hour', yField: 'mobile', name: 'Mobile', fillOpacity: 0.35 },
    ],
    tooltip: { mode: 'shared', range: 'nearest' },
  };
}
ts
export function getData() {
  const data = [];
  for (let hour = 0; hour < 24; hour++) {
    data.push({
      hour: `${String(hour).padStart(2, '0')}:00`,
      mobile: Math.round(40 + 35 * Math.exp(-((hour - 20) ** 2) / 18) + 25 * Math.exp(-((hour - 8) ** 2) / 10)),
      desktop: Math.round(20 + 55 * Math.exp(-((hour - 14) ** 2) / 22)),
    });
  }
  return data;
}

Options

Options common to all series (name, showInLegend, tooltip.renderer, …) are covered in Common series options.

OptionTypeDefaultDescription
xFieldstringdata keys
yFieldstringdata keys
fillColorValuepalettearea fill
fillOpacityFraction0.35area fill
strokeColorValuefill colortop line
strokeWidthPixels2top line
lineDashPixels[]line dash pattern
normalizedTonumbernormalize the stack total (100 — percentage stack)
stackedbooleanfalsestacking
stackGroupstringfalsestacking
label.enabledbooleanfalseshow value labels
label.placement'top' | 'bottom' | 'left' | 'right''top'label position
label.formatter({ value, datum }) => stringthe valuelabel content
label.fontSizePixels11label font size
label.fontWeightstring | numbernormalfont weight
label.fontFamilystringtheme fontfont family
label.colorColorValueforeground; auto-contrast when insidetext color
marker.enabledbooleanfalseshow markers
marker.shapeMarkerShapecirclemarker shape
marker.sizePixels7marker size
marker.fillColorValueseries colormarker fill
marker.strokeColorValuechart backgroundmarker stroke
marker.strokeWidthPixels1.5stroke width