Gallery › Column and line chart

Column and line chart: Ambulance response time against the target

Like column; seriesTypes: {"Target": "line"} draws chosen series as lines, on the same scale.

Ambulance response time against the targetMedian minutes from call to arrival

Column and line chart of Median response and Target across 9 values of Month. Median response is highest for Jan (9.8) and lowest for Aug (8.2). Every value of Target is 9.

  • Median response
  • Target
0246810MinutesJanFebMarAprMayJunJulAugSep
02.557.510MinutesJanFebMarAprMayJunJulAugSep
Data for “Ambulance response time against the target”
MonthMedian responseTarget
Jan9.89
Feb9.49
Mar9.19
Apr8.79
May8.99
Jun9.69
Jul8.59
Aug8.29
Sep8.49

Source: Halcyon County sample data (fictional, for the demo)

The spec

This is everything OSCharts needed to draw the chart above. The data is a table: named columns and rows, the way it sits in a spreadsheet.

{
  "id": "response-vs-target",
  "type": "combo",
  "title": "Ambulance response time against the target",
  "subtitle": "Median minutes from call to arrival",
  "source": "Halcyon County sample data (fictional, for the demo)",
  "seriesTypes": {
    "Median response": "column",
    "Target": "line"
  },
  "format": {
    "maximumFractionDigits": 1
  },
  "yAxis": {
    "title": "Minutes"
  },
  "data": {
    "columns": [
      "Month",
      "Median response",
      "Target"
    ],
    "rows": [
      [
        "Jan",
        9.8,
        9
      ],
      [
        "Feb",
        9.4,
        9
      ],
      [
        "Mar",
        9.1,
        9
      ],
      [
        "Apr",
        8.7,
        9
      ],
      [
        "May",
        8.9,
        9
      ],
      [
        "Jun",
        9.6,
        9
      ],
      [
        "Jul",
        8.5,
        9
      ],
      [
        "Aug",
        8.2,
        9
      ],
      [
        "Sep",
        8.4,
        9
      ]
    ]
  }
}

Put it on a page

In a browser, load the two files and mount the chart:

<link rel="stylesheet" href="oscharts.css">
<script src="oscharts.js" defer></script>
<div id="chart"></div>
<script type="module">
  OSCharts.mount(document.getElementById("chart"), spec);
</script>

Or render it on a server or in a build step, so the chart is in the page before any JavaScript runs:

import { render } from "oscharts";
const html = render(spec);   // a complete, accessible <figure>

Command line: npx oscharts render spec.json > chart.html