Chartist

Search

Find a guide, an API entry or an example.

Try

1.x classes

LineChart, BarChart and PieChart as in 1.x, with their options, axis classes, events and drawing helpers. Deprecated, and removed from chartist in 3.0: new code uses the chart functions.

These are the 1.x classes and what only they use, kept so 1.x code runs unchanged. New code uses the chart functions: see Charts, and Coming from 1.x for moving over.

LineChart

deprecated1.xSource
class LineChart extends PresetChart<LineChartEventsTypes, LineChartData, LineChartOptions>
new LineChart(query: string | Element | null, data: LineChartData, options?: LineChartOptions<AxisOptions, AxisOptions>, responsiveOptions?: ResponsiveOptions<LineChartOptions<AxisOptions, AxisOptions>>)

The 1.x line chart class: a wrapper over the lineChart preset with the 1.x API. 1.x events and 1.x plugin functions need the compat plugin (chartist/compat).

Deprecated. Use lineChart(). Removed in 3.0.

See also: lineChart for the v2 functional API.

BarChart

deprecated1.xSource
class BarChart extends PresetChart<BarChartEventsTypes, BarChartData, BarChartOptions>
new BarChart(query: string | Element | null, data: BarChartData, options?: BarChartOptions<AxisOptions, AxisOptions>, responsiveOptions?: ResponsiveOptions<BarChartOptions<AxisOptions, AxisOptions>>)

The 1.x bar chart class: a wrapper over the barChart preset with the 1.x API. 1.x events and 1.x plugin functions need the compat plugin (chartist/compat).

Deprecated. Use barChart(). Removed in 3.0.

See also: barChart for the v2 functional API.

PieChart

deprecated1.xSource
class PieChart extends PresetChart<PieChartEventsTypes, PieChartData, PieChartOptions>
new PieChart(query: string | Element | null, data: PieChartData, options?: PieChartOptions, responsiveOptions?: ResponsiveOptions<PieChartOptions>)

The 1.x pie chart class: a wrapper over the pieChart preset with the 1.x API. 1.x events and 1.x plugin functions need the compat plugin (chartist/compat).

Deprecated. Use pieChart(). Removed in 3.0.

See also: pieChart for the v2 functional API.

BaseChart

deprecated1.xSource
class BaseChart<TEventsTypes = BaseChartEventsTypes>
new BaseChart<TEventsTypes = BaseChartEventsTypes<CreatedEvent<Options<AxisOptions, AxisOptions>>, DrawEvent>>(query: string | Element | null, data: Data, defaultOptions: Options, options: Options, responsiveOptions?: ResponsiveOptions<Options<AxisOptions, AxisOptions>>)

The base class of the 1.x chart classes (LineChart, BarChart, PieChart): the container, update, detach, on and off.

Deprecated. Use the chart functions: lineChart(), barChart(), pieChart() and chart(). Removed in 3.0.

getSeriesOption

deprecated1.xSource
function getSeriesOption<T extends 'height' | 'width' | 'viewBox' | 'axisX' | 'axisY' | 'classNames' | 'high' | 'low' | 'referenceValue' | 'chartPadding' | 'plugins' | 'showLine' | 'showPoint' | 'showArea' | 'areaBase' | 'lineSmooth' | 'showGridBackground' | 'fullWidth' | 'reverseData'>(series: Series | SeriesObject<SeriesPrimitiveValue>, options: LineChartOptionsWithDefaults, key: T): LineChartOptionsWithDefaults[T]

Reads a line chart option for a series: the per-series value from options.series[name] if the series has a name and sets it, the chart's value otherwise.

Deprecated. Part of the 1.x chart classes, with no functional counterpart. Removed in 3.0.

createSvg

deprecated1.xSource
function createSvg(container: Element, width?: string | number, height?: string | number, className?: string, viewBox?: ViewBox): Svg

Create or reinitialize the SVG element for the chart

Deprecated. Part of the 1.x chart classes. The functional API builds a scene instead. Removed in 3.0.

Parameters

container Element

The containing DOM Node object that will be used to plant the SVG element

width? string | number = '100%'

Set the width of the SVG element. Default is 100%

height? string | number = '100%'

Set the height of the SVG element. Default is 100%

className? string

Specify a class to be added to the SVG element

viewBox? ViewBox

Returns

The created/reinitialized SVG element

createGrid

deprecated1.xSource
function createGrid(position: number, index: number, axis: Axis, offset: number, length: number, group: Svg, classes: string[], eventEmitter: EventEmitter): void

Creates a grid line based on a projected value.

Deprecated. Use the axisGrid() layer. Removed in 3.0.

Parameters

position number
index number
axis Axis
offset number
length number
group Svg
classes string[]
eventEmitter EventEmitter

createGridBackground

deprecated1.xSource
function createGridBackground(gridGroup: Svg, chartRect: ChartRect, className: string, eventEmitter: EventEmitter): void

Creates a grid background rect and emits the draw event.

Deprecated. Use the axisGrid() layer. Removed in 3.0.

