generating SVG from JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Akmal

generating SVG from JFreeChart

Post by Akmal » Thu Nov 29, 2001 2:22 pm

Hello David!

I do not know if someone else contributed this, but I thought it would be interesting to share it with those interested in generating an SVG format, based on batik, from the charts:

...
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.GenericDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
...
private JFreeChart myChart;
//your code

DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();

Document document = domImpl.createDocument (null, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
myChart.draw(svgGenerator, new java.awt.geom.Rectangle2D.Double(0, 0, 800, 500));
boolean useCSS = true;
Writer outsvg = new OutputStreamWriter(new FileOutputStream("chart.svg"), "UTF-8");
svgGenerator.stream(outsvg, useCSS);

...

cheers :-)
Akmal

David Gilbert

RE: generating SVG from JFreeChart

Post by David Gilbert » Mon Dec 03, 2001 11:27 pm

Hi Akmal,

Thanks for the info...this looks pretty useful, I'll give it a try some time soon. And maybe extend the demo program for a future release.

Regards,

DG.

David Gilbert

RE: generating SVG from JFreeChart

Post by David Gilbert » Mon Jan 07, 2002 6:08 pm

I tried this out today and it works really well. For those that want to try out Batik, the link is:

http://xml.apache.org/batik

DG

Locked