# Chartist v2: guides, API reference and packages
Chartist draws responsive SVG charts and leaves their look to CSS. This is Chartist v2, a TypeScript library with no dependencies, available from npm (`chartist`) or as ES modules from a CDN, without a build step.
When writing Chartist code:
- Create charts with the functions: `lineChart(target, data, options)`, `barChart(…)` and `pieChart(…)` for the classic chart types, and `chart({ data, axes, layers })` for composed charts (bars and lines together, several axes). Import them from `chartist`, and the default styles with `import 'chartist/styles.css'`.
- Don't write `new Chartist.Line(…)`, `new LineChart(…)` or `Chartist.Interpolation`: that's the 1.x and 0.x API. The 1.x classes are deprecated and leave `chartist` in 3.0; they still work, for compatibility only.
- Style charts with CSS and custom properties (`--ct-series-a`, `--ct-line-width`, …), not with options.
- Change what a chart draws with plugins: listeners on the pipeline's phase events (`compose` for scene nodes, `mount` for the DOM). 1.x `draw` events need the `compat` plugin from `chartist/compat`.
- Size charts with their container (CSS), and use responsive options for what changes with the size.
- For charts that update while people look at them, pass `renderer: liveDomRenderer()` from `chartist/live`: the chart keeps its SVG and changes it in place. Set up elements on the `add` changes in `mount`, not on every render.
- Packages under `@chartist-js` (listed below) take the same data and options: `@chartist-js/terminal` draws charts as terminal text or HTML text art, `@chartist-js/essentials` adds layers such as `axisTitle()`, and `@chartist-js/tooltips` adds tooltips for mouse, touch and keyboard.
## Getting started
> Your first chart in about two minutes. No build step, no bundler, no framework. An HTML file and a browser.
> **Works without a bundler.** Chartist ships as a native ES module, so a `
```
### Open it in a browser
That's it. Here's the whole file, ready to save as `index.html`:
```html
My first chart
```
And this is what it draws, live. Press **Edit** and change a number. The editor knows Chartist's types: point at a name to read what it takes, press Ctrl+Space for suggestions, and a mistake gets a red underline before you run it.
**My first chart** (runs in the browser):
`src/main.ts`:
```ts
import 'chartist/styles.css';
import { lineChart } from 'chartist';
lineChart('#chart', {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
series: [
[12, 9, 7, 8, 5],
[2, 1, 3.5, 7, 3]
]
});
```
`index.html`:
```html
```
### Import Chartist by name
An import map tells the browser where `chartist` lives, so your code can import it by name, just like with npm. The same code then moves to a bundler unchanged, and plugins that import `chartist` find it too:
```html
```
The import map goes before the first module script. `chartist/compat` is only needed if you use the [1.x compatibility](https://chartist.dev/docs/coming-from-1x/); it shares the core of the `chartist` entry, since `compat.min.js` imports `index.min.js` next to it.
### Using npm
Same API, installed from npm. It works with Vite, webpack, Rollup, esbuild and Astro, and it's written in TypeScript, so the types come with it.
```sh
npm install chartist
```
```ts
import 'chartist/styles.css';
import { barChart } from 'chartist';
barChart(
'#chart',
{
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
series: [
[5, 4, 3, 7],
[3, 2, 9, 5]
]
},
{ stackBars: true }
);
```
Chartist only adds what you import to your bundle, so a single line chart stays small.
### Make it yours with CSS
There's no theme option. Charts are SVG with predictable classes, so you style them the way you style everything else. Custom properties cover the common cases, for the whole page, one container or one chart:
```css
#chart {
--ct-series-a: #9a6a45; /* first series */
--ct-line-width: 2px;
--ct-grid-dasharray: none;
}
```
> **Coming from Chartist 1.x?** Your code keeps working: the chart classes are
> still there, and your charts look exactly the same. [Coming from
> 1.x](https://chartist.dev/docs/coming-from-1x/) shows how to move to the functions, one chart at a
> time.
### Where to next
- Pick your chart: [line](https://chartist.dev/docs/line-charts/), [bar](https://chartist.dev/docs/bar-charts/), [pie and donut](https://chartist.dev/docs/pie-and-donut-charts/), or [bars and lines together](https://chartist.dev/docs/composed-charts/).
- Shape your data and options: [Data and options](https://chartist.dev/docs/data-and-options/), [Sizing charts](https://chartist.dev/docs/sizing-charts/).
- Make it yours: [Styling with CSS](https://chartist.dev/docs/styling-with-css/), then [Responsive sugar topping](https://chartist.dev/docs/responsive/).
- Wondering whether Chartist fits? [Why Chartist?](https://chartist.dev/docs/why-chartist/) says what it's made for, and what it leaves to you.
## Why Chartist?
> Chartist draws simple, responsive charts as SVG and leaves styling, interaction and the rest to the web platform. Here's what that means for you.
Chartist has one job: turn your data into a clean, responsive SVG chart. Everything the browser already does well (styling, events, animation, layout) it leaves to the browser. That's a choice, and it shapes everything else on this site.
### SVG in the DOM
A Chartist chart is an inline `