2.0.2-dev • Published 6 days ago

chartscii v2.0.2-dev

Weekly downloads
54
License
MIT
Repository
github
Last release
6 days ago

npm.io

install

npm install chartscii

usage

chartscii accepts an array of data objects, with optional labels, and outputs an ascii bar chart.

usage example

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:

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:

import Chartscii, {ChartData} from 'chartscii';

const data: Array<ChartData> = [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

[{ value: 2, label: 'some_label' }, { value: 2, label: 'some_label' }] 
[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

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

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.

themed charts

2.0.1-dev

6 days ago

2.0.2-dev

6 days ago

2.0.0-dev

6 days ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.8

3 years ago

1.2.9

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.0.44

4 years ago

1.0.46

4 years ago

1.0.41

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago