You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by villejck <vi...@yahoo.com> on 2007/04/11 22:03:56 UTC

JFreeChart to SVG, No XML Tag, Store Into String

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'>

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

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


Re: JFreeChart to SVG, No XML Tag, Store Into String

Posted by th...@kodak.com.
Hi Villejck,

villejck <vi...@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