Usage

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

Simple ASCII Chart generates ASCII-based charts in different environments: as a TypeScript library, through the CLI, or over the API.

Library usage

Install simple-ascii-chart with npm or yarn:

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

Import and call the chart function from application code:

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 usage

Generate ASCII charts from the command line with the Simple ASCII Chart CLI.

Install the CLI globally:

npm install -g simple-ascii-chart-cli

Then render a chart directly in the terminal:

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

API usage

The API supports GET query params and POST JSON requests.

GET accepts input and optional settings query parameters.

  • input: chart data as an array of points.
  • settings: optional chart appearance settings.
curl -G https://simple-ascii-chart.vercel.app/api \
  --data-urlencode 'input=[[1,2],[2,3],[3,4]]' \
  --data-urlencode 'settings={"width":50,"height":10}'
curl -X POST https://simple-ascii-chart.vercel.app/api \
  -H 'content-type: application/json' \
  -d '{"input":[[1,2],[2,3],[3,4]],"settings":{"width":50,"height":10}}'

Example API response:

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

Error responses return JSON as { error: { code, message, details? } }.