Responsive SVG Charts with Vanilla JavaScript – Chartist

Category: Chart & Graph , Javascript , Recommended | October 21, 2026
Authorchartist-js
Last UpdateOctober 21, 2026
LicenseMIT
Views0 views
Responsive SVG Charts with Vanilla JavaScript – Chartist

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 formDescription
labelsOptional category labels or pie-slice labels.
seriesRequired 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, NaNMissing values that leave gaps in the chart.

Configuration Options

Shared preset options

OptionDescription
widthChart width as a number of pixels or CSS length.
heightChart height as a number of pixels or CSS length.
lowLower limit for the value scale.
highUpper limit for the value scale.
referenceValueValue the scale should include, subject to explicit axis limits.
chartPaddingNumber 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.
viewBoxSVG coordinates as { width, height }.
pluginsArray of v2 plugins or plugin-and-options entries.
onPhase listeners registered before the initial draw. Accepts individual phase properties or '*'.
rendererRendering 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.
classNamesPublic override object for the SVG class names of a preset. See the class-name reference.

Line chart options

OptionDefault and behavior
labels'html' or 'svg'. Choose the label rendering format. Default follows the renderer.
showLinetrue. Draw the line connecting data points.
showPointtrue. Draw point markers.
showAreafalse. Fill the area below each line.
areaBase0. Value where area fills close.
lineSmoothtrue. Use monotone cubic interpolation. Set false for straight segments, or supply an interpolation function.
showGridBackgroundfalse. Draw the grid background rectangle.
fullWidthfalse. Extend the final X position to the far edge.
reverseDatafalse. Reverse labels, series order, and values.
seriesPer-series options keyed by series name. Accepts showLine, showPoint, showArea, areaBase, and lineSmooth.
axisX, axisYAxis setup, ticks, labels, and bounds.

Bar chart options

OptionDefault and behavior
labels'html' or 'svg'. Choose the label rendering format. Default follows the renderer.
seriesBarDistance15. Distance in pixels between bars in one category.
stackBarsfalse. Stack each category’s bar values.
stackMode'accumulate'. Also accepts 'accumulate-relative', 'overlap', and true (overlap).
horizontalBarsfalse. Put categories on the Y axis and values on X.
distributeSeriesfalse. Give the values of a flat series individual series colors.
reverseDatafalse. Reverse labels, series order, and values.
showGridBackgroundfalse. Fill the grid background rectangle.
axisX, axisYAxis setup and bounds. For horizontal bars, configure the value scale on X.

Pie and donut chart options

OptionDefault and behavior
startAngle0. Starting angle clockwise from the top, in degrees.
totalSum of values by default. Set a larger number for a partially filled gauge.
donutfalse. Draw ring-shaped slices.
donutWidthWidth in pixels or a string percentage of the radius. When absent, the browser reads the stylesheet width, 60px by default.
showLabeltrue. Display slice labels.
labelOffset0. Move labels radially in pixels.
labelPosition'inside'. Also accepts 'outside' and 'center'.
labelTransformFunction (value, index) => label for each slice. Return null to omit it.
labelInterpolationFncLegacy alias of labelTransform. The newer option wins when both exist.
labelDirection'neutral'. Also accepts 'explode' and 'implode'.
ignoreEmptyValuesfalse. Omit empty slices and their labels.
preventOverlappingLabelOffset0. Extra separation for overlapping labels in pixels.

Axis options for line and bar charts

OptionDescription
typestepAxis(), autoScaleAxis(), or fixedScaleAxis() factory. Legacy axis classes also work.
low, highExplicit numeric scale bounds.
referenceValueNumeric value to keep in the scale.
offsetLabel 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 }.
showLabelDisplay axis labels. Default true.
labelAlignSVG text alignment as { horizontal, vertical }. Horizontal accepts 'start', 'middle', 'end'. Vertical accepts 'top', 'middle', 'bottom'.
showGridDisplay grid lines. Default true.
labelTransform(value, index) => label. Return null or undefined to omit the label.
labelInterpolationFncLegacy label formatter. labelTransform takes priority.
scaleMinSpaceMinimum pixel spacing between auto-scale ticks. Value-axis defaults are generally 20 pixels.
onlyIntegerUse integer tick values. Default false on auto-scale axes.
ticksExplicit step-axis or fixed-scale tick values.
stretchStretch step-axis ticks to the full axis length.
divisorNumber of equal intervals for a fixed scale when ticks is absent.
highLowScale 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

