You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by jose pascual ortiz <jp...@alu.um.es> on 2004/07/09 08:50:32 UTC

JFreeChart

Hi all. I am trying create a html page and a graphic created with
JFreeChart. Do you know how do this ?

Thans in advance.


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: JFreeChart

Posted by Eduardo Samboal <es...@telcomunity.com>.
I've never used jBoss, but with Tomcat it works fine just locating the 
library in the webapp lib directory.

Regards.

At 10:02 09/07/2004, you wrote:
>Do you use JBoss? where did you place the jfreechart jar library? I must
>locate it at server lib directory yo make my application work well. I want
>to move it to the application lib library. Can I?
>
>Thx,
>Nanda Firdausi
>
>On Fri, 09 Jul 2004 09:48:34 +0200, Eduardo Samboal
><es...@telcomunity.com> wrote:
>
>>Hi, i'm currently working in an webapp that uses Tapestry as its
>>presentation layer and JFreeChart to create a large variety of different
>>graphics. If you tell me what is exactly your problem, i could be able to
>>help you to resolve it.
>>
>>Regards.
>>
>>At 08:50 09/07/2004, you wrote:
>>>Hi all. I am trying create a html page and a graphic created with
>>>JFreeChart. Do you know how do this ?
>>>
>>>Thans in advance.
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: JFreeChart

Posted by Nanda Firdausi <na...@divusi.com>.
Do you use JBoss? where did you place the jfreechart jar library? I must  
locate it at server lib directory yo make my application work well. I want  
to move it to the application lib library. Can I?

Thx,
Nanda Firdausi

On Fri, 09 Jul 2004 09:48:34 +0200, Eduardo Samboal  
<es...@telcomunity.com> wrote:

> Hi, i'm currently working in an webapp that uses Tapestry as its
> presentation layer and JFreeChart to create a large variety of different
> graphics. If you tell me what is exactly your problem, i could be able to
> help you to resolve it.
>
> Regards.
>
> At 08:50 09/07/2004, you wrote:
>> Hi all. I am trying create a html page and a graphic created with
>> JFreeChart. Do you know how do this ?
>>
>> Thans in advance.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>     Eduardo Samboal
> <ma...@telcomunity.com>esamboal@telcomunity.com
>       Tlf Movil: 667644144
>
> <http://www.telcomunity.com/>www.telcomunity.com



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: JFreeChart

Posted by Eduardo Samboal <es...@telcomunity.com>.
Hi, i'm currently working in an webapp that uses Tapestry as its 
presentation layer and JFreeChart to create a large variety of different 
graphics. If you tell me what is exactly your problem, i could be able to 
help you to resolve it.

Regards.

At 08:50 09/07/2004, you wrote:
>Hi all. I am trying create a html page and a graphic created with
>JFreeChart. Do you know how do this ?
>
>Thans in advance.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


    Eduardo Samboal
<ma...@telcomunity.com>esamboal@telcomunity.com
      Tlf Movil: 667644144

<http://www.telcomunity.com/>www.telcomunity.com

Re: JFreeChart

Posted by Jeff LaMarche <je...@mac.com>.
I stumbled across @ServiceLink mere moments after sending that 
e-mail... sorry to have bothered you.. =)


On Jul 9, 2004, at 3:20 PM, Shawn Church wrote:

