Project

inkplot

0.0
The project is in a healthy, maintained state
Build line, bar, scatter, histogram, and other charts as standalone SVG or PNG.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 13.0
~> 4.1
~> 3.0
~> 1.0
 Project Readme

Inkplot

Build clear SVG and PNG charts from plain Ruby data.

CI Ruby 3.2+ MIT license

Inkplot draws line, scatter, bar, area, histogram, and step charts without runtime dependencies. SVG output uses only Ruby's standard library; optional PNG output needs tessel and glyphic.

Install

Install the gem:

gem install inkplot

Quick start

require "inkplot"

chart = Inkplot.line([3, 1, 4, 1, 5, 9], title: "A small series")
chart.save("series.svg")

Use the builder to combine series and configure axes:

chart = Inkplot.plot(width: 720, height: 420, theme: :dark) do |plot|
  plot.title "Quarterly requests"
  plot.x_axis(label: "Quarter")
  plot.y_axis(label: "Requests", min: 0)
  plot.line(%w[Q1 Q2 Q3 Q4], [18, 23, 28, 36], label: "Current")
  plot.line(%w[Q1 Q2 Q3 Q4], [14, 19, 21, 30], label: "Previous", dash: true)
  plot.hline(25, label: "Target")
  plot.legend(position: :top_right)
end

svg = chart.to_svg

PNG output

PNG rendering is optional and uses the pure Ruby Tessel and Glyphic gems:

gem install tessel glyphic
chart = Inkplot.line([3, 1, 4, 1, 5, 9], title: "A small series")
chart.save("series.png", scale: 2)
png_bytes = chart.to_png

Set Inkplot.config.font to a TrueType font path for Unicode text. Without a font path, PNG output uses Glyphic's small ASCII bitmap font; SVG uses the viewer's system fonts.

Data and output

Charts accept arrays, hashes, CSV tables, and records with string or symbol keys. Scales include linear, logarithmic, time (Time and Date), and ordered categories. Light and dark themes, grouped and stacked bars, annotations, and terminal sparklines are included.

latencies = [12, 13, 15, 15, 18, 21, 26, 42]
Inkplot.histogram(latencies, bins: :auto, x_label: "ms").save("latencies.svg")

For dated data, configure the x axis with type: :time. plot.annotate(x, y, "text") places text at a data point; hline and vline can also carry labels.

The gallery contains 20 runnable examples. Regenerate its SVG previews with:

ruby examples/gallery.rb

API contracts

  • to_svg returns a standalone SVG string; save writes .svg or .png files. to_png returns PNG bytes and to_image returns a Tessel::Image.
  • Paired x/y arrays must have the same length. Non-finite y values break line segments by default; use gaps: :connect to bridge them.
  • Explicit axis limits must be ordered. Log scales omit non-positive values. Time axes reject mixed time zones while preserving local daylight-saving transitions.
  • Invalid scales, colors, dimensions, and file extensions raise ArgumentError.
  • Charts provide _repr_svg_ for notebook frontends and to_inlay for Inlay; neither is a runtime dependency.

Development

bundle install
bundle exec rake verify

License

MIT. See LICENSE.txt.