Chartist

Search

Find a guide, an API entry or an example.

Try

Timeseries

Two series of dated values on a fixed scale X axis with six month and day labels.

src/main.ts
import 'chartist/styles.css';
import { lineChart, fixedScaleAxis } from 'chartist';

lineChart(
  '#chart',
  {
    series: [
      {
        name: 'series-1',
        data: [
          { x: new Date(143134652600), y: 53 },
          { x: new Date(143234652600), y: 40 },
          { x: new Date(143340052600), y: 45 },
          { x: new Date(143366652600), y: 40 },
          { x: new Date(143410652600), y: 20 },
          { x: new Date(143508652600), y: 32 },
          { x: new Date(143569652600), y: 18 },
          { x: new Date(143579652600), y: 11 }
        ]
      },
      {
        name: 'series-2',
        data: [
          { x: new Date(143134652600), y: 53 },
          { x: new Date(143234652600), y: 35 },
          { x: new Date(143334652600), y: 30 },
          { x: new Date(143384652600), y: 30 },
          { x: new Date(143568652600), y: 10 }
        ]
      }
    ]
  },
  {
    // Room for the label of the last tick, at the right edge.
    chartPadding: { right: 40 },
    axisX: {
      type: fixedScaleAxis(),
      divisor: 5,
      labelInterpolationFnc: value =>
        new Date(value).toLocaleString(undefined, {
          month: 'short',
          day: 'numeric'
        })
    }
  }
);
Live
Open in the playgroundView as MarkdownSwitch to 1.x above the code to see the same chart written with the Chartist 1.x classes.