ADW-Charting - simple chart drawing with Common Lisp

Abstract

ADW-Charting is a simple chart drawing library for quickly creating nice-looking pie charts and line charts. It presents a function-oriented interface similar to Vecto, and saves results to PNG. Since ADW-Charting and all supporting libraries are written completely in Common Lisp, without depending on external non-Lisp libraries, it should work in any Common Lisp environment. ADW-Charting is available under a BSD-like license. The 'ADW' in the name is referencing my employer, Acceleration.net, who has sponsored much of this work. The current version is 0.5, released on January 18th, 2008.

The canonical location for ADW-Charting is http://ryepup.unwashedmeme.com/lisp/adw-charting/

Download shortcut:

http://ryepup.unwashedmeme.com/lisp/adw-charting/adw-charting.tgz

Contents

  1. Overview and Limitations
  2. Examples
  3. Dictionary
  4. Acknowledgements
  5. Feedback

Overview and Limitations

ADW-Charting is a library that provides a simple interface to the Vecto vector drawing library. It supports drawing on a canvas and saving the results to a PNG file. The API was designed to eliminate as many decisions as possible, and simply produce a reasonable result with minimal fuss. It tries to scale various elements of the chart to fit nicely, but sometimes this goes awry.

ADW-Charting depends on the following libraries:

The easiest way to install ADW-Charting and all its dependencies is ASDF-Install

ADW-Charting's function interface is similar to Vecto's interface: you create charts by setting up a chart context and adding or setting information on that chart.

There are many known limitations at this point. We've got some plans on how to solve some of these, and other aren't priorities for me, and might stay around for ahwile.

Related libraries

Examples

All examples are available in test/examples.lisp in the distribution.

Minimal Pie Chart

(with-pie-chart (300 200)
    (add-slice "A" 5.0d0)
    (add-slice "B" 2.0d0)
    (save-file "minimal-pie-chart.png"))

Minimal Line Chart

(with-line-chart (400 300)
    (add-series "A" '((-1 -2) (0 4) (1 5) (4 6) (5 -3)))
    (add-series "B" '((-1 4) (0 -2) (1 6) (5 -2) (6 5)))
    (save-file "minimal-line-chart.png"))

Customized Line Chart

(with-line-chart (400 300 :background '(.7 .5 .7))
    (add-series "A" '((-1 -2) (0 4) (1 5) (4 6) (5 -3)))
    (add-series "B" '((-1 4) (0 -2) (1 6) (5 -2) (6 5)))
    (add-series "C"
		'((-1 0) (0 3) (1 1) (2 5) (4 -6))
		:color '(.3 .7 .9))
    (set-axis :y "widgets" :label-formatter "~,2F")
    (set-axis :x nil
	      :draw-gridlines-p nil
	      :label-formatter #'(lambda (v)
                                   ;;could do something more interesting here
				   (format nil "#~a" (floor v))))
    (save-file "customized-line-chart.png"))

Dictionary

The following symbols are exported from the ADW-CHARTING package.

[Macro]
with-pie-chart (width height &key (background '(1 1 1))) &rest body
Evaluates body with a chart established with the specified dimensions as the target for chart commands, with the specified background.
[Function]
add-slice label value &key color
Adds a slice to the chart, with an optional color. A color will be automatically assigned if none is specified.
[Macro]
with-line-chart (width height &key (background '(1 1 1))) &rest body
Evaluates body with a chart established with the specified dimensions as the target for chart commands, with the specified background.
[Function]
add-series label data &key (color nil)
Add another series to the line chart. data is a list of (x y) pairs. A color will be automatically assigned if none is specified.
[Function]
set-axis axis title &key (draw-gridlines-p t) (label-formatter #'princ-to-string)
Sets the axis on the current line chart. axis must be either :x or :y. The label-formatter must be either a format control string or a function of 1 argument that returns a string with the desired axis label.
[Function]
save-file filename => truename
Draws the chart as a png file to the given path.

Acknowledgements

Thanks to:

Feedback

If you have any questions, comments, bug reports, or other feedback regarding ADW-Charting, please email Ryan Davis