Question on JFreeChart and Batik

Discussion in 'Java' started by Shripathi Kamath, Nov 26, 2003.

  1. 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);
    }

    +++

    --
    Shripathi Kamath
     
    Shripathi Kamath, Nov 26, 2003
    #1
    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. Lordy
    Replies:
    1
    Views:
    1,210
    Lordy
    Sep 13, 2003
  2. Brian K
    Replies:
    0
    Views:
    870
    Brian K
    Oct 12, 2003
  3. Dobedani
    Replies:
    0
    Views:
    560
    Dobedani
    May 12, 2005
  4. Brian K
    Replies:
    0
    Views:
    682
    Brian K
    Oct 12, 2003
  5. Laurent Rincon

    A question about the Batik Api

    Laurent Rincon, May 22, 2006, in forum: Java
    Replies:
    0
    Views:
    316
    Laurent Rincon
    May 22, 2006
Loading...

Share This Page