charting library taking form

It now does line charts and better pie charts, and has had a lot of bugs removed since the last post. We did some code review on it at work, brought some of the spaghetti under control, and included the library in an intranet app.

Here’s a sample line graph:

line-chart-sample.png

The (somewhat verbose) code for this:

(defun line-chart-sample ()
  "draws a simple line chart"
  (let* ((seriesA (make-instance 'series
				 :label "SeriesA"
					;data expressed as a list (x y) pairs
				 :data '((-1 -2) (0 4) (1 5) (4 6) (5 -3))))
	 (seriesB (make-instance 'series
				 :label "SeriesB"
				 :data '((-1 4) (0 -2) (1 6) (5 -2) (6 5))))
	 (chart (make-instance 'line-chart
			       :width 400
			       :background '(.7 .7 .7)
			       :series (list seriesA seriesB))))
    (render-chart chart "line-chart-sample.png")))

I’ll probably make some easier syntax for creating series, similar to the one I made for pie slices, but for now the CLOS approach has been working decently. My data is coming from clsql, so the code ends up more concise than this example.

There are a few spots internally where it gets a little nasty, needing to pass many things around to many functions. I may end up changing the style to use “with-line-chart” functions with some global variables tracking the current chart, but I’m not sure how that would work in a multi-threaded environment. Hell, I’m not sure if my existing code will work in a multi-threaded environment. The load on this intranet app is very low, so I may be lucky enough to get away with it.

3 Comments »

  1. Vilson Vieira said,

    January 8, 2008 @ 10:30 pm

    Hi Ryan,

    your charting library looks dead simple and so sexy :-) Do you think to turn it public as open source? I’m thinking to create a simple interface to CL to use a JS charting library like Plotr and maybe I can use your solution as a PNG export format.

    Cheers.

  2. ryan said,

    January 11, 2008 @ 4:04 pm

    vilson: Yes, I was considering tossing this out there. I want to add some axis labesl to the line charts and make some good documentation, which requires a lot of time. I’ll probably be asking for feedback on #lisp over the next month or so as I find time to put into this.

  3. Vilson Vieira said,

    January 11, 2008 @ 10:08 pm

    OK. I have my eyes on that :-)

RSS feed for comments on this post · TrackBack URI

Leave a Comment