how to generate chart with svg?
Re: how to generate chart with svg?
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);
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);