What is babar?
The 'babar' npm package is a simple, ASCII bar chart generator for Node.js. It allows you to create bar charts directly in the terminal, which can be useful for quick visualizations of data without needing a graphical interface.
What are babar's main functionalities?
Basic Bar Chart
This feature allows you to create a basic bar chart with a set of data points. The code sample demonstrates how to generate a bar chart with data points representing a quadratic function.
const babar = require('babar');
const data = [
{ x: 0, y: 0 },
{ x: 1, y: 1 },
{ x: 2, y: 4 },
{ x: 3, y: 9 },
{ x: 4, y: 16 }
];
console.log(babar(data));
Customizing Bar Chart
This feature allows you to customize the appearance of the bar chart. The code sample shows how to set the width, height, and color of the bar chart.
const babar = require('babar');
const data = [
{ x: 0, y: 0 },
{ x: 1, y: 1 },
{ x: 2, y: 4 },
{ x: 3, y: 9 },
{ x: 4, y: 16 }
];
const options = {
width: 40,
height: 10,
color: 'green'
};
console.log(babar(data, options));
Multiple Series
This feature allows you to plot multiple series of data on the same bar chart. The code sample demonstrates how to plot two different sets of data points on the same chart.
const babar = require('babar');
const data = [
{ x: 0, y: 0 },
{ x: 1, y: 1 },
{ x: 2, y: 4 },
{ x: 3, y: 9 },
{ x: 4, y: 16 }
];
const data2 = [
{ x: 0, y: 16 },
{ x: 1, y: 9 },
{ x: 2, y: 4 },
{ x: 3, y: 1 },
{ x: 4, y: 0 }
];
console.log(babar([data, data2]));
Other packages similar to babar
cli-chart
The 'cli-chart' package is another tool for creating ASCII charts in the terminal. It offers more customization options compared to 'babar', such as different chart types (line, bar, etc.) and more control over the appearance of the charts.
asciichart
The 'asciichart' package is focused on creating simple and fast ASCII line charts. It is more lightweight than 'babar' and is ideal for quick visualizations of time series data.
sparkly
The 'sparkly' package generates sparklines (small inline charts) in the terminal. It is less feature-rich than 'babar' but is useful for embedding small charts within text output.
Babar
CLI bar charts for node.js
Babar is a simple node.js library to draw bar charts in your console.
While it isn't an advanced charting library, it can be useful to get a rought idea of:
- whether some data is random or not
- whether some data is linear, exponential, etc ...
Features:
- easy to use
- lightweight (~100 lines of code)
- color output
- ASCII output
- automatically bucketizes values (currently only averages values in a bucket)
- MIT license
Limitations:
- limited options
- only bar charts
- only one data set per graph
- limited accuracy
- only numerical labels
- only linear axes
Installation
npm install babar
Usage
Babar exposes a function whose signature expects at least an array of points, where a point is an array of two values [x, y]
. It returns a string representation of the data which can be output to your console.
var babar = require('babar');
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]));
While it does its best to render the data automatically, you can also pass along some options.
var babar = require('babar');
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]], {
color: 'green',
width: 40,
height: 10,
maxY: 10,
yFractions: 1
}));
Options
- caption: specify a caption to display over the bar chart
- color="cyan": specify a color ('yellow', 'cyan', 'white', 'magenta', 'green', 'red', 'grey', 'blue', or 'ascii')
- grid="black": specify a color ('yellow', 'cyan', 'white', 'magenta', 'green', 'red', 'grey', 'blue')
- width=80: output will fit in specified width
- height=15: output will fit in specified height
- xFractions: number of fractions for x labels, does its best by default
- yFractions: number of fractions for y labels, does its best by default
- minX: minimum x value for x axle
- maxX: maximum x value for x axle
- minY: minimum y value for y axle (negative values not supported yet)
- maxY: maximum y value for y axle
License
(The MIT License)
Copyright (c) 2013 Stephan Florquin
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.