Parameters

gridGroup Svg
chartRect ChartRect
className string
eventEmitter EventEmitter

createLabel

deprecated1.xSource
function createLabel(position: number, length: number, index: number, label: Label, axis: Axis, axisOffset: number, labelOffset: { x: number; y: number }, group: Svg, classes: string[], eventEmitter: EventEmitter): void

Creates a label based on a projected value and an axis.

Deprecated. Use the axisLabels() layer. Removed in 3.0.

Parameters

position number
length number
index number
label Label
axis Axis
axisOffset number
labelOffset { x: number; y: number }
group Svg
classes string[]
eventEmitter EventEmitter

optionsProvider

deprecated1.xSource
function optionsProvider<T = unknown>(options: T, responsiveOptions: ResponsiveOptions<T> | undefined, eventEmitter: EventEmitter): OptionsProvider<T>

Provides options handling functionality with callback for options changes triggered by responsive options and media query matches

Deprecated. Part of the 1.x chart classes. Responsive options are an argument of the chart functions. Removed in 3.0.

Parameters

options T

Options set by user

responsiveOptions ResponsiveOptions<T> | undefined

Optional functions to add responsive behavior to chart

eventEmitter EventEmitter

The event emitter that will be used to emit the options changed events

Returns

The consolidated options object from the defaults, base and matching responsive options

AutoScaleAxis

deprecated1.xSource
class AutoScaleAxis extends Axis
new AutoScaleAxis(axisUnit: AxisUnits, data: NormalizedSeries[], chartRect: ChartRect, options: AxisOptions)

The 1.x axis with a scale fitted to the values, in round steps at least scaleMinSpace px apart.

Deprecated. Use autoScaleAxis(). Removed in 3.0.

Axis

deprecated1.xSource
class Axis
new Axis(units: AxisUnits, chartRect: ChartRect, ticks: Label[])

The base class of the 1.x axes: projects values to px along the drawing area and draws its grid lines and labels.

Deprecated. Use the scale functions autoScaleAxis(), fixedScaleAxis() and stepAxis(). Removed in 3.0.

FixedScaleAxis

deprecated1.xSource
class FixedScaleAxis extends Axis
new FixedScaleAxis(axisUnit: AxisUnits, data: NormalizedSeries[], chartRect: ChartRect, options: AxisOptions)

The 1.x axis with fixed ticks: the ticks option, or divisor equal steps from low to high, with a tick at both ends.

Deprecated. Use fixedScaleAxis(). Removed in 3.0.

StepAxis

deprecated1.xSource
class StepAxis extends Axis
new StepAxis(axisUnit: AxisUnits, _data: unknown, chartRect: ChartRect, options: AxisOptions)

The 1.x axis with one step per tick, such as the labels of a line chart's X axis.

Deprecated. Use stepAxis(). Removed in 3.0.

EventEmitter

deprecated1.xSource
class EventEmitter
new EventEmitter()

The 1.x event emitter: on, off and emit by event name, with '*' for all events.

Deprecated. Use the chart handle's on() and off(). Removed in 3.0.

AxisType

deprecated1.xSource
type AxisType = typeof AutoScaleAxis | typeof FixedScaleAxis | typeof StepAxis

The 1.x axis classes an axis's type option takes: AutoScaleAxis, FixedScaleAxis or StepAxis.

Deprecated. Use the scale functions autoScaleAxis(), fixedScaleAxis() and stepAxis(). Removed in 3.0.

BarChartOptions

deprecated1.xSource
interface BarChartOptions<TXAxisOptions = AxisOptions, TYAxisOptions = TXAxisOptions> extends Options<TXAxisOptions, TYAxisOptions>

The options of a bar chart (1.x BarChart, and barChart).

Deprecated. For barChart(), the options type is BarChartPresetOptions. Removed in 3.0.

Properties

classNames? { … }

The class names of the chart's elements. Change them to style the chart with your own CSS instead of Chartist's.

classNames.chart? string default 'ct-chart-bar'

The chart's SVG element.

classNames.horizontalBars? string default 'ct-horizontal-bars'

The chart's SVG element, with horizontalBars.

classNames.label? string default 'ct-label'

Each axis label.

classNames.labelGroup? string default 'ct-labels'

The group of an axis's labels.

classNames.series? string default 'ct-series'

The group of each series.

classNames.bar? string default 'ct-bar'

Each bar.

classNames.grid? string default 'ct-grid'

Each grid line.

classNames.gridGroup? string default 'ct-grids'

The group of the grid lines.

classNames.gridBackground? string default 'ct-grid-background'

The grid background (with showGridBackground).

classNames.vertical? string default 'ct-vertical'

Labels and grid lines of the vertical axis.

classNames.horizontal? string default 'ct-horizontal'

Labels and grid lines of the horizontal axis.

classNames.start? string default 'ct-start'

Labels at the start of their axis (left or top).

classNames.end? string default 'ct-end'

Labels at the end of their axis (right or bottom).

seriesBarDistance? number default 15

