Charts to display in your console or terminal. Input an Array with numbers like [1, 4, 11, 3, 9, 0, 2, 5]
or objects [{label: "Apples", value: 5}, {label: "Oranges", value: 7}, {label: "Bananas", value: 8}]
. Arrays of numbers will be converted into objects with the label of the index + 1.
Please note: ConsoleCharts is not yet finished. This readme describes the features already working. There is more to come.
class ConsoleCharts
(data array
)
- Sorts the array of objects.
- Param
order
can be set to "ASC" or "DESC". Default "ASC" - Param
sortBy
can be set to "label" or "value", so that you can order either by the values or the label. (Ifnumber
, then numeric. Ifstring
, then by the first character.) Default "value" - return
ConsoleCharts
- Returns multiline string with a vertical bar chart
- Param
options
is optional:minHeight
default false
The smallest value will be displayed starting by one step.pattern
default false
Every second bar gets a different pattern.spaced
default false
Space between bars.hideLabels
default false
Hide / Do not display any labels at the axis.type
default "sideways-bar"
Defines the barchart type. Possible Values are:
- return
string
- Converts the data array to a normal array
- To enable reuse of charted data
- Param
property
is optional. It can be "value" or "label". Default "value" - return
array
let ch = new ConsoleCharts([1, 4, 11, 3, 9, 0, 2, 5]);
console.log(ch.chart());
1 │█
4 │████
11 │███████████
3 │███
9 │█████████
0 │
2 │██
5 │█████
└───────────
let ch = new ConsoleCharts([9, 4, 11, 3, 9, 21, 2, 5]);
console.log(ch.chart({minHeight: true}));
1 │║████████ 9
2 │║███ 4
3 │║██████████ 11
4 │║██ 3
5 │║████████ 9
6 │║████████████████████ 21
7 │║█ 2
8 │║████ 5
└─────────────────────
let ch = new ConsoleCharts([9, 4, 11, 3, 9, 21, 2, 5]);
console.log(ch.chart(minHeight: true, pattern: true));
1 │║████████ 9
2 │║▓▓▓ 4
3 │║██████████ 11
4 │║▓▓ 3
5 │║████████ 9
6 │║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 21
7 │║█ 2
8 │║▓▓▓▓ 5
└─────────────────────
let obj = new ConsoleCharts([{label: "Apples", value: 5}, {label: "Oranges", value: 7}, {label: "Bananas", value: 8}, {label: "Pears", value: 10}, {label: "Grapes", value: 4}, {label: "Pineapples", value: 5}, {label: "Strawberries", value: 12}, {label: "Watermelons", value: 3}, {label: "Mangos", value: 3}, {label: "Lemons", value: 6}, {label: "Limes", value: 4}, {label: "Peaches", value: 10}]);
console.log(obj.chart({ pattern: true }));
Apples │█████ 5
Oranges │▓▓▓▓▓▓▓ 7
Bananas │████████ 8
Pears │▓▓▓▓▓▓▓▓▓▓ 10
Grapes │████ 4
Pineapples │▓▓▓▓▓ 5
Strawberries │████████████ 12
Watermelons │▓▓▓ 3
Mangos │███ 3
Lemons │▓▓▓▓▓▓ 6
Limes │████ 4
Peaches │▓▓▓▓▓▓▓▓▓▓ 10
└───────────────
let obj = new ConsoleCharts([{label: "Apples", value: 5}, {label: "Oranges", value: 7}, {label: "Bananas", value: 8}, {label: "Pears", value: 10}, {label: "Grapes", value: 4}, {label: "Pineapples", value: 5}, {label: "Strawberries", value: 12}, {label: "Watermelons", value: 3}, {label: "Mangos", value: 3}, {label: "Lemons", value: 6}, {label: "Limes", value: 4}, {label: "Peaches", value: 10}]);
obj.sort("DESC", "label");
console.log(obj.chart({ pattern: true }));
Watermelons │███ 3
Strawberries │▓▓▓▓▓▓▓▓▓▓▓▓ 12
Pineapples │█████ 5
Pears │▓▓▓▓▓▓▓▓▓▓ 10
Peaches │██████████ 10
Oranges │▓▓▓▓▓▓▓ 7
Mangos │███ 3
Limes │▓▓▓▓ 4
Lemons │██████ 6
Grapes │▓▓▓▓ 4
Bananas │████████ 8
Apples │▓▓▓▓▓ 5
└───────────────
let obj = new ConsoleCharts([{label: "Apples", value: 5}, {label: "Oranges", value: 7}, {label: "Bananas", value: 8}, {label: "Pears", value: 10}, {label: "Grapes", value: 4}, {label: "Pineapples", value: 5}, {label: "Strawberries", value: 12}, {label: "Watermelons", value: 3}, {label: "Mangos", value: 3}, {label: "Lemons", value: 6}, {label: "Limes", value: 4}, {label: "Peaches", value: 10}]);
console.log(obj.sort("ASC", "value").chart({ pattern: true }));
Watermelons │███ 3
Mangos │▓▓▓ 3
Grapes │████ 4
Limes │▓▓▓▓ 4
Apples │█████ 5
Pineapples │▓▓▓▓▓ 5
Lemons │██████ 6
Oranges │▓▓▓▓▓▓▓ 7
Bananas │████████ 8
Pears │▓▓▓▓▓▓▓▓▓▓ 10
Peaches │██████████ 10
Strawberries │▓▓▓▓▓▓▓▓▓▓▓▓ 12
└───────────────
let obj = new ConsoleCharts([{label: "Apples", value: 5}, {label: "Oranges", value: 7}, {label: "Bananas", value: 8}, {label: "Pears", value: 10}, {label: "Grapes", value: 4}, {label: "Pineapples", value: 5}, {label: "Strawberries", value: 12}, {label: "Watermelons", value: 3}, {label: "Mangos", value: 3}, {label: "Lemons", value: 6}, {label: "Limes", value: 4}, {label: "Peaches", value: 10}]);
console.log(obj.chart({ type: "bar", spaced: true, pattern: true}));
│ █
│ █
│ ▓ █ ▓
│ ▓ █ ▓
│ █ ▓ █ ▓
│ ▓ █ ▓ █ ▓
│ ▓ █ ▓ █ ▓ ▓
│█ ▓ █ ▓ ▓ █ ▓ ▓
│█ ▓ █ ▓ █ ▓ █ ▓ █ ▓
│█ ▓ █ ▓ █ ▓ █ ▓ █ ▓ █ ▓
│█ ▓ █ ▓ █ ▓ █ ▓ █ ▓ █ ▓
│█ ▓ █ ▓ █ ▓ █ ▓ █ ▓ █ ▓
└────────────────────────
Apples (5)
Oranges (7)
Bananas (8)
Pears (10)
Grapes (4)
Pineapples (5)
Strawberries (12)
Watermelons (3)
Mangos (3)
Lemons (6)
Limes (4)
Peaches (10)
let objV = new ConsoleCharts([{label: "Apples", value: 5}, {label: "Oranges", value: 7}, {label: "Bananas", value: 8}, {label: "Pears", value: 10}, {label: "Grapes", value: 4}, {label: "Pineapples", value: 5}, {label: "Strawberries", value: 12}, {label: "Watermelons", value: 11}, {label: "Mangos", value: 10}, {label: "Lemons", value: 6}, {label: "Limes", value: 4}, {label: "Peaches", value: 10}]);
console.log(objV.chart({ type: "bar", spaced: true, pattern: true, hideLabels: true, minHeight: true}));
│ █
│ █ ▓
│ ▓ █ ▓ █ ▓
│ ▓ █ ▓ █ ▓
│ █ ▓ █ ▓ █ ▓
│ ▓ █ ▓ █ ▓ █ ▓
│ ▓ █ ▓ █ ▓ █ ▓ ▓
│█ ▓ █ ▓ ▓ █ ▓ █ ▓ ▓
│█ ▓ █ ▓ █ ▓ █ ▓ █ ▓ █ ▓
│═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═
└────────────────────────
let arr = new ConsoleCharts([{label: "Apples", value: 5}, {label: "Oranges", value: 7}, {label: "Bananas", value: 8}, {label: "Pears", value: 10}, {label: "Grapes", value: 4}, {label: "Pineapples", value: 5}, {label: "Strawberries", value: 12}, {label: "Watermelons", value: 11}, {label: "Mangos", value: 10}, {label: "Lemons", value: 6}, {label: "Limes", value: 4}, {label: "Peaches", value: 10}]);
console.log(arr.chart({ type: "dot", spaced: false, hideLabels: false, minHeight: false}));
│ ·
│ · · ·
│
│ ·
│ ·
│ ·
│· ·
│ · ·
│
│
│
│
└────────────
Apples (5)
Oranges (7)
Bananas (8)
Pears (10)
Grapes (4)
Pineapples (5)
Strawberries (12)
Watermelons (11)
Mangos (10)
Lemons (6)
Limes (4)
Peaches (10)