problem using Batik + JFreeChart

Discussion in 'Java' started by Lordy, Sep 13, 2003.

  1. Lordy

    Lordy Guest

    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
    Lordy, Sep 13, 2003
    #1
    1. Advertising

  2. Lordy

    Lordy Guest

    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.

    Lordy
    Lordy, Sep 13, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shripathi Kamath

    Question on JFreeChart and Batik

    Shripathi Kamath, Nov 26, 2003, in forum: Java
    Replies:
    0
    Views:
    2,316
    Shripathi Kamath
    Nov 26, 2003
  2. Mardagg
    Replies:
    0
    Views:
    803
    Mardagg
    May 12, 2006
  3. Replies:
    0
    Views:
    540
  4. milof83

    editing svg in batik problem

    milof83, Aug 18, 2006, in forum: Java
    Replies:
    0
    Views:
    372
    milof83
    Aug 18, 2006
  5. Replies:
    13
    Views:
    1,337
    Andrew Thompson
    Mar 19, 2007
Loading...

Share This Page