L
Lordy
Hi all,
I'm trying to get a simple demo to create a chart using JFreeChart and
render as SVG using Batik. I keep getting a null pointer exception from
Batik when calling the chart.draw() method with SVGGraphics2D...
Here is the example code besed on the PieChartDemo by David Gilbert
<snip lots of imports>
public class PieChartDemo1 {
public PieChartDemo1(PrintWriter out) throws Exception {
// Batik: Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Batik: Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Batik: Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// JFreeChart: create a dataset...
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("One", new Double(43.2));
data.setValue("Two", new Double(10.0));
data.setValue("Three", new Double(27.5));
data.setValue("Four", new Double(17.5));
data.setValue("Five", new Double(11.0));
data.setValue("Six", new Double(19.4));
// JFreeChart: create the chart...
JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title
data, // data
false, // include legend
false, //tooltips
false //URLs
);
// set the background color for the chart...
chart.setBackgroundPaint(Color.yellow);
chart.draw(svgGenerator,new Rectangle2D.Double(0,0,1000,1000),null);
// 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
svgGenerator.stream(out, useCSS);
}
}
The stack trace is
at org.apache.batik.svggen.SVGGeneratorContext.doubleString(Unknown Source)
at org.apache.batik.svggen.SVGGraphics2D.drawString(Unknown Source)
at org.jfree.chart.TextTitle.drawHorizontal(Unknown Source)
at org.jfree.chart.TextTitle.draw(Unknown Source)
at org.jfree.chart.JFreeChart.drawTitle(Unknown Source)
at org.jfree.chart.JFreeChart.draw(Unknown Source)
at PieChartDemo1.<init>(PieChartDemo1.java:nn)
I could get more info if I recomplied the batik libraries with -g but I'm
hoping I missed something obvious. Its something to do with
rendering the title Any ideas?
Cheers,
Lordy
I'm trying to get a simple demo to create a chart using JFreeChart and
render as SVG using Batik. I keep getting a null pointer exception from
Batik when calling the chart.draw() method with SVGGraphics2D...
Here is the example code besed on the PieChartDemo by David Gilbert
<snip lots of imports>
public class PieChartDemo1 {
public PieChartDemo1(PrintWriter out) throws Exception {
// Batik: Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Batik: Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Batik: Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// JFreeChart: create a dataset...
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("One", new Double(43.2));
data.setValue("Two", new Double(10.0));
data.setValue("Three", new Double(27.5));
data.setValue("Four", new Double(17.5));
data.setValue("Five", new Double(11.0));
data.setValue("Six", new Double(19.4));
// JFreeChart: create the chart...
JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title
data, // data
false, // include legend
false, //tooltips
false //URLs
);
// set the background color for the chart...
chart.setBackgroundPaint(Color.yellow);
chart.draw(svgGenerator,new Rectangle2D.Double(0,0,1000,1000),null);
// 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
svgGenerator.stream(out, useCSS);
}
}
The stack trace is
at org.apache.batik.svggen.SVGGeneratorContext.doubleString(Unknown Source)
at org.apache.batik.svggen.SVGGraphics2D.drawString(Unknown Source)
at org.jfree.chart.TextTitle.drawHorizontal(Unknown Source)
at org.jfree.chart.TextTitle.draw(Unknown Source)
at org.jfree.chart.JFreeChart.drawTitle(Unknown Source)
at org.jfree.chart.JFreeChart.draw(Unknown Source)
at PieChartDemo1.<init>(PieChartDemo1.java:nn)
I could get more info if I recomplied the batik libraries with -g but I'm
hoping I missed something obvious. Its something to do with
rendering the title Any ideas?
Cheers,
Lordy