Sparkline

Generate lightweight sparkline chart images in PHP using the GD extension.

Library
Composer
v2.4.0
70stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
57/100Fair
Development Activity68
Maintenance44
Community44
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture72
Code Quality74
Innovation60
Learning Curve88

davaxi/sparkline is a PHP library that renders sparklines - small, word-sized trend charts - as image files using the GD extension. You feed it a series of numeric values and it produces a compact PNG suitable for embedding in tables, dashboards, emails, or reports.

It supports customization of dimensions, line and fill colors, thickness, and DPI, and can output the image directly, save it to disk, or return it as base64, making it easy to drop inline trend visualizations into server-rendered PHP applications.

What You Get

  • A Sparkline class that turns an array of numbers into a chart image
  • Configurable width, height, DPI, line color, thickness, and fill
  • Multiple output modes: render inline, save to file, or return base64
  • GD-based rendering with no external services required
  • A simple API suited to embedding trends in tables and dashboards

Common Use Cases

  • Embedding inline trend charts in HTML tables and reports
  • Adding sparklines to server-rendered dashboards
  • Including small trend images in emails or PDFs
  • Visualizing time-series metrics compactly without a JS charting stack

Under The Hood

Architecture - The library exposes a Sparkline class in src/ that accepts a numeric data series and rendering options, normalizes the values to the target pixel canvas, and uses GD drawing primitives to plot the trend line (and optional fill) at the configured DPI before emitting the result. Output methods let callers stream the PNG to the browser, write it to disk, or return a base64-encoded string. Tech Stack - Pure PHP (>=8.0) depending on the GD and MBString extensions, packaged for Composer/Packagist. It ships a Dockerfile and docker-compose for a reproducible dev environment and uses PHPUnit for testing. Code Quality - The repository includes a tests/ suite with Code Climate maintainability and coverage badges and CI history, indicating reasonable engineering hygiene, though the project is minimally maintained with low recent activity. The scope is small and the code is straightforward. API Design - The API is compact and approachable: construct a Sparkline, set data and a few style options, then call a render/save/display method. The README’s example-driven documentation makes the common case trivial, keeping the learning curve low.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search