> Jeff,
>
> IChartProvider is a minimal interface which looks like this:
>
> import org.jfree.chart.JFreeChart;
>
> /**
>  *  An object which can provide a {@link org.jfree.chart.JFreeChart}
> (to the {@link ChartService}).
>  **/
>
> public interface IChartProvider
> {
>     public JFreeChart getChart();
> }
>
>
> The class I have which implements IChartProvider is called ChartPage,
> and its implementation of getChart() creates and returns a JFreeChart.
> Below is my abbreviated code to create the chart, although there is
> nothing Tapestry-specific about the getChart() method itself.  I've
> stripped out a bunch of code since I'm doing some funny things with the
> chart image (we wanted the chart to have an image of one of our
> machines climbing up the line ;), but maybe it will be useful to you.
>
> The getChartImageAsset() is important however, since it provides the
> IAsset needed by the @Image component:
>
> public abstract class ChartPage extends BasePage
>    implements PageRenderListener, IChartProvider
> {
>    ...
>
>    public IAsset getChartImageAsset()
>    {
>       if (chartImageAsset == null)
>          chartImageAsset = new ChartAsset(getRequestCycle(), this);
>
>       return chartImageAsset;
>    }
>
>    public JFreeChart getChart()
>    {
>
>      String[] xAxisLabels = {"Sep", "Oct", "Nov", "Dec", "Jan",
>                               "Feb", "Mar", "Apr", "May", "Jun", "Jul",
> "Aug"};
>
>      ArrayList sections = getSections();
>      Iterator sectionIter = sections.iterator();
>      DefaultTableXYDataset dataset = new DefaultTableXYDataset();
>      int lastval = 0;
>      while (sectionIter.hasNext())
>      {
>         String section = (String) sectionIter.next();
>         XYSeries dataSeries = new XYSeries(section, true, false);
>
>         while (true)
>         {
>            lastval = 0;
>            double val = _salesData.getSepytd().doubleValue();
>            if (val <= 0)
>               break;
>            dataSeries.add(lastval++, val);
> 			
> 			...
>
>         }
>
>         dataset.addSeries(dataSeries);
>      }
>
>      //  Create the X-Axis
>      SymbolicAxis xAxis = new SymbolicAxis(null, xAxisLabels);
>      xAxis.setRange(0, 12);
>      xAxis.setLowerMargin(0.0);
>      xAxis.setUpperMargin(0.0);
>
>      //  Create the Y-Axis
>      NumberAxis yAxis = new NumberAxis(null);
>      yAxis.setRange(0, 55000000);
>      yAxis.setLabel("Sales");
>
>      //  Create the renderer
>      StackedXYAreaRenderer renderer =
>         new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);
>
>      renderer.setShapePaint(Color.gray);
>      renderer.setShapeStroke(new BasicStroke(0.5f));
>      renderer.setShape(new Ellipse2D.Double(-3, -3, 6, 6));
>      renderer.setOutline(true);
>
>      //  Create the plot
>      XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
>      plot.setForegroundAlpha(0.65f);
>
>      //  Reconfigure Y-Axis so the auto-range knows that the data is
> stacked
>      yAxis.configure();
>
> 	...
>
>      // Create the chart
>      JFreeChart chart = new JFreeChart(null,
> JFreeChart.DEFAULT_TITLE_FONT, plot, true);
>      chart.setBackgroundPaint(java.awt.Color.white);
>
>      return chart;
>    }
>
>
> Here is my ChartAsset (an IAsset is needed by the @Image Tapestry
> component):
>
> public class ChartAsset extends AbstractAsset
> {
>    private IEngineService _chartService;
>    private IComponent _chartProvider;
>
>    public ChartAsset(IRequestCycle cycle, IComponent chartProvider)
>    {
>       super(null, null);
>
>       IEngine engine = cycle.getEngine();
>
>       _chartService = engine.getService(ChartService.SERVICE_NAME);
>       _chartProvider = chartProvider;
>    }
>
>    public String buildURL(IRequestCycle cycle)
>    {
>       ILink l = _chartService.getLink(cycle, _chartProvider, null);
>       return l.getURL();
>    }
>
>    public InputStream getResourceAsStream(IRequestCycle cycle)
>    {
>       return null;
>    }
>
>    public InputStream getResourceAsStream(IRequestCycle cycle, Locale
> locale)
>    {
>       return null;
>    }
>
> }
>
> Finally, to have my page render and use the actual chart image, I use
> the @Image component in my ChartPage.html:
>
> <img jwcid="@Image" image="ognl:chartImageAsset"/>
>
>
> By the way, I've used a similar method to create PDF documents and
> other types of files where the bytestream is written to the service()
> method's ResponseOutputStream.  Hopefully this helps.
>
> Shawn
>
>
> Quoting Jeff LaMarche <je...@mac.com>:
>
>> Shawn:
>>
>> Thanks for posting your ChartService code - it's got me pointed in
>> the
>> right direction on a similar problem. One thing, though: Your code
>> references an interface called IChartProvider. I don't see it in your
>>
>> import statements, so I'm assuming it's also your code - any chance
>> you
>> could tell me a little more about it?
>>
>>
>> Thanks.
>> Jeff
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> tapestry-user-help@jakarta.apache.org
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: JFreeChart

