Build clear SVG and PNG charts from plain Ruby data.
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 the gem:
gem install inkplotrequire "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_svgPNG rendering is optional and uses the pure Ruby Tessel and Glyphic gems:
gem install tessel glyphicchart = Inkplot.line([3, 1, 4, 1, 5, 9], title: "A small series")
chart.save("series.png", scale: 2)
png_bytes = chart.to_pngSet 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.
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.rbto_svgreturns a standalone SVG string;savewrites.svgor.pngfiles.to_pngreturns PNG bytes andto_imagereturns aTessel::Image.- Paired x/y arrays must have the same length. Non-finite y values break line segments by default; use
gaps: :connectto 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 andto_inlayfor Inlay; neither is a runtime dependency.
bundle install
bundle exec rake verifyMIT. See LICENSE.txt.