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.
Hi Barny,
Are you doing any chart types not supported by cfchart using your technique? Just curious…
Fat fingers – make that Barney, not Barny!
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.
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.
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.
Hi Barney,
I'm entirely new to SVG (sadly, I know) and I was wondering if you could should me an example of coverting an SVG image to PNG using the built-in libraries of CF8.
Thanks a milion.
Here's another post that details a little more: http://www.barneyb.com/barneyblog/2005/10/06/coldfusion-and-batik/
Thanks Barney – I ran your example code and I'm getting a java error…
Object Instantiation Exception.
An exception occurred when instantiating a Java object. The class must not be an interface or an abstract class. Error: org/apache/batik/dom/util/DocumentFactory.
If you want to see the full error, here is a link:
http://www.sterling-staging.com/svg.cfm
I'm sorry to bug you, but you're the only help I have found online.
@Barney – I found the problem. I was putting stuff in the CFFORMS folder inadvertently.
That code is a couple years old, so it might not work with modern CF. Here's one that runs on my CF8 box: http://barneyb.com/r/svg_demo.cfm
Thanks so much Barney- its working like a charm now!
Well I guess I thought I had it too soon… Is there some trick to linking in image files
This code causes the renderer to return a blank white screen:
Do i need to use a complete path?
<image y="87.727219″ x="1″ height="189″ width="300″ xlink:href="{imgName}" />
I've not tried to embed images into the SVG before running it through Batik, so I don't know. I'd wager that you need a fully-qualified URL in there, because Batik is going to be executing in an isolated context, and thus unable to resolve relative paths. That's just a guess though.
Hi Barney – the way I got the image to work was to use a full URI: file:///c:/inetpub/wwwroot/blah.jpg
I'm still trying to figure out why the font render so ugly. If I render it huge (500%) – it seems to make it antialiased, but if I got 100% it look jagged and hideous.
Having no luck getting this code (including the CF8 example in the comments) to render on CF9, either with the built-in Batik libraries or ones that I install myself. The best I can get it to do is output an empty or unreadable PNG. Any thoughts? Anyone gotten Batik to behave on CF9?
Zane,
I haven't tried with CF9. I use Google Charts (http://code.google.com/apis/chart/) pretty much exclusively these days, and ported almost all of my old Batik-based stuff over (before CF9 released). The one app I haven't moved still runs on CF7 and probably will for the remainder of it's life.