The distance in px between the bars of a group (one bar per series).

stackBars? boolean default false

Stacks the bars of a group on each other; stackMode says how.

stackMode? boolean | 'accumulate' | 'accumulate-relative' default 'accumulate'

How stacked bars stack: accumulate adds up each group's values (the value axis fits the totals), accumulate-relative stacks positive values up and negative values down, and true draws every bar from zero, overlapping.

horizontalBars? boolean default false

Draws horizontal bars. The axes swap: the Y axis shows the labels and the X axis the values, so swap their options too.

distributeSeries? boolean default false

Treats one flat array of values as one series per value, each in its own color: a profile rather than values over time.

reverseData? boolean default false

Reverses the labels, the order of the series and each series' values.

showGridBackground? boolean default false

Fills the grid area with a background (class ct-grid-background).

width? string | number

The chart's width: px as a number, or a CSS length such as '100%'. Without it, the chart takes the width of its container.

height? string | number

The chart's height: px as a number, or a CSS length such as '300px'. Without it, the chart takes the height of its container.

low? number

The lowest value the value axis shows, instead of the data's lowest. Values below it are drawn outside the drawing area.

high? number

The highest value the value axis shows, instead of the data's highest. Values above it are drawn outside the drawing area.

referenceValue? number default 0

A value the value axis always includes, such as 0, so it shows even when all values are above or below it. Bar charts use 0.

chartPadding? number | Partial<ChartPadding> default { top: 15, right: 15, bottom: 5, left: 10 }

Space in px between the chart's edges and its drawing area (labels sit in it): one number for every side, or an object with some sides.

axisX? TXAxisOptions default { offset: 30, position: 'end', labelOffset: { x: 0, y: 0 }, showLabel: true, showGrid: true, scaleMinSpace: 30, onlyInteger: false }

Options of the X axis.

axisY? TYAxisOptions default { offset: 40, position: 'start', labelOffset: { x: 0, y: 0 }, showLabel: true, showGrid: true, scaleMinSpace: 20, onlyInteger: false }

Options of the Y axis.

plugins? (Plugin | [Plugin, any] | { readonly name: string; install: (chart: any, options?: any) => void })[]

1.x plugin functions (they run with the compat plugin) and v2 plugins such as compat.

viewBox? ViewBox

A viewBox for the SVG, so the drawing scales with its box instead of being drawn for its size. Text scales too: adjust it with responsive options.

viewBox.width number

The viewBox width, in SVG units.

viewBox.height number

The viewBox height, in SVG units.

BarChartOptionsWithDefaults

deprecated1.xSource
type BarChartOptionsWithDefaults = RequiredKeys<BarChartOptions<RequiredKeys<AxisOptions, 'offset' | 'position' | 'labelOffset' | 'showLabel' | 'showGrid' | 'labelInterpolationFnc' | 'scaleMinSpace'>, RequiredKeys<AxisOptions, 'offset' | 'position' | 'labelOffset' | 'showLabel' | 'showGrid' | 'labelInterpolationFnc' | 'scaleMinSpace'>>, 'referenceValue' | 'chartPadding' | 'seriesBarDistance' | 'stackMode' | 'axisX' | 'axisY', 'classNames'>

BarChartOptions after the defaults are applied: the 1.x BarChart works with these.

Deprecated. The resolved options of the 1.x BarChart. Removed in 3.0.

BarChartCreatedEvent

deprecated1.xSource
type BarChartCreatedEvent = CreatedEvent<BarChartOptions>

The payload of a bar chart's 1.x created event.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

svg Svg

The chart's SVG element, wrapped in Svg.

options TOptions

The options the chart was drawn with, defaults and responsive options applied.

BarDrawEvent

deprecated1.xSource
interface BarDrawEvent extends DrawEvent

The 1.x draw event of a bar, one per value. The bar is a line element from its base (x1, y1) to its value (x2, y2).

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'bar'

Always 'bar'.

value number | NormalizedMulti

The bar's normalized value: a number, or { x, y } numbers.

x1 number

The x of the bar's base, in px.

y1 number

The y of the bar's base, in px.

x2 number

The x of the bar's end (its value), in px.

y2 number

The y of the bar's end (its value), in px.

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

meta any

The meta of the value (or of the series, for lines and areas).

index number

The index of the value in its series (of the series, for lines and areas).

series SeriesObject<SeriesPrimitiveValue> | FlatSeriesValue<FlatSeriesPrimitiveValue> | Series<SeriesPrimitiveValue>

The series as given in the data: an array or a series object.

seriesIndex number

The index of the series in the data.

BarChartEventsTypes

deprecated1.xSource
type BarChartEventsTypes = BaseChartEventsTypes<BarChartCreatedEvent, AxesDrawEvent | BarDrawEvent>

The 1.x events of a BarChart and their payloads, by event name.

Deprecated. The 1.x events of a BarChart. On barChart(), the handle's on() knows its events. Removed in 3.0.

LineInterpolation

