Skip to the page content

Line charts

Fifteen ways to draw a trend with Chart.js, each one colored by your theme.

15 charts

The week so far

Tiny lines with no axes beside a number. Direction, not detail.

Sparklines

Store revenue

$55.5k

Last 12 days

Orders

503

This week, 72 a day

Store sessions

9,030

This week

Conversion

5.6%

Orders per session

Show config
options: {
  scales: { x: { display: false }, y: { display: false } },
  plugins: { legend: { display: false }, tooltip: { enabled: false } },
  elements: { point: { radius: (c) => (c.dataIndex === last ? 3 : 0) } },
}

Daily active accounts

Last 30 days. The thin line is a 7-day average that smooths weekends.

Time series
  • Accounts
  • 7-day average
Show config
labels: lastDays(30),   // real dates, built at load
scales: { x: { ticks: { maxTicksLimit: 7, maxRotation: 0 } } }

Staff on the floor

Holds flat until someone clocks in or out.

Stepped
Show config
{ stepped: true, pointRadius: 0 }

Orders by region

Four regions, one color each. Hover a month to read all four.

Multi-series
  • Northeast
  • Midwest
  • West
  • South
Show config
datasets: categories.map((c, i) => ({
  label: c.name, data: c.orders, borderColor: series[i],
})),
interaction: { mode: 'index', intersect: false }

Sessions and orders, same start

Both rebased so Monday is 100. Traffic dips on the weekend; orders hold.

Indexed
  • Sessions
  • Orders
  • Monday level
Show config
const index = (arr) => arr.map((v) => Math.round((v / arr[0]) * 100));
datasets: [{ data: index(sessions) }, { data: index(orders) }]

Monthly recurring revenue

Solid is actual, dashed is forecast, the band is the likely range.

Forecast with range
  • Actual
  • Forecast
  • Likely range
Show config
{ label: 'High', data: high, pointRadius: 0, borderWidth: 0 },
{ label: 'Low',  data: low,  pointRadius: 0, borderWidth: 0, fill: '-1',
  backgroundColor: tint(series1, .16) },
{ label: 'Forecast', data: forecast, borderDash: [6, 5] }

Trials started per month

The best and worst months are marked, so no hovering is needed.

Annotations
Show config
pointRadius: data.map((v, i) => (i === best || i === worst ? 5 : 0)),
plugins: [{ id: 'callouts', afterDatasetsDraw(chart) { /* label pills */ } }]

Paying accounts

Every point carries its value, for reports and screenshots.

Data labels
Show config
plugins: [{
  id: 'values',
  afterDatasetsDraw(chart) { /* fillText(value, point.x, point.y - 12) */ },
}]

Sessions by channel

One small chart per channel on one scale, so shapes compare easily.

Small multiples
Search2.9k
Direct1.6k
Ads1.1k
Email1.0k
Referral900
Social400
Show config
// One chart per channel, all sharing the same y maximum
scales: { y: { display: false, min: 0, max: sharedMax } }

Weekly orders by state

Pick a state to bring its line forward; the rest stay gray.

Highlight one
Show config
chart.data.datasets.forEach((ds, i) => {
  ds.borderColor = i === picked ? series1 : gray;
  ds.order = i === picked ? 0 : 1;   // lower order draws on top
});
chart.update();

Newsletter sign-ups per week

Same numbers twice: straight in gray, curved on top.

Smoothed
  • Curved, tension 0.4
  • Straight
Show config
{ tension: 0.4, cubicInterpolationMode: 'default', pointRadius: 0 }

Deals closed against target

Solid for this year, dashed for target, dotted for last year.

Dashed and dotted
  • This year
  • Target
  • Last year
Show config
{ label: 'Target',    borderDash: [6, 5] },
{ label: 'Last year', borderDash: [1, 4], borderCapStyle: 'round' }

Days from order to delivery

The band is the 2 to 4 day promise. Dots mark late days.

Target range
  • Average days
  • Promise, 2 to 4 days
  • Late
Show config
plugins: [{
  id: 'band',
  beforeDatasetsDraw({ ctx, chartArea, scales: { y } }) {
    const top = y.getPixelForValue(4), bottom = y.getPixelForValue(2);
    ctx.fillRect(chartArea.left, top, chartArea.width, bottom - top);
  },
}]

Store revenue

A soft fill gives the line weight. Flat turns it into one even tint.

Gradient fill
Show config
fill: true,
backgroundColor: ({ chart: { ctx, chartArea } }) => {
  const g = basaltGradient(ctx, 0, chartArea.top, 0, chartArea.bottom);
  g.addColorStop(0, tint(series2, .3));
  g.addColorStop(1, tint(series2, 0));
  return g;
}

Average order value

The plainest version: one series, no fill.

Basic
Show config
new Chart(canvas, {
  type: 'line',
  data: { labels, datasets: [{ label: 'Average order', data, tension: 0 }] },
});