PropertyDescription
dataRequired labels and series.
layersRequired array of drawing layers, painted in order.
axesCartesian axis configuration, normally from cartesianAxes().
coordinates'cartesian' by default, or 'polar' for pie layers.
paddingNumber or partial { top, right, bottom, left } pixel values.
width, heightOptional CSS lengths or numeric pixel sizes.
viewBoxFixed { width, height } SVG coordinate system.
classNameClass or classes attached to the root SVG.
labels'html' or 'svg' label rendering mode.
responsiveResult of responsive([...]) with media or container conditions.
pluginsv2 plugin entries.
onPhase listeners, including the initial render.
rendererRenderer instance. The standard browser renderer is the default.
presetRead-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

FunctionPurpose
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

FactoryPublic properties
axisGridaxes, classNames, background.
axisLabelsaxes, classNames, labels, align.
lineseries, x, y, align, showLine, showPoint, showArea, areaBase, lineSmooth, overrides, reverseData, classNames. The overrides object uses the five per-series line settings.
barseries, x, y, horizontalBars, stackBars, stackMode, seriesBarDistance, offset, distributeSeries, reverseData, classNames.
piestartAngle, total, donut, donutWidth, showLabel, labelOffset, labelPosition, labelTransform, labelInterpolationFnc, labelDirection, ignoreEmptyValues, preventOverlappingLabelOffset, classNames.
bandlow, high, series, x, y, lineSmooth, align, className, mark, classNames.
targetLinevalue, label, className, axis, labelPosition, classNames.
trendLineseries, x, y, align, classNames.

Additional public chart helpers

ExportDescription
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.
InterpolationPublic 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.
compatOptional plugin from chartist/compat for Chartist 1.x events.
fromLegacyPlugin(plugin, options?)Convert a Chartist 1.x plugin to a v2 plugin.

API Methods

MethodDescription
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.

PhasePayload / trigger
resolve{ config } after defaults are resolved.
prepare{ data } after data normalization.
layoutChart dimensions and drawing area.
composeEach generated scene node. May return an altered node or null.
scene{ scene } containing the composed SVG tree.
renderScene written or updated by the renderer, with output, cause, and changes.
mountOutput 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

VariableDefault / effect
--ct-series-a through --ct-series-zSeries colors. The default palette contains 15 colors and repeats after its final entry.
--ct-colorSeries-local color inherited by drawing elements.
--ct-line-width4px. Line stroke width.
--ct-line-dasharraynone. Line dash pattern.
--ct-point-size10px. Point size.
--ct-point-shaperound. Can be square.
--ct-area-opacity0.1. Filled area opacity.
--ct-bar-width10px. Bar stroke width.
--ct-donut-width60px. Donut stroke width.
--ct-grid-colorrgba(0, 0, 0, 0.2). Grid color.
--ct-grid-width1px. Grid stroke width.
--ct-grid-dasharray2px. Grid dash pattern.
--ct-grid-background-fillnone. Grid background fill.
--ct-grid-minor-colorMinor grid line color for custom axes that create minor ticks.
--ct-grid-minor-width1px. Minor grid stroke width.
--ct-grid-minor-dasharraynone. Minor grid dash pattern.
--ct-label-colorrgba(0, 0, 0, 0.4). Label color.
--ct-label-size0.75rem. Label text size.
--ct-target-line-colorColor of reference lines created with targetLine().
--ct-target-line-widthStroke width of a reference line.
--ct-target-line-dasharrayDash pattern of a reference line.
--ct-band-colorFill color for a range created with band().
--ct-band-opacityOpacity of the band fill.
--ct-trend-line-widthStroke width of a trendLine() layer.
--ct-trend-line-dasharrayDash pattern of a trend line.
--ct-update-duration300ms with smilAnimations(). Set 0s to turn off update animations.
--ct-update-easingease-out with smilAnimations(). Accepts a CSS easing.

Public SVG class names