Posted by Shawn Church <sh...@boxity.com>.
Jeff,

IChartProvider is a minimal interface which looks like this:

import org.jfree.chart.JFreeChart;

/**
 *  An object which can provide a {@link org.jfree.chart.JFreeChart} 
(to the {@link ChartService}).
 **/

public interface IChartProvider
{
    public JFreeChart getChart();
}


The class I have which implements IChartProvider is called ChartPage, 
and its implementation of getChart() creates and returns a JFreeChart.  
Below is my abbreviated code to create the chart, although there is 
nothing Tapestry-specific about the getChart() method itself.  I've 
stripped out a bunch of code since I'm doing some funny things with the 
chart image (we wanted the chart to have an image of one of our 
machines climbing up the line ;), but maybe it will be useful to you.

The getChartImageAsset() is important however, since it provides the 
IAsset needed by the @Image component:

public abstract class ChartPage extends BasePage 
   implements PageRenderListener, IChartProvider
{
   ...

   public IAsset getChartImageAsset()
   {
      if (chartImageAsset == null)
         chartImageAsset = new ChartAsset(getRequestCycle(), this);

      return chartImageAsset;
   }

   public JFreeChart getChart()
   {

     String[] xAxisLabels = {"Sep", "Oct", "Nov", "Dec", "Jan",
                              "Feb", "Mar", "Apr", "May", "Jun", "Jul", 
"Aug"};

     ArrayList sections = getSections();
     Iterator sectionIter = sections.iterator();
     DefaultTableXYDataset dataset = new DefaultTableXYDataset();
     int lastval = 0;
     while (sectionIter.hasNext())
     {
        String section = (String) sectionIter.next();
        XYSeries dataSeries = new XYSeries(section, true, false);

        while (true)
        {
           lastval = 0;
           double val = _salesData.getSepytd().doubleValue();
           if (val <= 0)
              break;
           dataSeries.add(lastval++, val);
			
			...

        }

        dataset.addSeries(dataSeries);
     }

     //  Create the X-Axis
     SymbolicAxis xAxis = new SymbolicAxis(null, xAxisLabels);
     xAxis.setRange(0, 12);
     xAxis.setLowerMargin(0.0);
     xAxis.setUpperMargin(0.0);

     //  Create the Y-Axis
     NumberAxis yAxis = new NumberAxis(null);
     yAxis.setRange(0, 55000000);
     yAxis.setLabel("Sales");

     //  Create the renderer
     StackedXYAreaRenderer renderer =
        new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);

     renderer.setShapePaint(Color.gray);
     renderer.setShapeStroke(new BasicStroke(0.5f));
     renderer.setShape(new Ellipse2D.Double(-3, -3, 6, 6));
     renderer.setOutline(true);

     //  Create the plot
     XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
     plot.setForegroundAlpha(0.65f);

     //  Reconfigure Y-Axis so the auto-range knows that the data is 
stacked
     yAxis.configure();

	...

     // Create the chart
     JFreeChart chart = new JFreeChart(null, 
JFreeChart.DEFAULT_TITLE_FONT, plot, true);
     chart.setBackgroundPaint(java.awt.Color.white);

     return chart;
   }


Here is my ChartAsset (an IAsset is needed by the @Image Tapestry 
component):

public class ChartAsset extends AbstractAsset
{
   private IEngineService _chartService;
   private IComponent _chartProvider;

   public ChartAsset(IRequestCycle cycle, IComponent chartProvider)
   {
      super(null, null);

      IEngine engine = cycle.getEngine();

      _chartService = engine.getService(ChartService.SERVICE_NAME);
      _chartProvider = chartProvider;
   }

   public String buildURL(IRequestCycle cycle)
   {
      ILink l = _chartService.getLink(cycle, _chartProvider, null);
      return l.getURL();
   }