1.xSource
type LineInterpolation = (pathCoordinates: number[], valueData: SegmentData[]) => SvgPath

Turns a series' points into the path of its line (see Interpolation).

LineChartOptions

deprecated1.xSource
interface LineChartOptions<TXAxisOptions = AxisOptions, TYAxisOptions = TXAxisOptions> extends Options<TXAxisOptions, TYAxisOptions>

The options of a line chart (1.x LineChart, and lineChart).

Deprecated. For lineChart(), the options type is LineChartPresetOptions. Removed in 3.0.

Properties

classNames? { … }

The class names of the chart's elements. Change them to style the chart with your own CSS instead of Chartist's.

classNames.chart? string default 'ct-chart-line'

The chart's SVG element.

classNames.label? string default 'ct-label'

Each axis label.

classNames.labelGroup? string default 'ct-labels'

The group of an axis's labels.

classNames.series? string default 'ct-series'

The group of each series.

classNames.line? string default 'ct-line'

Each line.

classNames.point? string default 'ct-point'

Each point.

classNames.area? string default 'ct-area'

Each area.

classNames.grid? string default 'ct-grid'

Each grid line.

classNames.gridGroup? string default 'ct-grids'

The group of the grid lines.

classNames.gridBackground? string default 'ct-grid-background'

The grid background (with showGridBackground).

classNames.vertical? string default 'ct-vertical'

Labels and grid lines of the vertical axis.

classNames.horizontal? string default 'ct-horizontal'

Labels and grid lines of the horizontal axis.

classNames.start? string default 'ct-start'

Labels at the start of their axis (left or top).

classNames.end? string default 'ct-end'

Labels at the end of their axis (right or bottom).

showLine? boolean default true

Draws the lines.

showPoint? boolean default true

Draws a point at each value.

showArea? boolean default false

Fills the area between each line and areaBase.

areaBase? number default 0

The value the areas close at, usually 0.

lineSmooth? boolean | LineInterpolation default true

How a line runs between its points: true smooths it with Interpolation.monotoneCubic, false draws straight segments (Interpolation.none), or pass an interpolation such as Interpolation.cardinal(), Interpolation.step() or your own.

showGridBackground? boolean default false

Fills the grid area with a background (class ct-grid-background).

fullWidth? boolean default false

Stretches the X axis so the last value lands on the right edge, without a last grid line. The last label may need chart padding to fit.

reverseData? boolean default false

Reverses the labels, the order of the series and each series' values.

series? Record<string, Omit<LineChartOptions<TXAxisOptions, TYAxisOptions>, 'series'>>

Options per series, by series name: line options for one series.

width? string | number

The chart's width: px as a number, or a CSS length such as '100%'. Without it, the chart takes the width of its container.

height? string | number

The chart's height: px as a number, or a CSS length such as '300px'. Without it, the chart takes the height of its container.

low? number

The lowest value the value axis shows, instead of the data's lowest. Values below it are drawn outside the drawing area.

high? number

The highest value the value axis shows, instead of the data's highest. Values above it are drawn outside the drawing area.

referenceValue? number

A value the value axis always includes, such as 0, so it shows even when all values are above or below it. Bar charts use 0.

chartPadding? number | Partial<ChartPadding> default { top: 15, right: 15, bottom: 5, left: 10 }

Space in px between the chart's edges and its drawing area (labels sit in it): one number for every side, or an object with some sides.

axisX? TXAxisOptions default { offset: 30, position: 'end', labelOffset: { x: 0, y: 0 }, showLabel: true, showGrid: true }

Options of the X axis.

axisY? TYAxisOptions default { offset: 40, position: 'start', labelOffset: { x: 0, y: 0 }, showLabel: true, showGrid: true, scaleMinSpace: 20, onlyInteger: false }

Options of the Y axis.

plugins? (Plugin | [Plugin, any] | { readonly name: string; install: (chart: any, options?: any) => void })[]

1.x plugin functions (they run with the compat plugin) and v2 plugins such as compat.

viewBox? ViewBox

A viewBox for the SVG, so the drawing scales with its box instead of being drawn for its size. Text scales too: adjust it with responsive options.

viewBox.width number

The viewBox width, in SVG units.

viewBox.height number

The viewBox height, in SVG units.

LineChartOptionsWithDefaults

deprecated1.xSource
type LineChartOptionsWithDefaults = RequiredKeys<LineChartOptions<RequiredKeys<AxisOptions, 'offset' | 'position' | 'labelOffset' | 'showLabel' | 'showGrid' | 'labelInterpolationFnc'>, RequiredKeys<AxisOptions, 'offset' | 'position' | 'labelOffset' | 'showLabel' | 'showGrid' | 'labelInterpolationFnc' | 'scaleMinSpace'>>, 'showLine' | 'showPoint' | 'areaBase' | 'lineSmooth' | 'chartPadding' | 'axisX' | 'axisY', 'classNames'>

LineChartOptions after the defaults are applied: the 1.x LineChart works with these.

