communication between turbine servlets and JFreeChart

"OSullivan, Michael" <[email protected]>
Newsgroups gmane.comp.jakarta.turbine.user
Message-ID <[email protected]>
Hi

I am trying to get my turbine app to display a dynamic chart using =
Jfreechart and Velocity templating but to no avail. I've been using the
= example below which was sent via one of the forum threads. I've
created = a Java Screen class (i.e not an action class) exactly the same
as in the = attached code and I have included the following image tag in
my velocity = template but to no avail.=20

<img src="$link.setPage("mrtg,Image.vm")" border="0"/>

To start I would just like to get this example working and then try and
= add tooltips and url drill down to the image. Should this be possible
= using the method outlined below. Any help would be greatly
appreciated.

Thanks
Regards, Mike


########################################################################
#=
#########################################################


Hi,

here is a simple example:

package de.byteaction.modules.screens.mrtg;


import org.apache.turbine.modules.screens.RawScreen;

import org.apache.turbine.util.RunData;

import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;

import java.io.OutputStream;

/**
 * @author buddy
 */
public class Image extends RawScreen
{
    /* (non-Javadoc)
     * @see =
org.apache.turbine.modules.screens.RawScreen#getContentType(org.apache.t
u=
rbine.util.RunData)
     */
    protected String getContentType(RunData data)
    {
        return "image/jpeg";
    }

    /* (non-Javadoc)
     * @see =
org.apache.turbine.modules.screens.RawScreen#doOutput(org.apache.turbine
.=
util.RunData)
     */
    protected void doOutput(RunData data) throws Exception
    {
        JFreeChart   chart =3D (JFreeChart) =
data.getSession().getAttribute("chart");
        OutputStream out =3D data.getResponse().getOutputStream();

        ChartUtilities.writeChartAsJPEG(out, chart, 800, 400);
        out.flush();
    }
}

I have build the chart inside my action and put it into the users =
Session. You could do that using
data.getUser().setTemp("image"),JFreeChart) also.
Then I have setup the screen like this. Now I can reference the screen =
in my image tags

&lt;img src=3D"$link.setPage("mrtg,Image.vm")" border=3D"0"/&gt;

kind regards=20

J=FCrgen Hoffmann
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.