Skip to content

Guide · Open source

How to use Chartist: install, draw charts and style them with CSS

Updated · written with AI from the project's own documentation and checked against our catalogue data

Chartist is a JavaScript library for drawing charts on web pages. It renders charts as SVG, so they scale to fit their container, and you style them with ordinary CSS. This guide shows you how to install it, draw a first line chart, and style and size it, so you can add a simple chart to a page.

Chartistchartist-js/chartist · ★ 13.5k · MIT

Quick start

  1. 1Install the package. Run npm install chartist in your project folder. The README lists no prerequisites.
  2. 2Add a container. Place a div with an id and the class ct-golden-section where the chart should appear.
  3. 3Import the function and stylesheet. Import lineChart and the Chartist stylesheet, or load them from the CDN if you have no bundler.
  4. 4Pass labels and series. Call lineChart with the container selector and an object holding labels and an array of series.
  5. 5Style with CSS. Adjust the SVG classes and custom properties in your own stylesheet to match your page.
  6. 6Check responsiveness. Resize the browser to confirm the chart scales to its container and that any media query options behave as you intended.

Install Chartist with npm

Chartist is published on npm. If your project uses a package manager, install it from your project folder with the command below. The README lists no prerequisites, but its examples assume you are comfortable with HTML and JavaScript.

npm install chartist

Draw your first chart

Chartist draws a chart into a container element. Give a div an id, then pass that id to a chart function along with your data. The example uses lineChart, which takes labels and a list of series, where each series is an array of numbers.

Add the stylesheet and a container with the class ct-golden-section, which gives the chart its default proportions.

  • Pass the container selector, such as '#chart', as the first argument.
  • Put your x-axis labels in labels and one array per line in series.
  • Import the stylesheet alongside the function so the chart is drawn with its default styles.
import { lineChart } from 'chartist';\nimport 'chartist/styles.css';\n\nlineChart('#chart', {\n labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],\n series: [\n [12, 9, 7, 8, 5],\n [2, 1, 3.5, 7, 3]\n ]\n});

Use Chartist without a build step

If you have no bundler, Chartist works as a native ES module loaded from a CDN. Link the stylesheet, add the container, and import the function in a script tag with type set to module.

This route suits small pages where you want a chart without setting up a build tool.

<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/chartist@2/dist/index.min.css\" />\n<div id=\"chart\" class=\"ct-golden-section\"></div>\n<script type=\"module\">\n import { lineChart } from 'https://cdn.jsdelivr.net/npm/chartist@2/dist/index.min.js';\n lineChart('#chart', { series: [[1, 3, 2, 5]] });\n</script>

Style charts with CSS

Chartist renders plain SVG with predictable class names, and it exposes custom properties for colors, lines and labels. You change the look with your own stylesheet rather than a theme engine.

Because the output is ordinary SVG and CSS, the same styling rules you already use for your page apply to the chart.

  • Target the SVG classes Chartist adds to change colors, line thickness and label appearance.
  • Set the custom properties for colors and lines to keep a consistent palette across charts.
  • Use the container class to control the chart's shape and size.

Make charts responsive

Because charts are SVG, they scale to fit their container. Chartist also lets you change options at different screen sizes in two ways: with media queries, or based on the chart's own container.

Use media queries when the whole page layout changes width. Use container-based options when the same chart sits in different sized slots.

Render charts on the server

Chartist can render on a server with real SVG text labels. The README names PDFs, email and images as uses for this, since the output does not depend on a browser running client-side scripts.

The docs site has framework recipes, including server rendering for React, Vue, Angular and Svelte.

What people use it for

  • Adding a simple line chart of weekly figures to a web page
  • Drawing bars and lines together in one chart on a dashboard
  • Rendering a chart as SVG on a server for a PDF report or an email
  • Loading a chart on a static HTML page with no build step

Frequently asked questions

Is Chartist free to use?

Yes. The README says Chartist is dual-licensed under MIT or WTFPL, at your choice. Check the LICENSE-MIT and LICENSE-WTFPL files in the repository for the full text.

What do I need to install Chartist?

The README lists no prerequisites. Install it with npm install chartist. The examples assume you know basic HTML and JavaScript.

Can I use Chartist without npm or a bundler?

Yes. The README says Chartist is a native ES module, so you can load the stylesheet and script from the jsDelivr CDN and import the function in a script tag with type set to module.

Does Chartist work with React, Vue or Angular?

You do not need a wrapper. The docs site has a Charts in frameworks page with recipes for React, Vue, Angular and Svelte. The README also lists community wrappers, but some were built for older releases and need an npm overrides entry to run on the current one.

What is Chartist alternative for more chart types?

The README focuses on core simple charts and does not list many advanced chart types or built-in interactivity. Projects often compare it with Chart.js, ApexCharts, Recharts and D3 for those needs.

Can I render Chartist charts on a server?

Yes. The README says Chartist can render on a server as SVG with real SVG text labels, which suits PDFs, email and images.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Chartist suits web developers who want simple, responsive SVG charts that they style with plain CSS, with or without a build step. If you need many advanced chart types, built-in interactivity or a beginner-friendly setup, pick a larger library such as Chart.js, ApexCharts or Recharts instead.

Install options & downloads