On the JFreeChart web site it says that the library can output the chart in vector format.
From the JFreeChart site:
- support for many output types, including Swing components, image files (including PNG and JPEG), and vector graphics file formats (including PDF, EPS and SVG);
But how can I actually output in SVG format?
There is a way using the Apache Batik library, but from the statement above I would think JFreeChart can do it without Batik.
I could figure out the output for PNG and JPG in the ChartUtilities class, but there seems to be no class for vector graphics output.
No, JFreeChart
supports SVG in the sense that it can be used in conjunction with Batik
or JFreeSVG
, which are required. Related resources include these:
The JFreeChart Developer Guide†, discussed here.
JFreeSVG
, which can "generate content in SVG format using the standard Java2D
drawing API, Graphics2D
." Demonstration programs may be found here, including this SVGBarChartDemo1
excerpt:
JFreeChart chart = createChart(createDataset());
SVGGraphics2D g2 = new SVGGraphics2D(600, 400);
Rectangle r = new Rectangle(0, 0, 600, 400);
chart.draw(g2, r);
File f = new File("SVGBarChartDemo1.svg");
SVGUtils.writeToSVG(f, g2.getSVGElement());
†Disclaimer: Not affiliated with Object Refinery Limited; just a satisfied customer and very minor contributor.