Deprecated. The resolved options of the 1.x LineChart. Removed in 3.0.

LineChartCreatedEvent

deprecated1.xSource
type LineChartCreatedEvent = CreatedEvent<LineChartOptions>

The payload of a line chart's 1.x created event.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

svg Svg

The chart's SVG element, wrapped in Svg.

options TOptions

The options the chart was drawn with, defaults and responsive options applied.

PointDrawEvent

deprecated1.xSource
interface PointDrawEvent extends DrawEvent

The 1.x draw event of a line chart's point, one per value. The point is a very short line element at x, y (CSS gives it a round cap).

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'point'

Always 'point'.

value NormalizedSeriesPrimitiveValue

The point's normalized value: { x, y } numbers, or a number.

x number

The point's x, in px.

y number

The point's y, in px.

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

meta any

The meta of the value (or of the series, for lines and areas).

index number

The index of the value in its series (of the series, for lines and areas).

series SeriesObject<SeriesPrimitiveValue> | FlatSeriesValue<FlatSeriesPrimitiveValue> | Series<SeriesPrimitiveValue>

The series as given in the data: an array or a series object.

seriesIndex number

The index of the series in the data.

LineDrawEvent

deprecated1.xSource
interface LineDrawEvent extends DrawEvent

The 1.x draw event of a line, one per series. index is the series' index and meta the series' meta.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'line'

Always 'line'.

values NormalizedSeries

All normalized values of the series.

path SvgPath

The line's path as drawn (a copy, safe to change).

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

meta any

The meta of the value (or of the series, for lines and areas).

index number

The index of the value in its series (of the series, for lines and areas).

series SeriesObject<SeriesPrimitiveValue> | FlatSeriesValue<FlatSeriesPrimitiveValue> | Series<SeriesPrimitiveValue>

The series as given in the data: an array or a series object.

seriesIndex number

The index of the series in the data.

AreaDrawEvent

deprecated1.xSource
interface AreaDrawEvent extends DrawEvent

The 1.x draw event of an area (with showArea), one per series and segment. index is the series' index and meta the series' meta.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'area'

Always 'area'.

values NormalizedSeries

All normalized values of the series.

path SvgPath

The area's path as drawn (a copy, safe to change).

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

meta any

The meta of the value (or of the series, for lines and areas).

index number

The index of the value in its series (of the series, for lines and areas).

series SeriesObject<SeriesPrimitiveValue> | FlatSeriesValue<FlatSeriesPrimitiveValue> | Series<SeriesPrimitiveValue>

The series as given in the data: an array or a series object.

seriesIndex number

The index of the series in the data.

LineChartEventsTypes

deprecated1.xSource
type LineChartEventsTypes = BaseChartEventsTypes<LineChartCreatedEvent, AxesDrawEvent | PointDrawEvent | LineDrawEvent | AreaDrawEvent>

The 1.x events of a LineChart and their payloads, by event name.

Deprecated. The 1.x events of a LineChart. On lineChart(), the handle's on() knows its events. Removed in 3.0.

LabelDirection

1.xSource
type LabelDirection = 'implode' | 'neutral' | 'explode'

Which way pie labels anchor: see labelDirection in PieChartOptions.

AnchorPosition

1.xSource
type AnchorPosition = 'start' | 'middle' | 'end'

The text-anchor of a pie label: 'start', 'middle' or 'end'.

RadialLabelPosition

1.xSource
type RadialLabelPosition = 'inside' | 'center' | 'outside'

Where pie labels go: see labelPosition in PieChartOptions.

Dot

1.xSource
interface Dot

A point in px, such as the center of a pie.

Properties

x number

The x, in px.

y number

The y, in px.

PieChartOptions

deprecated1.xSource
interface PieChartOptions extends Omit<Options, 'axisX' | 'axisY'>

The options of a pie or donut chart (1.x PieChart, and pieChart).

Deprecated. For pieChart(), the options type is PieChartPresetOptions. Removed in 3.0.

Properties

classNames? { … }

The class names of the chart's elements. Change them to style the chart with your own CSS instead of Chartist's.

classNames.chartPie? string default 'ct-chart-pie'

The chart's SVG element, for pies.

classNames.chartDonut? string default 'ct-chart-donut'

The chart's SVG element, for donuts.

classNames.series? string default 'ct-series'

The group of each series.

classNames.slicePie? string default 'ct-slice-pie'

Each pie slice.

classNames.sliceDonut? string default 'ct-slice-donut'

Each donut slice.

classNames.label? string default 'ct-label'

Each axis label.

startAngle? number default 0

Where the first slice starts, in degrees clockwise from the top.

total? number

The value a full circle stands for. With a total above the sum of the values, the pie stays open, as for a gauge.

donut? boolean default false

Draws a donut: rings instead of filled slices.

donutWidth? string | number

The width of a donut's ring: px as a number, or a share of the radius as a string ('30%'). Without it, the stylesheet sets the width (--ct-donut-width, 60px by default), and in the browser the ring is laid out for the width the stylesheet gives a slice. Without a DOM (renderToString()), it's laid out for 60 px.

