Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Last active August 29, 2015 14:07
Show Gist options
  • Save ben-bradley/282674a12cefd5feb9bc to your computer and use it in GitHub Desktop.
Save ben-bradley/282674a12cefd5feb9bc to your computer and use it in GitHub Desktop.
ASCII charts in the command line with Node.js
// http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html
var chart = require('ascii-chart'),
_ = require('lodash');
var data = [];
var out = process.stdout;
out.write('\033[2J'); // clear the screen
setInterval(function () {
var datum = _.random(0, 100);
data.push(datum);
data = _.last(data, 40);
out.write('\033[0;0H'); // set the cursor to 0;0
datum = (datum < 10) ? ' ' + datum : (datum < 99) ? ' ' + datum : datum;
console.log('Current: ' + datum);
out.write(chart(data, {
width: 80,
height: 20
}));
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment