JSPM

  • Created
  • Published
  • Downloads 376
  • Score
    100M100P100Q95762F
  • License MIT

create beautiful ascii charts

Package Exports

  • chartscii

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chartscii) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

  • 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