simple-ascii-chart

Create terminal-native TypeScript ASCII charts for CLIs, logs, API responses, dashboards, and developer documentation.

simple-ascii-chart

Simple ASCII Chart is a lightweight and flexible TypeScript library for customizable ASCII charts directly in terminal output. It visualizes two-dimensional data, multiple series, colors, formatting, thresholds, legends, and axis labels.

Simple ASCII Chart
Example code
let step = 0;
const interval = 0.1;
const maxPoints = 20;
const sinPoints: Point[] = [];
const cosPoints: Point[] = [];

setInterval(() => {
  console.clear();

  sinPoints.push([step, Math.sin(step)]);
  cosPoints.push([step, Math.cos(step)]);

  if (sinPoints.length > maxPoints) sinPoints.shift();
  if (cosPoints.length > maxPoints) cosPoints.shift();

  console.log(
    plot([sinPoints, cosPoints], {
      showTickLabel: true,
      color: ['ansiRed', 'ansiBlue'],
      width: 120,
      height: 16,
      yRange: [-1, 1],
      xLabel: 'Step (π)',
      yLabel: 'Amplitude',
      legend: { position: 'bottom', series: ['Sine', 'Cosine'] },
      axisCenter: [undefined, 0],
      formatter: (x, { axis }) => {
        if (axis === 'y') return x;
        return `${(x / Math.PI).toFixed(1)}π`;
      },
    }),
  );

  step += interval;
}, 200);

Generate compact charts where graphical rendering is not available: command-line tools, build logs, API responses, diagnostics, and lightweight dashboards.

Project article

Read the gtktsc.com write-up on the design choices behind simple-ascii-chart, from terminal defaults to API ergonomics: Designing simple-ascii-chart.

Support

If this project helps you, consider supporting the open-source work: Buy me a coffee.