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 accepts two query parameters:
- 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).
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}'
Example API call response:
▲
4┤ ┏━━
│ ┃
2┤ ┏━┛
1┤━┛
└┬─┬─┬▶
1 2 3