Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tool3/chartscii
📊 create beautiful ascii charts
https://github.com/tool3/chartscii
ascii ascii-chart chart javascript npm-package
Last synced: 3 months ago
JSON representation
📊 create beautiful ascii charts
- Host: GitHub
- URL: https://github.com/tool3/chartscii
- Owner: tool3
- License: mit
- Created: 2020-02-19T06:12:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T18:48:15.000Z (4 months ago)
- Last Synced: 2024-02-29T19:49:19.656Z (4 months ago)
- Topics: ascii, ascii-chart, chart, javascript, npm-package
- Language: JavaScript
- Homepage: https://chartscii.netlify.app/
- Size: 3.14 MB
- Stars: 16
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-ascii - chartscii
README
[![](https://img.shields.io/static/v1?label=created%20with%20shellfie&message=📸&color=pink)](https://github.com/tool3/shellfie)
* command line usage see: [chartscii-cli](https://github.com/tool3/chartscii-cli)
* typescript usage [typescript](#typescript-usage-example)# install
```bash
npm install chartscii
```# usage
`chartscii` accepts an array of data objects, with optional labels, and outputs an ascii bar chart.## usage example
```js
const Chartscii = require('chartscii');// generate random chart data
const data = [];for (let i = 1; i <= 20; i++) {
data.push(Math.floor(Math.random() * 100) + 1);
}// create chart
const chart = new Chartscii(data, {
label: 'Example Chart',
theme: 'lush',
width: 50,
sort: true,
reverse: true,
color: 'pink'
});
console.log(chart.create(), 'example')
```outputs:
you can customize the acsii character for the bar chart using the `char` option. for example:
```js
const chart = new Chartscii(data, {
label: 'Example Chart',
theme: 'pastel',
width: 50,
char: 'â– ',
sort: true,
reverse: true,
color: 'green'
});
```outputs:
## typescript usage example
example usage in typescript:
```ts
import Chartscii, {ChartData} from 'chartscii';const data: Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const chart: Chartscii = new Chartscii(data, { naked: true });
console.log(chart.create());
```
# options
## data options
`chartscii` accepts data in objects or simply an array of numeric values
```js
[{ value: 2, label: 'some_label' }, { value: 2, label: 'some_label' }]
``````js
[3, 34, 45]
```### label (string)
a label for the data point.### value (number)
a value for a bar in a chart.### color (string)
a color to paint the bar (colors label as well if `colorLabel: true`)
color should correspond to the [supported colors](#supported-colors)## chart options
### label (string)
a label for the chart.### width (number)
the width of the chart, scales values accordingly
default: `100`### sort (boolean)
sort data
default: `false`### reverse (boolean)
reverse chart values order
default: `false`### char (string)
ascii char for bars
default: `â–ˆ`### fill (string)
fill chart with ascii character.
no default.
recommended: `â–‘`### color (string)
color bars in chart and label if provided.
see [colors](#colors)### percentage (boolean)
show percentage of each bar, using the highest value in the provided data array
default `false`### colorLabels (boolean)
color labels as well
default `false`### naked (boolean)
don't print chart ascii structure
default `false`## color
this lib uses `styl3`, which has built in themes, the string you input in the color property of the chart or of a data point, will change depending on the theme.
defaults to `pastel`.
these are the currently supported colors, provided as string in the data object (e.g `{ value: 3, color: 'green' }`) or for the entire chart as an option.
- red
- green
- yellow
- blue
- purple
- pink
- cyan
- orange> NOTE: you can also provide a string formatted color: '\x1b[32;1m'
> see: https://misc.flogisoft.com/bash/tip_colors_and_formatting### themed charts