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-chartyarn add simple-ascii-chartOnce 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-cliOnce installed, you can generate charts directly in your terminal:
simple-ascii-chart "[[1, 1], [2, 4], [3, 8]]" --width 20 --height 10This 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.
- input: The data for the chart, provided as an array of arrays (points).
- settings: Optional settings for customizing the chart appearance (e.g., width, height).
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 3Error responses return JSON in a standardized shape: { error: { code, message, details? } }