Class or option groupElements
ct-chart-line, ct-chart-bar, ct-horizontal-barsLine chart, bar chart, and horizontal bar chart SVG roots.
ct-chart-pie, ct-chart-donutPie and donut SVG roots.
ct-series, ct-series-a through ct-series-zSeries grouping and per-series color classes.
ct-line, ct-point, ct-area, ct-barLines, points, area fills, and bars.
ct-slice-pie, ct-slice-donutPie and donut slices.
ct-grids, ct-grid, ct-grid-backgroundGrid group, lines, and background.
ct-labels, ct-labelLabel groups and individual labels.
ct-vertical, ct-horizontal, ct-start, ct-endAxis orientation and side modifiers.
ct-target-line, ct-target-label, ct-trend-lineReference and trend lines.
ct-band, ct-band-area, ct-in-band, ct-out-bandBands and their optional value markers.
ct-theme-accessibleContainer class enabling the additional color-accessible theme.

`classNames` override properties

PresetKeys
lineChartchart, label, labelGroup, series, line, point, area, grid, gridGroup, gridBackground, vertical, horizontal, start, end.
barChartchart, horizontalBars, label, labelGroup, series, bar, grid, gridGroup, gridBackground, vertical, horizontal, start, end.
pieChartchartPie, chartDonut, series, slicePie, sliceDonut, label.

Responsive sizing classes

ClassWidth to height
ct-square1:1
ct-minor-second16:15
ct-major-second9:8
ct-minor-third6:5
ct-major-third5:4
ct-perfect-fourth4:3
ct-perfect-fifth3:2
ct-minor-sixth8:5
ct-golden-section1.618:1
ct-major-sixth5:3
ct-minor-seventh16:9
ct-major-seventh15:8
ct-octave2:1
ct-major-tenth5:2
ct-major-eleventh8:3
ct-major-twelfth3:1
ct-double-octave4: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
VariableDescription
$ct-scalesRatios for responsive containers.
$ct-scales-namesClass names associated with the ratios.
$ct-container-ratioDefault container ratio for the SVG container mixin.
$ct-series-namesNames used by the generated color series classes.
$ct-series-colorsPalette used by the generated series classes.
$ct-include-classesEnable the default CSS class output.
$ct-include-colored-seriesEnable series color CSS rules.
$ct-include-alternative-responsive-containersEnable alternate aspect-ratio container classes.
Labels, grid, and dark mode
VariableDescription
$ct-text-colorDefault label color.
$ct-text-color-darkLabel color in a dark color scheme.
$ct-text-sizeLabel font size.
$ct-text-alignAlignment of label contents.
$ct-text-justifyJustification of label contents.
$ct-text-line-heightLabel line height.
$ct-grid-colorMajor grid line color.
$ct-grid-color-darkMajor grid line color in dark color schemes.
$ct-grid-widthMajor grid stroke width.
$ct-grid-dasharrayMajor grid dash pattern.
$ct-grid-background-fillGrid background fill.
$ct-grid-minor-colorMinor grid line color.
$ct-grid-minor-color-darkMinor grid line color for dark schemes.
$ct-grid-minor-dasharrayMinor grid dash pattern.
$ct-grid-minor-widthMinor grid stroke width.
Chart geometry
VariableDescription
$ct-line-widthLine stroke width.
$ct-line-dasharrayLine dash pattern.
$ct-point-sizePoint size.
$ct-point-shapePoint cap shape.
$ct-area-opacityFilled line-area opacity.
$ct-bar-widthBar stroke width.
$ct-band-colorBand fill color.
$ct-band-opacityBand fill opacity.
$ct-donut-widthDonut stroke width.
Generated class name variables
VariableDescription
$ct-class-chartGeneric chart root selector.
$ct-class-chart-lineLine chart root selector.
$ct-class-chart-barBar chart root selector.
$ct-class-horizontal-barsHorizontal bar chart modifier.
$ct-class-chart-piePie chart root selector.
$ct-class-chart-donutDonut chart root selector.
$ct-class-labelChart label selector.
$ct-class-seriesSeries group selector.
$ct-class-lineLine geometry selector.
$ct-class-pointPoint marker selector.
$ct-class-areaFilled line-area selector.
$ct-class-barBar geometry selector.
$ct-class-slice-piePie slice selector.
$ct-class-slice-donutDonut slice selector.
$ct-class-gridGrid line selector.
$ct-class-grid-backgroundGrid background selector.
$ct-class-grid-minorMinor grid line selector.
$ct-class-verticalVertical orientation modifier.
$ct-class-horizontalHorizontal orientation modifier.
$ct-class-startStart side modifier.
$ct-class-endEnd side modifier.
$ct-class-bandBand group selector.
$ct-class-band-areaBand fill selector.

Sass mixins

MixinPurpose
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

You Might Be Interested In:


Leave a Reply