CF8 and Batik (for SVG)

I just discovered that CF8 ships with a more complete Batik than CF7 did. Out of the box it's capable of transcoding SVG graphics to PNGs, which CF7's implementation wasn't capable of doing. With CF7 you had to move the partial Batik that came bundled and replace it with a full version to get transcoding to work, but no more. I'm not sure what CF8 uses it for, but CF7 appeared to use it for CFFORM stuff. Perhaps that's been extended and requires a full Batik, or maybe something else does. My initial thought was maybe the new Image libraries supported SVG, but that doesn't seem to be the case.

"Why SVG?", you ask? Because CFCHART is remarkably inflexible (and rather clumsy to boot) to the point that I wrote my own charting engine. It's hardly a CFCHART replacement, but far better suited to some of the charts that I need to produce. I chose SVG (several years ago, mind you) because it was widely supported and it's all text based, which makes generating it with CF a breeze. It also works as-is, or can be transcoded to a "normal" graphic (though you lose the vector base if you go to a raster format) for easier consumption.

Edit: Rob asked about the charts in the comments, so here's an example chart: capacity.png.  It doesn't really represent the full capabilities (area plots, multiple y-axes, etc.), but you get the idea.  The x-axis is labeled with age in days, with zero being midnight this morning.  If you've ever seen/used RRDTool (often paired with MRTG) the idea is similar, except that my database isn't round robin, it's historical, so I can change the time period on my dashboards and get charts back as far as I have data, if I want them.  Here's the same chart with data back to the beginning: capacity2.png.  As you can see, tracking of the 'imageCapacity' series started later (by about six months) than tracking 'totalImageCount'.  And no, those execution times (in the lower right) aren't representative - I grabbed these after a fresh restart so caches were empty.

5 Responses to “CF8 and Batik (for SVG)”


  1. 1 Rob Brooks-Bilson

    Hi Barny,

    Are you doing any chart types not supported by cfchart using your technique? Just curious…

  2. 2 Rob Brooks-Bilson

    Fat fingers - make that Barney, not Barny!

  3. 3 barneyb

    Rob,

    It actually only supports one type of chart: a line/area chart. But it supports N y-axes (up to one per series), supports a decimal number line for the x-axis, supports negative numbers on the x-axis, and doesn't require a interpolated point on every series if any series has one.

    The use case is for "last 7 days" type charts, where a given series has points recorded on it periodically, and then you can view the last however long. I'll go edit the post in just a sec with a link to an example.

  4. 4 Mike

    That's the best reason I've heard so far to upgrade to CF8. I have an application that uses SVG to draw activity network diagrams in a browser using live data from a database (see http://www.teamtool.net/anp/anp.html). Previously I've had to persuade users either to use Firefox 2 to view the images (native SVG support) or use the Adobe SVG viewer plug-in for IE/FF1. But the plug-in doesn't work with Vista and this explains (sort of) why Adobe have no plans to upgrade it.

  5. 5 barneyb

    Mike,

    The code I posted last year at http://www.barneyb.com/barneyblog/2006/05/04/more-batik-goodness/ is what I'm still running on CF8 without changes if you need a jump start. Should be able to just drop that in, supply it with an 'svg' variable containing your SVG markup, and be done with it. If you want it file based, just change the Input/OutputStreams as needed.

Leave a Reply