how to generate chart with svg?

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

how to generate chart with svg?

Post by YaoYue » Tue May 21, 2002 3:54 am

as title,thanks

Bryan

Re: how to generate chart with svg?

Post by Bryan » Tue May 21, 2002 6:46 am

I do not know if this is the best way. But using apache batik.
Hope it helps
Bryan

try

/// SVG Support
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.*;
import org.w3c.dom.*;
import org.w3c.dom.DOMImplementation;

// Servlet
OutputStream out = response.getOutputStream();

/// Local File
OutputStream out = FileOutputStream(filename);

OutputStreamWriter writer = new OutputStreamWriter(out);
// Get a DOMImplementation
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);

/// Create an SVG Context to customise
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
ctx.setComment("Generated by JFreeServlet using Batik SVG Generator");

// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
svgGenerator.setSVGCanvasSize(new Dimension(width,height));
chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), null);


svgGenerator.stream(writer, false);

Locked