I'm using jfreechart with both Wicket and WebObjects - there isn't much you have to do.

I created a class ChartResource that extends DynamicImageResource. In that class I have this:


    protected byte[] getImageData() {

        JFreeChart tmpChart = this.getFactory().getChart();

        tmpChart.setBorderVisible(false);
        tmpChart.setBackgroundPaint(this.getChartBackgroundPaint());
        tmpChart.getPlot().setOutlinePaint(this.getPlotOutlinePaint());

tmpChart.getPlot().setBackgroundPaint(this.getPlotBackgroundPaint());

        ByteArrayOutputStream tmpStream = new ByteArrayOutputStream();

        try {
ChartUtilities.writeChartAsPNG(tmpStream, tmpChart, this.getWidth().intValue(), this.getHeight().intValue());
        } catch (IOException anException) {
            // TODO Something!!
        }

        return tmpStream.toByteArray();
    }


Erik Brakkee wrote:
Decebal Suiu wrote:
Any example about how to display a chart generated
with jfreechart in a WebPage?
I am going to do the same for my application (trackdetective.com) for
displaying height profiles of GPS tracks.
Just browsed a little through the APIs. It seems you can use the Image
class. The most general constructor is

     public Image(final String id, final Resource imageResource)

In this way you can determine for yourself where it gets the input from.
Perhaps BlobImageResource or its super class DynamicImageResource are
good resource implementations for this.

I found a link about this topic
(http://www.nabble.com/JFreeChart-Experiment-tf1824840.html#a4977424)
but the link containing the source code is broken.

Thanks,
Decebal



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642



--
http://ojalgo.org/

Mathematics, Linear Algebra and Optimisation with Java
/*
 * Copyright © 2005 Optimatika (www.optimatika.se)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package se.optimatika.wicket.markup.html;

import java.awt.Paint;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Locale;

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

import se.optimatika.jfree.chart.AbstractChartFactory;
import se.optimatika.jfree.chart.ColourPalette;

import wicket.markup.html.image.resource.DynamicImageResource;
import wicket.protocol.http.WebResponse;

public abstract class ChartResource extends DynamicImageResource {

    private static final String CONTENT_TYPE = "image/png";

    private Paint myChartBackgroundPaint = 
ColourPalette.getInstance().getWhite();
    // private transient byte[] myData;
    private Number myHeight = 240;
    private Paint myPlotBackgroundPaint = 
ColourPalette.getInstance().getWhite();
    private Paint myPlotOutlinePaint = ColourPalette.getInstance().getWhite();
    private Number myWidth = 320;

    public ChartResource() {

        super();

        this.configure();
    }

    public ChartResource(Locale newLocale) {

        super(newLocale);

        this.configure();
    }

    public Paint getChartBackgroundPaint() {
        return myChartBackgroundPaint;
    }

    public String getContentType() {
        return CONTENT_TYPE;
    }

    public abstract AbstractChartFactory getFactory();

    public Number getHeight() {
        return myHeight;
    }

    public Paint getPlotBackgroundPaint() {
        return myPlotBackgroundPaint;
    }

    public Paint getPlotOutlinePaint() {
        return myPlotOutlinePaint;
    }

    public Number getWidth() {
        return myWidth;
    }

    public void setChartBackgroundPaint(Paint newChartBackgroundPaint) {
        myChartBackgroundPaint = newChartBackgroundPaint;
    }

    public void setHeight(Number newHeight) {
        myHeight = newHeight;
    }

    public void setPlotBackgroundPaint(Paint newPlotBackgroundPaint) {
        myPlotBackgroundPaint = newPlotBackgroundPaint;
    }

    public void setPlotOutlinePaint(Paint newPlotOutlinePaint) {
        myPlotOutlinePaint = newPlotOutlinePaint;
    }

    public void setWidth(Number newWidth) {
        myWidth = newWidth;
    }

    private void configure() {
        this.setCacheable(false);
    }

    protected byte[] getImageData() {

        JFreeChart tmpChart = this.getFactory().getChart();

        tmpChart.setBorderVisible(false);
        tmpChart.setBackgroundPaint(this.getChartBackgroundPaint());
        tmpChart.getPlot().setOutlinePaint(this.getPlotOutlinePaint());
        tmpChart.getPlot().setBackgroundPaint(this.getPlotBackgroundPaint());

        ByteArrayOutputStream tmpStream = new ByteArrayOutputStream();

        try {
            ChartUtilities.writeChartAsPNG(tmpStream, tmpChart, 
this.getWidth().intValue(), this.getHeight().intValue());
        } catch (IOException anException) {
            // TODO Something!!
        }

        return tmpStream.toByteArray();
    }

    @Override
    protected void setHeaders(WebResponse response) {

        if (this.isCacheable()) {
            super.setHeaders(response);
        } else {
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
            response.setHeader("Cache-Control", "private");
            response.setHeader("Cache-Control", "no-store");
        }

    }

}
/*
 * Copyright © 2004 Optimatika (www.optimatika.se)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package se.optimatika.jfree.chart;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;

/**
 * AbstractChartFactory
 * 
 * @author apete
 */
public abstract class AbstractChartFactory {

    public static final int TYPE_AreaChart = 1;
    public static final int TYPE_BarChart = 2;
    public static final int TYPE_BarChart3D = 3;
    public static final int TYPE_LineChart = 4;
    public static final int TYPE_MultiplePieChart = 5;
    public static final int TYPE_MultiplePieChart3D = 6;
    public static final int TYPE_PieChart = 7;
    public static final int TYPE_PieChart3D = 8;
    public static final int TYPE_ScatterPlot = 9;
    public static final int TYPE_StackedAreaChart = 10;
    public static final int TYPE_StackedAreaXYChart = 11;
    public static final int TYPE_StackedBarChart = 12;
    public static final int TYPE_StackedBarChart3D = 13;
    public static final int TYPE_TimeSeriesChart = 14;
    public static final int TYPE_WaterfallChart = 15;
    public static final int TYPE_XYAreaChart = 16;
    public static final int TYPE_XYLineChart = 17;
    public static final int TYPE_XYStepAreaChart = 18;
    public static final int TYPE_XYStepChart = 19;

    private Boolean myLegend = Boolean.FALSE;

    private PlotOrientation myOrientation = PlotOrientation.VERTICAL;
    private String myTitle = null;
    private int myType = 0;

    public AbstractChartFactory() {
        super();
    }

    public abstract JFreeChart getChart();

    public PlotOrientation getOrientation() {
        return myOrientation;
    }

    public String getTitle() {
        return myTitle;
    }

    public int getType() {
        return myType;
    }

    public Boolean hasLegend() {
        return myLegend;
    }

    public void setLegend(Boolean newLegend) {
        myLegend = newLegend;
    }

    public void setOrientation(PlotOrientation newOrientation) {
        myOrientation = newOrientation;
    }

    public void setTitle(String newTitle) {
        myTitle = newTitle;
    }

    public void setType(int newType) {
        myType = newType;
    }

}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to