Gradients
Series fills can use SVG gradients: declare them in linearGradients (or radialGradients) and point a series at one with gradient. As with stacks and groups, a sole configured gradient is applied automatically — to every area/bar series (or pie slice) that sets neither a colorProperty nor a categoryIndex fill, provided no patterns are configured. With several gradients, or any patterns, select the gradient by id.
ts
// Series reference a gradient by id. The gradient's x1/y1 → x2/y2 vector is
// in 0–1 shape coordinates (here top → bottom), and each stop sets an
// offset, color, and opacity.
import type { MochartInputConfig } from '@mochart/core';
export const config: MochartInputConfig = {
version: '1.0.0',
title: { text: 'Bandwidth' },
categoryAxis: { property: 'hour', type: 'string', scale: 'ordinal' },
linearGradients: [
{
id: 'fade',
x1: 0, y1: 0, x2: 0, y2: 1,
stops: [
{ offset: 0, color: '#1f77b4', opacity: 0.9 },
{ offset: 1, color: '#1f77b4', opacity: 0.05 }
]
}
],
series: [
{
property: 'gbps',
title: 'Throughput',
renderer: 'area',
gradient: 'fade'
}
]
};
export const data = [
{ hour: '00:00', gbps: 14 },
{ hour: '04:00', gbps: 9 },
{ hour: '08:00', gbps: 32 },
{ hour: '12:00', gbps: 45 },
{ hour: '16:00', gbps: 51 },
{ hour: '20:00', gbps: 38 }
];How it works
- The gradient vector runs from
x1/y1tox2/y2in 0–1 shape coordinates —0,0 → 0,1is a top-to-bottom fade (the default is the diagonal0,0 → 1,1). Addrotationto angle it. - Each stop sets
offset(0–1 along the vector),color, andopacity;stopsis the one property without a default. - Radial gradients take
cx/cy/r(circle) andfx/fy(focal point) instead of a vector. - Shared values for several gradients can go in
linearGradientDefaults/radialGradientDefaults, like every list section (see the config model). - Gradients are positional — the fade follows the shape, not the data. For color driven by data values, see color by value.
- In an XY chart, a series can use a gradient only when its
rendererisareaorbar; pie slices can use one whatever the series renderer. A series cannot combinegradientwithcolorPropertyorpattern, and a series whoseshapeStylefill color iscategoryIndexin any state cannot set one either, because that fill already varies per category. Setgradient: nullto opt a series out of an automatically applied sole gradient. - Legend and tooltip swatches reproduce the gradient.