asciiplot
v1.0.0
Published
Nice-looking lightweight console ASCII line charts ╭┈╯ with no dependencies (clone of asciichart)
Downloads
834
Maintainers
Readme
asciiplot
Console ASCII line charts in pure Javascript (for NodeJS) with no dependencies (clone of asciichart). This code is absolutely free for any usage, you just do whatever you want.
Usage
NodeJS
npm install asciiplot
var asciiplot = require ('asciiplot')
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciiplot.plot (s0))
Options
The width of the chart will always equal the length of data series. The height and range are determined automatically.
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciiplot.plot (s0))
The output can be configured by passing a second parameter to the plot (series, config)
function. The following options are supported:
var config = {
offset: 3, // axis offset from the left (min 2)
padding: ' ', // padding string for label formatting (can be overrided)
height: 10, // any height you want
// the label format function applies default padding
format: function (x, i) { return (padding + x.toFixed (2)).slice (-padding.length) }
}
Scale To Desired Height
var s = []
for (var i = 0; i < 120; i++)
s[i] = 15 * Math.cos (i * ((Math.PI * 8) / 120)) // values range from -15 to +15
console.log (asciiplot.plot (s, { height: 6 })) // this rescales the graph to ±3 lines
Auto-range
var s2 = new Array (120)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciiplot.plot (s2))