
Chartist is a JavaScript charting library that creates responsive line, bar, pie, and donut charts as SVG.
It also supports stacked bars, multi-axis charts, and mixed bar-and-line plots, with chart colors, strokes, and labels controlled through CSS.
Features
- Multiple series, value metadata, and explicit XY coordinates.
- Line charts with areas, smoothing, gaps, and XY data.
- Grouped, stacked, distributed, and horizontal bar charts.
- Pie charts, donuts, and partial-circle gauges.
- Mixed chart layers with independent axes.
- Media-query options and experimental container-query options.
- Dynamic data updates, lifecycle events, and plugins.
- Optional live DOM updates, animation, and server-side SVG rendering.
How To Use It
Installation
Include Chartist’s CSS file and import the JavaScript module.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/chartist/dist/index.min.css">
<div id="traffic-chart" class="ct-golden-section"></div>
<script type="module">
import { lineChart } from 'https://cdn.jsdelivr.net/npm/chartist/dist/index.min.js';
lineChart('#traffic-chart', {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
series: [[24, 38, 31, 46, 41]]
});
</script>
You can also install the package through npm.
npm install chartist
import 'chartist/styles.css';
import { lineChart } from 'chartist';
Basic Usage
Each preset takes a container selector or element, chart data, optional configuration, and optional responsive overrides. Create an HTML container for each chart ID shown in these examples.
The required data object has a series property. Line and bar charts use nested arrays.
<div id="line-chart" class="ct-golden-section"></div>
<div id="bar-chart" class="ct-golden-section"></div>
<div id="pie-chart" class="ct-square"></div>
import { barChart, lineChart, pieChart } from 'chartist';
lineChart('#line-chart', {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
series: [[18, 27, 24, 39], [12, 19, 21, 31]]
});
barChart('#bar-chart', {
labels: ['HTML', 'CSS', 'JavaScript'],
series: [[42, 35, 28]]
}, { horizontalBars: true });
pieChart('#pie-chart', {
labels: ['Desktop', 'Tablet', 'Mobile'],
series: [50, 15, 35]
}, { donut: true });
Advanced Examples
Create a stacked bar chart
stackBars stacks values at each category. For data with both positive and negative numbers, stackMode: 'accumulate-relative' keeps the stacks on opposite sides of zero.
import { barChart } from 'chartist';
barChart('#sales-chart', {
labels: ['Jan', 'Feb', 'Mar'],
series: [[8, 11, 9], [4, 7, 5]]
}, {
stackBars: true,
stackMode: 'accumulate',
axisY: { low: 0 }
});
Create a mixed bar and line chart
Use chart() when each series needs a different drawing layer or value axis. Supply each axis with an ID, then connect the corresponding layers through x and y.
import {
autoScaleAxis, axisGrid, axisLabels, bar,
cartesianAxes, chart, line, stepAxis
} from 'chartist';
chart('#overview-chart', {
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr'],
series: [
{ name: 'orders', data: [80, 95, 110, 125] },
{ name: 'returns', data: [4, 3, 7, 5] }
]
},
axes: cartesianAxes([
{ id: 'month', side: 'bottom', type: stepAxis() },
{ id: 'orders', side: 'left', type: autoScaleAxis(), low: 0 },
{ id: 'returns', side: 'right', type: autoScaleAxis(), low: 0 }
]),
layers: [
axisGrid({ axes: ['month', 'orders'] }),
bar({ series: ['orders'], x: 'month', y: 'orders' }),
line({ series: ['returns'], x: 'month', y: 'returns', align: 'center' }),
axisLabels()
]
});
Draw a goal line on a bar chart
A goal or threshold is useful when a chart needs to show performance against a fixed value. The built-in targetLine() layer can appear above the data in either a bar or line preset.
import { barChart, targetLine } from 'chartist';
barChart('#goal-chart', {
labels: ['Jan', 'Feb', 'Mar', 'Apr'],
series: [[820, 950, 1100, 980]]
}, {
low: 0,
layers: {
above: [targetLine({ value: 1000, label: 'Goal' })]
}
});
Change chart options at smaller screen widths
The fourth argument of a preset accepts [mediaQuery, options] pairs. A narrower rule can override values from an earlier rule. Container-query conditions require the separate match-container polyfill and CSS container-type.
import { lineChart } from 'chartist';
lineChart(
'#weekly-chart',
{ labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], series: [[8, 10, 6, 12, 11]] },
{ showArea: true, axisY: { low: 0 } },
[
['(max-width: 640px)', { showPoint: false }],
['(max-width: 400px)', { axisX: { showLabel: false } }]
]
);
Update a chart with new data
Keep the chart handle returned by a preset. Call update() with a configuration object to replace chart data, and setOptions() to change preset options.
import { lineChart } from 'chartist';
const salesChart = lineChart('#sales-chart', {
labels: ['Jan', 'Feb', 'Mar'],
series: [[12, 15, 19]]
});
salesChart.update({
data: { labels: ['Apr', 'May', 'Jun'], series: [[16, 23, 21]] }
});
salesChart.setOptions({ showArea: true });
Animate live chart updates
Chartist’s standard renderer creates a new SVG during updates. The experimental liveDomRenderer() updates existing SVG elements, and smilAnimations() animates changes to bars, lines, points, areas, and pie slices.
import { barChart } from 'chartist';
import { liveDomRenderer, smilAnimations } from 'chartist/live';
const chartHandle = barChart('#live-chart', {
labels: ['Q1', 'Q2', 'Q3'],
series: [[5, 4, 7]]
}, {
renderer: liveDomRenderer({ animations: smilAnimations() })
});
chartHandle.update({
data: { labels: ['Q1', 'Q2', 'Q3'], series: [[7, 6, 5]] }
});
Data Format Reference
| Property or form | Description |
|---|
labels | Optional category labels or pie-slice labels. |
series | Required chart values. Nested series for lines and grouped bars, or a flat series for pies and distributed bars. |
[2, 5, 3] | A numeric series. Numeric strings also work. |
[{ x, y }, ...] | Values with explicit X and Y coordinates for XY charts. Use a continuous X axis. |
{ name, data, className, meta } | A series object. name identifies a series, data contains its values, className overrides the default letter class, and meta stores application data. |
{ value, meta } | An individual value with metadata. |
{ value, name, className, meta } | A flat-series value, such as a pie slice, with its own series identity. |
null, undefined, NaN | Missing values that leave gaps in the chart. |
Configuration Options
Shared preset options
| Option | Description |
|---|
width | Chart width as a number of pixels or CSS length. |
height | Chart height as a number of pixels or CSS length. |
low | Lower limit for the value scale. |
high | Upper limit for the value scale. |
referenceValue | Value the scale should include, subject to explicit axis limits. |
chartPadding | Number or { top, right, bottom, left } in pixels. Default: { top: 15, right: 15, bottom: 5, left: 10 } for line/bar charts, and 5 on each side for pie charts. |
viewBox | SVG coordinates as { width, height }. |
plugins | Array of v2 plugins or plugin-and-options entries. |
on | Phase listeners registered before the initial draw. Accepts individual phase properties or '*'. |
renderer | Rendering implementation. Default is the DOM renderer. The optional live renderer comes from chartist/live. |
layers | { below?, above? } with optional custom layers around a preset’s principal series. |
classNames | Public override object for the SVG class names of a preset. See the class-name reference. |
Line chart options
| Option | Default and behavior |
|---|
labels | 'html' or 'svg'. Choose the label rendering format. Default follows the renderer. |
showLine | true. Draw the line connecting data points. |
showPoint | true. Draw point markers. |
showArea | false. Fill the area below each line. |
areaBase | 0. Value where area fills close. |
lineSmooth | true. Use monotone cubic interpolation. Set false for straight segments, or supply an interpolation function. |
showGridBackground | false. Draw the grid background rectangle. |
fullWidth | false. Extend the final X position to the far edge. |
reverseData | false. Reverse labels, series order, and values. |
series | Per-series options keyed by series name. Accepts showLine, showPoint, showArea, areaBase, and lineSmooth. |
axisX, axisY | Axis setup, ticks, labels, and bounds. |
Bar chart options
| Option | Default and behavior |
|---|
labels | 'html' or 'svg'. Choose the label rendering format. Default follows the renderer. |
seriesBarDistance | 15. Distance in pixels between bars in one category. |
stackBars | false. Stack each category’s bar values. |
stackMode | 'accumulate'. Also accepts 'accumulate-relative', 'overlap', and true (overlap). |
horizontalBars | false. Put categories on the Y axis and values on X. |
distributeSeries | false. Give the values of a flat series individual series colors. |
reverseData | false. Reverse labels, series order, and values. |
showGridBackground | false. Fill the grid background rectangle. |
axisX, axisY | Axis setup and bounds. For horizontal bars, configure the value scale on X. |
Pie and donut chart options
| Option | Default and behavior |
|---|
startAngle | 0. Starting angle clockwise from the top, in degrees. |
total | Sum of values by default. Set a larger number for a partially filled gauge. |
donut | false. Draw ring-shaped slices. |
donutWidth | Width in pixels or a string percentage of the radius. When absent, the browser reads the stylesheet width, 60px by default. |
showLabel | true. Display slice labels. |
labelOffset | 0. Move labels radially in pixels. |
labelPosition | 'inside'. Also accepts 'outside' and 'center'. |
labelTransform | Function (value, index) => label for each slice. Return null to omit it. |
labelInterpolationFnc | Legacy alias of labelTransform. The newer option wins when both exist. |
labelDirection | 'neutral'. Also accepts 'explode' and 'implode'. |
ignoreEmptyValues | false. Omit empty slices and their labels. |
preventOverlappingLabelOffset | 0. Extra separation for overlapping labels in pixels. |
Axis options for line and bar charts
| Option | Description |
|---|
type | stepAxis(), autoScaleAxis(), or fixedScaleAxis() factory. Legacy axis classes also work. |
low, high | Explicit numeric scale bounds. |
referenceValue | Numeric value to keep in the scale. |
offset | Label area in pixels. Preset defaults: X 30, Y 40. |
position | 'start' or 'end' side of the axis. Preset defaults: X 'end', Y 'start'. |
labelOffset | { x, y } pixel displacement. Default { x: 0, y: 0 }. |
showLabel | Display axis labels. Default true. |
labelAlign | SVG text alignment as { horizontal, vertical }. Horizontal accepts 'start', 'middle', 'end'. Vertical accepts 'top', 'middle', 'bottom'. |
showGrid | Display grid lines. Default true. |
labelTransform | (value, index) => label. Return null or undefined to omit the label. |
labelInterpolationFnc | Legacy label formatter. labelTransform takes priority. |
scaleMinSpace | Minimum pixel spacing between auto-scale ticks. Value-axis defaults are generally 20 pixels. |
onlyInteger | Use integer tick values. Default false on auto-scale axes. |
ticks | Explicit step-axis or fixed-scale tick values. |
stretch | Stretch step-axis ticks to the full axis length. |
divisor | Number of equal intervals for a fixed scale when ticks is absent. |
highLow | Scale bounds supplied as { high, low }. |
Composed Chart API
chart(containerOrSelector, {
data,
layers,
axes,
coordinates,
padding,
width,
height,
viewBox,
className,
labels,
responsive,
plugins,
on,
renderer
});
`chart()` configuration reference
| Property | Description |
|---|
data | Required labels and series. |
layers | Required array of drawing layers, painted in order. |
axes | Cartesian axis configuration, normally from cartesianAxes(). |
coordinates | 'cartesian' by default, or 'polar' for pie layers. |
padding | Number or partial { top, right, bottom, left } pixel values. |
width, height | Optional CSS lengths or numeric pixel sizes. |
viewBox | Fixed { width, height } SVG coordinate system. |
className | Class or classes attached to the root SVG. |
labels | 'html' or 'svg' label rendering mode. |
responsive | Result of responsive([...]) with media or container conditions. |
plugins | v2 plugin entries. |
on | Phase listeners, including the initial render. |
renderer | Renderer instance. The standard browser renderer is the default. |
preset | Read-only preset state set by the preset functions and available to plugins. It is not a normal chart option to set manually. |
Axis and layer factories
| Function | Purpose |
|---|
cartesianAxes([{ id, side, type, ... }]) | Register X/Y axes by ID and side ('top', 'bottom', 'left', 'right'). |
stepAxis() | Arrange categorical ticks by their index. |
autoScaleAxis() | Derive a continuous scale from chart values. |
fixedScaleAxis() | Draw a fixed numeric scale using ticks or divisor. |
axisGrid(options?) | Grid lines and optional background. |
axisLabels(options?) | Axis labels and their alignment. |
line(options?) | Lines, points, and optional area fills. |
bar(options?) | Grouped, stacked, distributed, or horizontal bars. |
pie(options?) | Pie and donut slices in polar coordinates. |
band(options) | Shaded band between two values or a group of series. |
targetLine(options) | Horizontal or vertical reference line and optional label. |
trendLine(options?) | Trend line for chart data. |
Layer configuration reference
| Factory | Public properties |
|---|
axisGrid | axes, classNames, background. |
axisLabels | axes, classNames, labels, align. |
line | series, x, y, align, showLine, showPoint, showArea, areaBase, lineSmooth, overrides, reverseData, classNames. The overrides object uses the five per-series line settings. |
bar | series, x, y, horizontalBars, stackBars, stackMode, seriesBarDistance, offset, distributeSeries, reverseData, classNames. |
pie | startAngle, total, donut, donutWidth, showLabel, labelOffset, labelPosition, labelTransform, labelInterpolationFnc, labelDirection, ignoreEmptyValues, preventOverlappingLabelOffset, classNames. |
band | low, high, series, x, y, lineSmooth, align, className, mark, classNames. |
targetLine | value, label, className, axis, labelPosition, classNames. |
trendLine | series, x, y, align, classNames. |
Additional public chart helpers
| Export | Description |
|---|
responsive(entries) | Build responsive configuration entries for chart(). Each entry contains a media query or container condition and a partial configuration object. |
container(query) | Create an experimental container condition for the responsive entries. Requires Element.matchContainer() through a polyfill. |
withOptions(plugin, options) | Associate typed options with a v2 plugin. |
lineChartConfig(data, options?) | Build a composable configuration for the line preset, useful for alternate renderers. |
barChartConfig(data, options?) | Build a composable configuration for the bar preset. |
pieChartConfig(data, options?) | Build a composable configuration for the pie preset. |
Interpolation | Public interpolation helpers, including none, monotoneCubic, cardinal, and step, for lineSmooth. |
liveDomRenderer(options?) | Experimental renderer from chartist/live that preserves SVG nodes during updates. |
smilAnimations() | Experimental chartist/live animation provider for live updates, configured with CSS timing variables. |
toScene(config, { width, height }) | Build a chart scene for server rendering through chartist/server. |
renderToString(scene) | Render a scene to SVG markup through chartist/server. |
renderForHydration(config, size) | Experimental chartist/server helper that emits SVG markup for adoption by liveDomRenderer() in the browser. |
computeStyles(scene, css, options?) | Experimental chartist/server helper that computes SVG presentation styles from application-controlled CSS. CSS coverage is intentionally limited. |
applyStyles(scene, styles, options?) | Experimental chartist/server helper that writes computed presentation styles into an SVG scene for image or PDF export. |
compat | Optional plugin from chartist/compat for Chartist 1.x events. |
fromLegacyPlugin(plugin, options?) | Convert a Chartist 1.x plugin to a v2 plugin. |
API Methods
| Method | Description |
|---|
update({ data?, layers?, axes?, ... }) | Shallow-merge allowed chart-config changes and redraw. Preset data is updated with it. |
detach() | Stop chart-managed resize and responsive listeners, leaving the rendered SVG in place. |
destroy() | Detach, remove chart output, and clear listeners. |
on(event, listener) | Register a phase or custom-event listener. |
off(event, listener?) | Remove a listener or the non-plugin listeners for that event. |
emit(name, payload) | Emit a declared custom event. Pipeline phase names are reserved. |
setOptions(options, { replace? }) | Preset handles only. Change preset options and redraw. replace: true resets previous overrides. |
Events And Plugins
A chart executes seven drawing phases. Pass the on object when you need an event from the first render. chart.on() registers listeners for subsequent renders. The core also emits responsive when matching configuration changes. A '*' listener receives the event name and payload. The render and mount phases identify create, update, resize, responsive, and fonts causes, plus added, updated, and removed scene nodes.
| Phase | Payload / trigger |
|---|
resolve | { config } after defaults are resolved. |
prepare | { data } after data normalization. |
layout | Chart dimensions and drawing area. |
compose | Each generated scene node. May return an altered node or null. |
scene | { scene } containing the composed SVG tree. |
render | Scene written or updated by the renderer, with output, cause, and changes. |
mount | Output attached to the page, with elementOf(node) and possible animation data. |
import { barChart } from 'chartist';
const chartHandle = barChart(
'#events-chart',
{ labels: ['Jan', 'Feb', 'Mar'], series: [[12, 18, 15]] },
{
on: {
mount: ({ cause }) => console.log('Rendered:', cause)
}
}
);
const onResponsive = ({ currentOptions }) => console.log(currentOptions);
chartHandle.on('responsive', onResponsive);
A chartist plugin is an object with name and install(chart, options?). Optional plugin fields include provides for custom event names and keyframes for update animations. A cleanup function returned by install() runs on destroy(), and a cleanup function returned by a mount listener runs before the next render and on destruction. Supply plugin settings with withOptions(plugin, settings) or a plugin-and-options entry.
import { barChart } from 'chartist';
const highlight = {
name: 'highlight',
install(chart) {
chart.on('compose', node => {
if (node.role !== 'bar') return;
return node.addClass('highlighted-bar');
});
}
};
barChart('#highlight-chart', { series: [[2, 4, 6]] }, {
plugins: [highlight]
});
Styling And Customization
Chartist styles its generated SVG using regular CSS. Set custom properties on a chart container, an ancestor, or :root.
#sales-chart {
--ct-series-a: #2563eb;
--ct-series-b: #f59e0b;
--ct-line-width: 2px;
--ct-point-size: 8px;
--ct-grid-dasharray: none;
--ct-label-color: #334155;
}
CSS custom properties
| Variable | Default / effect |
|---|
--ct-series-a through --ct-series-z | Series colors. The default palette contains 15 colors and repeats after its final entry. |
--ct-color | Series-local color inherited by drawing elements. |
--ct-line-width | 4px. Line stroke width. |
--ct-line-dasharray | none. Line dash pattern. |
--ct-point-size | 10px. Point size. |
--ct-point-shape | round. Can be square. |
--ct-area-opacity | 0.1. Filled area opacity. |
--ct-bar-width | 10px. Bar stroke width. |
--ct-donut-width | 60px. Donut stroke width. |
--ct-grid-color | rgba(0, 0, 0, 0.2). Grid color. |
--ct-grid-width | 1px. Grid stroke width. |
--ct-grid-dasharray | 2px. Grid dash pattern. |
--ct-grid-background-fill | none. Grid background fill. |
--ct-grid-minor-color | Minor grid line color for custom axes that create minor ticks. |
--ct-grid-minor-width | 1px. Minor grid stroke width. |
--ct-grid-minor-dasharray | none. Minor grid dash pattern. |
--ct-label-color | rgba(0, 0, 0, 0.4). Label color. |
--ct-label-size | 0.75rem. Label text size. |
--ct-target-line-color | Color of reference lines created with targetLine(). |
--ct-target-line-width | Stroke width of a reference line. |
--ct-target-line-dasharray | Dash pattern of a reference line. |
--ct-band-color | Fill color for a range created with band(). |
--ct-band-opacity | Opacity of the band fill. |
--ct-trend-line-width | Stroke width of a trendLine() layer. |
--ct-trend-line-dasharray | Dash pattern of a trend line. |
--ct-update-duration | 300ms with smilAnimations(). Set 0s to turn off update animations. |
--ct-update-easing | ease-out with smilAnimations(). Accepts a CSS easing. |
Public SVG class names
| Class or option group | Elements |
|---|
ct-chart-line, ct-chart-bar, ct-horizontal-bars | Line chart, bar chart, and horizontal bar chart SVG roots. |
ct-chart-pie, ct-chart-donut | Pie and donut SVG roots. |
ct-series, ct-series-a through ct-series-z | Series grouping and per-series color classes. |
ct-line, ct-point, ct-area, ct-bar | Lines, points, area fills, and bars. |
ct-slice-pie, ct-slice-donut | Pie and donut slices. |
ct-grids, ct-grid, ct-grid-background | Grid group, lines, and background. |
ct-labels, ct-label | Label groups and individual labels. |
ct-vertical, ct-horizontal, ct-start, ct-end | Axis orientation and side modifiers. |
ct-target-line, ct-target-label, ct-trend-line | Reference and trend lines. |
ct-band, ct-band-area, ct-in-band, ct-out-band | Bands and their optional value markers. |
ct-theme-accessible | Container class enabling the additional color-accessible theme. |
`classNames` override properties
| Preset | Keys |
|---|
lineChart | chart, label, labelGroup, series, line, point, area, grid, gridGroup, gridBackground, vertical, horizontal, start, end. |
barChart | chart, horizontalBars, label, labelGroup, series, bar, grid, gridGroup, gridBackground, vertical, horizontal, start, end. |
pieChart | chartPie, chartDonut, series, slicePie, sliceDonut, label. |
Responsive sizing classes
| Class | Width to height |
|---|
ct-square | 1:1 |
ct-minor-second | 16:15 |
ct-major-second | 9:8 |
ct-minor-third | 6:5 |
ct-major-third | 5:4 |
ct-perfect-fourth | 4:3 |
ct-perfect-fifth | 3:2 |
ct-minor-sixth | 8:5 |
ct-golden-section | 1.618:1 |
ct-major-sixth | 5:3 |
ct-minor-seventh | 16:9 |
ct-major-seventh | 15:8 |
ct-octave | 2:1 |
ct-major-tenth | 5:2 |
ct-major-eleventh | 8:3 |
ct-major-twelfth | 3:1 |
ct-double-octave | 4:1 |
Accessible color palette
Load chartist/themes/accessible.css after the main stylesheet and set ct-theme-accessible on the chart container or one of its ancestors. The palette includes light and dark variants.
In dark themes, declare color-scheme: dark and adjust label and grid colors as needed. Charts that convey important information should also have a text summary or data table.
import 'chartist/styles.css';
import 'chartist/themes/accessible.css';
Sass configuration
If the site already compiles Sass, import chartist/scss/index and customize the !default settings. The Sass configuration can change the color palette, ratio classes, output switches, and stroke styles at build time.
@use 'chartist/scss/index' with (
$ct-series-colors: (#2563eb, #f59e0b, #059669),
$ct-line-width: 2px,
$ct-grid-dasharray: false
);
Sass variables
Layout, palette, and CSS output
| Variable | Description |
|---|
$ct-scales | Ratios for responsive containers. |
$ct-scales-names | Class names associated with the ratios. |
$ct-container-ratio | Default container ratio for the SVG container mixin. |
$ct-series-names | Names used by the generated color series classes. |
$ct-series-colors | Palette used by the generated series classes. |
$ct-include-classes | Enable the default CSS class output. |
$ct-include-colored-series | Enable series color CSS rules. |
$ct-include-alternative-responsive-containers | Enable alternate aspect-ratio container classes. |
Labels, grid, and dark mode
| Variable | Description |
|---|
$ct-text-color | Default label color. |
$ct-text-color-dark | Label color in a dark color scheme. |
$ct-text-size | Label font size. |
$ct-text-align | Alignment of label contents. |
$ct-text-justify | Justification of label contents. |
$ct-text-line-height | Label line height. |
$ct-grid-color | Major grid line color. |
$ct-grid-color-dark | Major grid line color in dark color schemes. |
$ct-grid-width | Major grid stroke width. |
$ct-grid-dasharray | Major grid dash pattern. |
$ct-grid-background-fill | Grid background fill. |
$ct-grid-minor-color | Minor grid line color. |
$ct-grid-minor-color-dark | Minor grid line color for dark schemes. |
$ct-grid-minor-dasharray | Minor grid dash pattern. |
$ct-grid-minor-width | Minor grid stroke width. |
Chart geometry
| Variable | Description |
|---|
$ct-line-width | Line stroke width. |
$ct-line-dasharray | Line dash pattern. |
$ct-point-size | Point size. |
$ct-point-shape | Point cap shape. |
$ct-area-opacity | Filled line-area opacity. |
$ct-bar-width | Bar stroke width. |
$ct-band-color | Band fill color. |
$ct-band-opacity | Band fill opacity. |
$ct-donut-width | Donut stroke width. |
Generated class name variables
| Variable | Description |
|---|
$ct-class-chart | Generic chart root selector. |
$ct-class-chart-line | Line chart root selector. |
$ct-class-chart-bar | Bar chart root selector. |
$ct-class-horizontal-bars | Horizontal bar chart modifier. |
$ct-class-chart-pie | Pie chart root selector. |
$ct-class-chart-donut | Donut chart root selector. |
$ct-class-label | Chart label selector. |
$ct-class-series | Series group selector. |
$ct-class-line | Line geometry selector. |
$ct-class-point | Point marker selector. |
$ct-class-area | Filled line-area selector. |
$ct-class-bar | Bar geometry selector. |
$ct-class-slice-pie | Pie slice selector. |
$ct-class-slice-donut | Donut slice selector. |
$ct-class-grid | Grid line selector. |
$ct-class-grid-background | Grid background selector. |
$ct-class-grid-minor | Minor grid line selector. |
$ct-class-vertical | Vertical orientation modifier. |
$ct-class-horizontal | Horizontal orientation modifier. |
$ct-class-start | Start side modifier. |
$ct-class-end | End side modifier. |
$ct-class-band | Band group selector. |
$ct-class-band-area | Band fill selector. |
Sass mixins
| Mixin | Purpose |
|---|
ct-chart() | Generate Chartist chart styles. |
ct-responsive-svg-container($width, $ratio) | Create an SVG container with a custom ratio. |
ct-chart-label() | Generate label styling. |
ct-chart-grid() | Generate grid styling. |
ct-chart-point() | Generate point marker styling. |
ct-chart-line() | Generate line styling. |
ct-chart-area() | Generate filled-area styling. |
ct-chart-bar() | Generate bar styling. |
ct-chart-donut() | Generate donut styling. |
ct-chart-band-area() | Generate band styling. |
ct-chart-series-color($color) | Generate series color rules. |
Server-Side SVG Rendering
For static reports or exports, Chartist can build SVG markup in Node.js without a DOM.
import { lineChartConfig } from 'chartist';
import { renderToString, toScene } from 'chartist/server';
const config = lineChartConfig({
labels: ['Mon', 'Tue', 'Wed'],
series: [[5, 2, 4]]
});
const svg = renderToString(toScene(config, {
width: 600,
height: 300
}));
Alternatives And Related Resources