xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: JFreeChart to SVG, No XML Tag, Store Into String
Date Fri, 13 Apr 2007 10:05:12 GMT
Hi Villejck,

villejck <villejck@yahoo.com> wrote on 04/11/2007 04:03:56 PM:

> I would like to generate the SVG without these tags showing up:
>     <?xml version="1.0" encoding="UTF-8"?>
>     <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
> 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>

   This can be accomplished by 'calling 'getRoot()' on the
SVGGraphics2D to get the root of the generated SVG Tree.

The pass that Element to 
        batik.dom.util.DOMUtilities.writeNode(Node n, Writer w);

> I would also like to store the SVG code into a string or string buffer
> variable. Here is my current code:

   Use a java.io.StringWriter for the second argument.

> 
> public class export2svg {
> 
>    public static void main(String[] args) throws 
SVGGraphics2DIOException,
> UnsupportedEncodingException {
>       DefaultPieDataset dataset = new DefaultPieDataset();
>       dataset.setValue("1", 43.2);
>       dataset.setValue("2", 27.9);
>       dataset.setValue("3", 70.5);
> 
>       JFreeChart chart = ChartFactory.createPieChart(
>             "Sample Pie Chart",
>             dataset,
>             true,
>             true,
>             false);
> 
>       DOMImplementation domImpl =
> GenericDOMImplementation.getDOMImplementation();
> 
>       Document document = domImpl.createDocument(null, "svg", null);
> 
>       SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
> 
>       svgGenerator.getGeneratorContext().setPrecision(6);
>       svgGenerator.setSVGCanvasSize(new Dimension(200, 200));
> 
>       chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 200, 200), 
null);
> 
>       boolean useCSS = true;
>       Writer out = new OutputStreamWriter(System.out, "UTF-8");
> 
>       svgGenerator.stream(out, useCSS);
> 
>    }
> }
> 
> I appreciate any advice. Thank you!
> -- 
> View this message in context: http://www.nabble.com/JFreeChart-to-
> SVG%2C-No-XML-Tag%2C-Store-Into-String-tf3561707.html#a9947346
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message