To render a chart in SVG, you must create an XML input file that represents the chart you want to render. The XML file should contain the raw data and configuration data needed by the chart service to create the chart. The following is a fragment of code that will allow you to generate a SVG chart. The line numbers are shown to further explain the code fragment.
1 FileInputStream inputStream = new FileInputStream(new File("chart.xml"));
2 IChart chart = SerializerImpl.instance().read(inputStream);
3 IRenderer renderer = new SVGRenderer();
4 FileOutputStream outputStream = new FileOutputStream(new File("chart.svg"));
5 renderer.setProperty(IRenderer.OUTPUTSTREAM_IDENTIFIER, outputStream);
6 Generator.instance().run(renderer, chart);
Line 1 - In this line an input stream from an XML file is created. The XML file is formatted based on the input schema and contains the raw data and configuration data for the chart.
Line 2 - The SerializerImpl class provides a read method that will allow one to take the XML stream and construct an internal representation of the chart object model. It should be noted that the serializer interface can also consume a XML document object model instead of an input stream. Therefore, a developer can construct the XML document object model in memory and pass in this DOM to the serializer.
Line 3 - Construct the SVG device renderer.
Line 4 - An output stream is created that will generate an svg file called chart.svg.
Line 5 - We use the setProperty method on the renderer interface to pass in configuration information to the renderer. Here we set the outputstream that the SVG renderer will use to write the generated SVG chart.
Line 6 - This line generates and writes the chart to the output stream, created on line 4, based on the chart model which was parsed in Line 2.
Related reference
Formatting input data for charting
Programmer's Guide