S
Shripathi Kamath
I am trying to create SVG output for charts that can be produced by
JFreeChart.
I managed to figure out the necessary jar files to be included, and was able
to modify one of the demos to produce an SVG file. A SVG viewer shows the
correct output.
However, when I examine the SVG file, I see that the SVG generation looks
something like the following:
....
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M0 0 L500 0 L500 270 L0 270 L0 0 Z" />
</clipPath>
</defs>
<g style="font-family:sans-serif;" transform="translate(4,23)">
<image x="0" y="0" width="500"
xlink:href="data:image/png;base64,iVBORw0KGg....image data...mCC"
style="clip-path:url(#clipPath1);" height="270" preserveAspectRatio="none"
/>
</g>
</g>
I do not see the vector graphics instructions that actually create the
chart, instead I see the rendered image.
Of course, I can use Batik and see that vector graphics elements for lines,
rectangles, etc.. do indeed get produced when I create a drawing myself.
The question is what should I be doing so that I can use Batik to generate
an SVG file format (with no embedded images) chart from JFreeChart.
Does someone have an example they wouldn't mind sharing, or know of a place
on the web where this info is readily available?
Thanks.
Here is my sample code:
+++
public void createSVG(Component component)
{
// Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// Ask the object to render into the SVG Graphics2D implementation
component.update(svgGenerator);
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
try
{
Writer out = new OutputStreamWriter(new
FileOutputStream("output.svg"), "UTF-8");
svgGenerator.stream(out, useCSS);
out.close();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
and the sample modified.
public static void main(String[] args)
{
AreaChartDemo demo = new AreaChartDemo("Area Chart Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
demo.createSVG(demo);
}
+++
JFreeChart.
I managed to figure out the necessary jar files to be included, and was able
to modify one of the demos to produce an SVG file. A SVG viewer shows the
correct output.
However, when I examine the SVG file, I see that the SVG generation looks
something like the following:
....
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M0 0 L500 0 L500 270 L0 270 L0 0 Z" />
</clipPath>
</defs>
<g style="font-family:sans-serif;" transform="translate(4,23)">
<image x="0" y="0" width="500"
xlink:href="data:image/png;base64,iVBORw0KGg....image data...mCC"
style="clip-path:url(#clipPath1);" height="270" preserveAspectRatio="none"
/>
</g>
</g>
I do not see the vector graphics instructions that actually create the
chart, instead I see the rendered image.
Of course, I can use Batik and see that vector graphics elements for lines,
rectangles, etc.. do indeed get produced when I create a drawing myself.
The question is what should I be doing so that I can use Batik to generate
an SVG file format (with no embedded images) chart from JFreeChart.
Does someone have an example they wouldn't mind sharing, or know of a place
on the web where this info is readily available?
Thanks.
Here is my sample code:
+++
public void createSVG(Component component)
{
// Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// Ask the object to render into the SVG Graphics2D implementation
component.update(svgGenerator);
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
try
{
Writer out = new OutputStreamWriter(new
FileOutputStream("output.svg"), "UTF-8");
svgGenerator.stream(out, useCSS);
out.close();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
and the sample modified.
public static void main(String[] args)
{
AreaChartDemo demo = new AreaChartDemo("Area Chart Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
demo.createSVG(demo);
}
+++