   public InputStream getResourceAsStream(IRequestCycle cycle)
   {
      return null;
   }

   public InputStream getResourceAsStream(IRequestCycle cycle, Locale 
locale)
   {
      return null;
   }

}

Finally, to have my page render and use the actual chart image, I use 
the @Image component in my ChartPage.html:

<img jwcid="@Image" image="ognl:chartImageAsset"/>


By the way, I've used a similar method to create PDF documents and 
other types of files where the bytestream is written to the service() 
method's ResponseOutputStream.  Hopefully this helps.

Shawn


Quoting Jeff LaMarche <je...@mac.com>:

> Shawn:
> 
> Thanks for posting your ChartService code - it's got me pointed in
> the 
> right direction on a similar problem. One thing, though: Your code 
> references an interface called IChartProvider. I don't see it in your
> 
> import statements, so I'm assuming it's also your code - any chance
> you 
> could tell me a little more about it?
> 
> 
> Thanks.
> Jeff
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: JFreeChart

Posted by Jeff LaMarche <je...@mac.com>.
Shawn:

Thanks for posting your ChartService code - it's got me pointed in the 
right direction on a similar problem. One thing, though: Your code 
references an interface called IChartProvider. I don't see it in your 
import statements, so I'm assuming it's also your code - any chance you 
could tell me a little more about it?


Thanks.
Jeff


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: JFreeChart

Posted by Howard Lewis Ship <hl...@gmail.com>.
The Workbench originally used JFreeChart; the switch was related to
licensing.  JCharts has a compatible license, JFreeChart is LGPL.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: JFreeChart

Posted by Shawn Church <sh...@boxity.com>.
I've done this by creating a new service (ie - ChartService).  I think 
my implementation was based on one of the Tapestry examples which 
Howard provided but which was based on JCharts.  I've found JFreeChart 
to be more full-featured and reliable, but the implementations are 
similar.

In case you are interested, here's my service code:

import java.io.IOException;
import java.io.ByteArrayOutputStream;
import javax.servlet.ServletException;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.AbstractService;
import org.apache.tapestry.engine.IEngineServiceView;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.request.ResponseOutputStream;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;

public class ChartService extends AbstractService
{
   public static final String SERVICE_NAME = "chart";

   public ILink getLink(IRequestCycle cycle, IComponent component, 
Object[] parameters)
   {
      String[] context;
      String pageName = component.getPage().getPageName();
      String idPath = component.getIdPath();

      if (idPath != null)
      {
         context = new String[2];
         context[1] = idPath;
      }
      else
         context = new String[1];

      context[0] = pageName;

      return constructLink(cycle, SERVICE_NAME, context, null, true);
   }

   public void service(IEngineServiceView engine,
                       IRequestCycle cycle,
                       ResponseOutputStream output)
      throws ServletException, IOException
   {
      String context[] = getServiceContext(cycle.getRequestContext());

      String pageName = context[0];
      String idPath = (context.length == 1) ? null : context[1];

      IPage page = cycle.getPage(pageName);
      IComponent component = (idPath == null) ? page : 
page.getNestedComponent(idPath);

      try
      {
         IChartProvider provider = (IChartProvider) component;

         JFreeChart chart = provider.getChart();

         output.setContentType("image/jpeg");

         ByteArrayOutputStream stream = new ByteArrayOutputStream();

         ChartUtilities.writeChartAsJPEG( stream, chart, 700, 500);

         output.write(stream.toByteArray());
      }
      catch (ClassCastException ex)
      {
         engine.reportException("Component " + 
            component.getExtendedId() + " does not implement 
IChartProvider.", ex);

         return;
      }
      catch (Throwable ex)
      {
         engine.reportException("Error creating JPEG stream.", ex);

         return;
      }

      return;
   }

   public String getName()
   {
      return SERVICE_NAME;
   }
}


Shawn


Quoting jose pascual ortiz <jp...@alu.um.es>:

> Hi all. I am trying create a html page and a graphic created with
> JFreeChart. Do you know how do this ?
> 
> Thans in advance.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org