Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > problem using Batik + JFreeChart

Thread Tools

problem using Batik + JFreeChart

Posts: n/a
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 =

// 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.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, useCSS);



The stack trace is

at org.apache.batik.svggen.SVGGeneratorContext.double String(Unknown Source)
at org.apache.batik.svggen.SVGGraphics2D.drawString(U nknown 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>(

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?

Reply With Quote
Posts: n/a
On Sat, 13 Sep 2003 04:33:25 +0100, Lordy wrote:

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

I've sorted it now after recompiling Batik with debug on.
The decimalFormat had not been set.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
jFreeChart in Applet using Eclipse IDE with VE Java 13 03-19-2007 04:16 PM
editing svg in batik problem milof83 Java 0 08-18-2006 10:20 AM
batik svg editing problem Java 0 08-18-2006 10:18 AM
[SVG] problem with SVG image drawing with Batik Library Mardagg Java 0 05-12-2006 02:12 PM
Question on JFreeChart and Batik Shripathi Kamath Java 0 11-26-2003 01:17 AM