showLabel? boolean default true

Draws a label for each slice.

labelOffset? number default 0

Moves the labels away from the center (positive) or toward it (negative), in px.

labelPosition? RadialLabelPosition default 'inside'

Where labels go: inside (halfway out on a pie, on the middle of a donut's ring, plus labelOffset), outside (at the outer edge) or center (in the middle; move them with labelOffset).

labelInterpolationFnc? (value: Label, index: number) => Label | null | undefined

Turns each slice's label (or value) and index into the text to show. Return null or undefined to leave a label out.

labelDirection? LabelDirection default 'neutral'

Which way labels anchor: neutral, explode (away from the center, for labels outside the pie) or implode (toward it).

ignoreEmptyValues? boolean default false

Leaves out the slices and labels of empty values.

preventOverlappingLabelOffset? number default 0

Moves labels apart so they don't overlap, using this offset in px. The overlap is judged by the length of the drawn label text. 0 leaves them where they are.

width? string | number

The chart's width: px as a number, or a CSS length such as '100%'. Without it, the chart takes the width of its container.

height? string | number

The chart's height: px as a number, or a CSS length such as '300px'. Without it, the chart takes the height of its container.

low? number

The lowest value the value axis shows, instead of the data's lowest. Values below it are drawn outside the drawing area.

high? number

The highest value the value axis shows, instead of the data's highest. Values above it are drawn outside the drawing area.

referenceValue? number

A value the value axis always includes, such as 0, so it shows even when all values are above or below it. Bar charts use 0.

chartPadding? number | Partial<ChartPadding> default { top: 5, right: 5, bottom: 5, left: 5 }

Space in px between the chart's edges and its drawing area (labels sit in it): one number for every side, or an object with some sides.

plugins? (Plugin | [Plugin, any] | { readonly name: string; install: (chart: any, options?: any) => void })[]

1.x plugin functions (they run with the compat plugin) and v2 plugins such as compat.

viewBox? ViewBox

A viewBox for the SVG, so the drawing scales with its box instead of being drawn for its size. Text scales too: adjust it with responsive options.

viewBox.width number

The viewBox width, in SVG units.

viewBox.height number

The viewBox height, in SVG units.

PieChartOptionsWithDefaults

deprecated1.xSource
type PieChartOptionsWithDefaults = RequiredKeys<PieChartOptions, 'chartPadding' | 'startAngle' | 'showLabel' | 'labelOffset' | 'labelPosition' | 'labelInterpolationFnc' | 'labelDirection' | 'preventOverlappingLabelOffset', 'classNames'>

PieChartOptions after the defaults are applied: the 1.x PieChart works with these.

Deprecated. The resolved options of the 1.x PieChart. Removed in 3.0.

PieChartCreatedEvent

deprecated1.xSource
type PieChartCreatedEvent = Omit<CreatedEvent<PieChartOptions>, 'axisX' | 'axisY'>

The payload of a pie chart's 1.x created event: as for other charts, without axes.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

chartRect ChartRect

The drawing area, in px.

svg Svg

The chart's SVG element, wrapped in Svg.

options TOptions

The options the chart was drawn with, defaults and responsive options applied.

SliceDrawEvent

deprecated1.xSource
interface SliceDrawEvent extends Omit<DrawEvent, 'axisX' | 'axisY' | 'seriesIndex'>

The 1.x draw event of a pie or donut slice, one per value. index is the slice's index and series its value as given in the data.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'slice'

Always 'slice'.

totalDataSum number

The value of the full circle: the sum of all values, or the total option.

path SvgPath

The slice's path as drawn (a copy, safe to change).

center Dot

The center of the pie, in px.

radius number

The radius of the pie, in px.

startAngle number

Where the slice starts, in degrees clockwise from the top.

endAngle number

Where the slice ends, in degrees clockwise from the top.

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

chartRect ChartRect

The drawing area, in px.

meta any

The meta of the value (or of the series, for lines and areas).

index number

The index of the value in its series (of the series, for lines and areas).

series SeriesObject<SeriesPrimitiveValue> | FlatSeriesValue<FlatSeriesPrimitiveValue> | Series<SeriesPrimitiveValue>

The series as given in the data: an array or a series object.

SliceLabelDrawEvent

deprecated1.xSource
interface SliceLabelDrawEvent extends Omit<DrawEvent, 'axisX' | 'axisY' | 'seriesIndex'>

The 1.x draw event of a pie slice's label. index is the slice's index; the label is a text element anchored at x, y.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'label'

Always 'label'.

text string

The label as shown, after labelInterpolationFnc.

x number

The x the label is anchored at, in px.

y number

The y the label is anchored at, in px.

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

chartRect ChartRect

The drawing area, in px.

meta any

The meta of the value (or of the series, for lines and areas).

index number

The index of the value in its series (of the series, for lines and areas).

series SeriesObject<SeriesPrimitiveValue> | FlatSeriesValue<FlatSeriesPrimitiveValue> | Series<SeriesPrimitiveValue>

The series as given in the data: an array or a series object.

PieChartEventsTypes

deprecated1.xSource
type PieChartEventsTypes = BaseChartEventsTypes<PieChartCreatedEvent, SliceDrawEvent | SliceLabelDrawEvent>

The 1.x events of a PieChart and their payloads, by event name.

Deprecated. The 1.x events of a PieChart. On pieChart(), the handle's on() knows its events. Removed in 3.0.

BaseChartEventsTypes

deprecated1.xSource
interface BaseChartEventsTypes<TCreateEvent = CreatedEvent, TDrawEvents = DrawEvent>

The 1.x events every chart class emits and their payloads, by event name.

Deprecated. The 1.x events of the chart classes. On the chart functions, the handle's on() knows its events. Removed in 3.0.

OptionsProvider

deprecated1.xSource
interface OptionsProvider<T = unknown>

What optionsProvider returns: the current options, and a way to stop listening to media queries.

Deprecated. Part of the 1.x chart classes. Responsive options are an argument of the chart functions. Removed in 3.0.

Properties

ChartPadding

1.xSource
interface ChartPadding

Space in px between the chart's edges and its drawing area, per side.

Properties

top number

Space above the drawing area, in px.

right number

Space right of the drawing area, in px.

bottom number

Space below the drawing area, in px.

left number

Space left of the drawing area, in px.

Plugin

deprecated1.xSource
type Plugin = (chart: any, options?: any) => void

A 1.x plugin: a function that gets the chart object (and its options) and registers listeners with chart.on('draw', …). It runs with the compat plugin from chartist/compat, whose fromLegacyPlugin() also turns it into a v2 plugin.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Options

deprecated1.xSource
interface Options<TXAxisOptions = AxisOptions, TYAxisOptions = TXAxisOptions>

The options all 1.x charts share: size, value range, padding, axes, class names and plugins. LineChartOptions, BarChartOptions and PieChartOptions build on them.

Deprecated. The base options of the 1.x chart classes. Use the options type of the chart function. Removed in 3.0.

Properties

width? string | number

The chart's width: px as a number, or a CSS length such as '100%'. Without it, the chart takes the width of its container.

height? string | number

The chart's height: px as a number, or a CSS length such as '300px'. Without it, the chart takes the height of its container.

low? number

The lowest value the value axis shows, instead of the data's lowest. Values below it are drawn outside the drawing area.

high? number

The highest value the value axis shows, instead of the data's highest. Values above it are drawn outside the drawing area.

referenceValue? number

A value the value axis always includes, such as 0, so it shows even when all values are above or below it. Bar charts use 0.

chartPadding? number | Partial<ChartPadding>

Space in px between the chart's edges and its drawing area (labels sit in it): one number for every side, or an object with some sides.

axisX? TXAxisOptions

Options of the X axis.

axisY? TYAxisOptions

Options of the Y axis.

classNames? Record<string, string>

The class names of the chart's elements, to style a chart with your own classes instead of Chartist's.

plugins? (Plugin | [Plugin, any] | { readonly name: string; install: (chart: any, options?: any) => void })[]

1.x plugin functions (they run with the compat plugin) and v2 plugins such as compat.

viewBox? ViewBox

A viewBox for the SVG, so the drawing scales with its box instead of being drawn for its size. Text scales too: adjust it with responsive options.

AxisOptions

1.xSource
interface AxisOptions

The options of one axis of a line or bar chart.

Properties

type? AxisType

The axis type: StepAxis (one step per label), AutoScaleAxis (a scale fitted to the values) or FixedScaleAxis (fixed ticks).

low? number

The lowest value this axis shows, instead of the data's lowest.

high? number

The highest value this axis shows, instead of the data's highest.

referenceValue? number

A value this axis always includes, such as 0.

offset? number

Room in px for the axis labels, between the drawing area and the chart's edge.

position? 'end' | 'start'

Where the labels go: start (left or top) or end (right or bottom).

labelOffset? { x: number; y: number }

Moves the labels by x and y px from where they'd go.

showLabel? boolean

Draws the axis labels.

showGrid? boolean

Draws the grid lines of the axis.

labelInterpolationFnc? (value: Label, index: number) => Label | null | undefined

Turns each label (and its index) into the text to show. Return null or undefined to leave a label out.

scaleMinSpace? number

The minimum space in px between two grid lines of a scale: the scale takes fewer, larger steps to keep it.

onlyInteger? boolean

Only whole numbers on the scale.

ticks? Label[]

The ticks: the labels of a step axis, or the values of a fixed scale axis.

stretch? boolean

Step axis: spreads the ticks over the whole axis, so the last one lands on its end (line charts with fullWidth set it).

divisor? number

Fixed scale axis without ticks: the number of equal steps between its low and high, with a tick at each end.

highLow? { high: number; low: number }

The value range of a scale as { high, low }, instead of the one computed from the data.

OptionsWithDefaults

deprecated1.xSource
type OptionsWithDefaults = RequiredKeys<Options<RequiredKeys<AxisOptions, 'offset' | 'labelOffset' | 'labelInterpolationFnc'>, RequiredKeys<AxisOptions, 'offset' | 'labelOffset' | 'labelInterpolationFnc'>>, 'axisX' | 'axisY' | 'classNames'>

Options after the defaults are applied: the axes and class names are set.

Deprecated. The resolved options of the 1.x chart classes. Removed in 3.0.

ResponsiveOptions

deprecated1.xSource
type ResponsiveOptions<T = Options> = [string, T][]

The 1.x responsive options: [mediaQuery, options] pairs, applied over the chart's options while the media query matches.

Deprecated. For the chart functions, the type is PresetResponsiveOptions. Removed in 3.0.

CreatedEvent

deprecated1.xSource
interface CreatedEvent<TOptions = Options>

The payload of the 1.x created event, emitted once a chart is drawn: its SVG, drawing area, axes and options.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

svg Svg

The chart's SVG element, wrapped in Svg.

options TOptions

The options the chart was drawn with, defaults and responsive options applied.

DrawEvent

deprecated1.xSource
interface DrawEvent

The fields every 1.x draw event shares. A draw listener gets one per element drawn; check type to tell them apart.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type string

What was drawn: 'point', 'line', 'bar', 'grid', …

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

chartRect ChartRect

The drawing area, in px.

axisX Axis

The X axis, a 1.x Axis object.

axisY Axis

The Y axis, a 1.x Axis object.

meta any

The meta of the value (or of the series, for lines and areas).

index number

The index of the value in its series (of the series, for lines and areas).

series SeriesObject<SeriesPrimitiveValue> | FlatSeriesValue<FlatSeriesPrimitiveValue> | Series<SeriesPrimitiveValue>

The series as given in the data: an array or a series object.

seriesIndex number

The index of the series in the data.

DataEvent

deprecated1.xSource
interface DataEvent

The payload of the 1.x data event, emitted before a chart draws new data. Listeners may change data in place to transform it.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'initial' | 'update'

'initial' for the first data, 'update' for data set later.

data Data

The data the chart is about to draw (a copy, safe to change).

OptionsChangedEvent

deprecated1.xSource
interface OptionsChangedEvent<T = Options>

The payload of the 1.x optionsChanged event, emitted when a responsive option starts or stops applying.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

previousOptions T

The options before the change.

currentOptions T

The options now in effect.

GridDrawEvent

deprecated1.xSource
interface GridDrawEvent extends Omit<DrawEvent, 'chartRect' | 'axisX' | 'axisY' | 'meta' | 'series' | 'seriesIndex'>

The 1.x draw event of a grid line, one per tick of each axis. x1, y1, x2, y2 are the line's ends in px.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

index number

The index of the value in its series (of the series, for lines and areas).

type 'grid'

Always 'grid'.

axis Axis

The axis the grid line belongs to.

x1 number

The x of the line's start, in px.

y1 number

The y of the line's start, in px.

x2 number

The x of the line's end, in px.

y2 number

The y of the line's end, in px.

GridBackgroundDrawEvent

deprecated1.xSource
interface GridBackgroundDrawEvent

The 1.x draw event of the grid background, the rect behind the drawing area (with showGridBackground).

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

type 'gridBackground'

Always 'gridBackground'.

group Svg

The grid group the background is in.

element Svg

The background rect.

LabelDrawEvent

deprecated1.xSource
interface LabelDrawEvent extends Omit<DrawEvent, 'chartRect' | 'axisX' | 'axisY' | 'meta' | 'series' | 'seriesIndex'>

The 1.x draw event of an axis label, one per tick. The label is a foreignObject with a span, placed at x, y with the given size.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

Properties

element Svg

The drawn element, wrapped in Svg: change or animate it here.

group Svg

The group the element is in, wrapped in Svg.

index number

The index of the value in its series (of the series, for lines and areas).

type 'label'

Always 'label'.

axis Axis

The axis the label belongs to.

text Label

The label as shown, after labelInterpolationFnc.

x number

The x of the label's box, in px.

y number

The y of the label's box, in px.

width number

The width of the label's box, in px.

height number

The height of the label's box, in px.

AxesDrawEvent

deprecated1.xSource
type AxesDrawEvent = GridDrawEvent | GridBackgroundDrawEvent | LabelDrawEvent

The 1.x draw events of the axes: grid lines, the grid background and labels.

Deprecated. Import it from chartist/compat, which turns on the 1.x events and plugins. Removed in 3.0.

EventListener

deprecated1.xSource
type EventListener<T = any> = (data: T) => void

A listener of one event: gets the event's payload.

Deprecated. Use the chart handle's on() and off(). Removed in 3.0.

AllEventsListener

deprecated1.xSource
type AllEventsListener<T = any> = (event: string, data: T) => void

A listener of every event ('*'): gets the event's name and payload.

Deprecated. Use the chart handle's on() and off(). Removed in 3.0.