Simple ASCII Chart is a versatile tool that allows you to generate ASCII-based charts in different environments: as a library, via the CLI, or through the API.

Library Usage

To use the simple-ascii-chart library in your project, install it via npm or yarn:

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

Once installed, import and use it in your code like this:

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

You can also generate ASCII charts from the command line using the Simple ASCII Chart CLI.

To install the CLI globally, run:

npm install -g simple-ascii-chart-cli

Once installed, you can generate charts directly in your terminal:

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

This command will output the chart directly in your terminal. For more details, visit the CLI GitHub repository.

API Usage

The API supports both GET query params and POST JSON requests.

For GET requests, use the same two query parameters as before: input and optional settings.

GET example:

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}'

POST example:

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 call response:

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

Error responses return JSON in a standardized shape: { error: { code, message, details? } }