Usage

Install simple-ascii-chart, render charts from TypeScript, use the CLI, or call the HTTP API.

Render charts from TypeScript code with the library, from a shell with the CLI, or over HTTP with the hosted API.

Library

Install simple-ascii-chart with npm or yarn:

npm install simple-ascii-chart
yarn add simple-ascii-chart

Import plot and pass it your data and settings:

import plot from 'simple-ascii-chart';

const input = [
  [1, 1],
  [2, 4],
  [3, 8],
  [4, 16],
];

const settings = { width: 20, height: 10 };
console.log(plot(input, settings));

CLI

Render charts from the command line with simple-ascii-chart-cli.

Install the CLI globally:

npm install -g simple-ascii-chart-cli

Then render a chart in the terminal:

simple-ascii-chart "[[1, 1], [2, 4], [3, 8]]" --width 20 --height 10

HTTP API

The hosted API renders charts with plot. It accepts GET requests with query parameters and POST requests with a JSON body. Both use the same fields.

GET accepts input and optional settings query parameters.

  • input: chart data as JSON: an array of [x, y] points, or an array of such arrays, one per series.
  • settings: a JSON object of plot settings, such as width and height.
curl -G https://simple-ascii-chart.gtktsc.com/api \
  --data-urlencode 'input=[[1,2],[2,3],[3,4]]' \
  --data-urlencode 'settings={"width":50,"height":10}'
curl -X POST https://simple-ascii-chart.gtktsc.com/api \
  -H 'content-type: application/json' \
  -d '{"input":[[1,2],[2,3],[3,4]],"settings":{"width":50,"height":10}}'

Example response

  ▲
 4┤   ┏━━
  │   ┃
 2┤ ┏━┛
 1┤━┛
  └┬─┬─┬▶
   1 2 3

Error responses are JSON objects shaped like { error: { code, message, details? } }.

Limits

  • Charts can be up to 300 columns wide and 150 rows tall. If you omit width or height, the size derived from your data must fit as well.
  • Input can contain up to 20 series and 10,000 points in total. Each axis can have up to 300 ticks.
  • POST bodies can be up to 256 KB and GET query strings up to 8,192 characters, so send larger charts with POST.
  • A request over a limit gets a JSON error with status 400, or 413 when the body is too large.
  • Successful GET responses can be cached by CDNs for one day.