4 Replies Latest reply on Mar 27, 2009 8:01 AM by lucius yu

    How to display a gantt chart with Seam??

    sandra sandra Newbie


      I am working on a scheduling application, and I am using Seam for my first time, i want to display  a gantt chart but Seam supports only three chart types of the jfreechart library.... I tried to use tomahawk but coudn't integrate it successfully....

      Is there any way for doing that???

      I may use a scheduel component or a calendar widget, not necessary a gantt chart, what is important for me is to display something that could organize my events.......

      PLZ help...

      Thnk u

        • 1. Re: How to display a gantt chart with Seam??
          Javier Ferrero Newbie

          Try using jfreechart directly. For instance:


          public class ChartProcesserBean implements ChartProcesserLocal {
              @Remove @Destroy
              public void remove(){}
              private byte[] chart; // chart image (.png) as a byte array
              public void createChart() {
                  IntervalBarChartDemo1 sample = new IntervalBarChartDemo1();
                  JFreeChart chart = sample.getOverlaidChart();
                      this.chart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(800, 400));
                  } catch (IOException e){


          public JFreeChart getChart() {
                  DefaultIntervalCategoryDataset data = null;
                  final Number[][] lows = {{10000, 18000, 26000, 34000, 42000},{1000, 1800, 2600, 3400, 4200}};
                  final Number[][] highs = {{20000, 28000, 36000, 44000, 52000},{20000, 28000, 36000, 44000, 52000}};
                  data = new DefaultIntervalCategoryDataset(SERIES, lows, highs);
                  final String title = "Salary Comparaison";
                  final String xTitle = "Bands";
                  final String yTitle = "Salary";
                  final CategoryAxis xAxis = new CategoryAxis(xTitle);
                  final NumberAxis yAxis = new NumberAxis(yTitle);
                  yAxis.setRange(0, 60000);
                  //final DecimalFormat formatter = new DecimalFormat("0.##%");
                  yAxis.setTickUnit(new NumberTickUnit(5000));
                  final IntervalBarRenderer renderer = new IntervalBarRenderer();
                  renderer.setSeriesPaint(0, new Color(51, 102, 153));
                  //renderer.setLabelGenerator(new IntervalCategoryLabelGenerator());
                  final ItemLabelPosition p = new ItemLabelPosition(
                          ItemLabelAnchor.CENTER, TextAnchor.CENTER
                  IntervalCategoryItemLabelGenerator generator = new IntervalCategoryItemLabelGenerator("{3}{4}", new DecimalFormat());
                  final CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer);
                  CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator(
                          "{2}", new DecimalFormat("0.00"));
                  this.chart = new JFreeChart(title, titleFont, plot, false);
                  return this.chart;

          and the XHTML:

          <s:graphicImage value="#{chartprocesser.chart}" />

          Just change IntervalBarChartDemo1 to create your chart.


          • 2. Re: How to display a gantt chart with Seam??
            David Beaumont Newbie

            Dear Javier,

            I am trying to draw a Gantt chart and have been following your guide and also that at:

            My code looks like:

            public byte[] getFundingGanttChart() {
                      if(!(null == this.fundingGanttChart)) return fundingGanttChart;
                      Map<OrganisationNameCcr, TaskSeries> funders = new HashMap<OrganisationNameCcr, TaskSeries>();
                      // Strong typing - I've heard of it
                      for(Object obj: this.getAllFundings()) {
                           Object[] objArray = (Object[]) obj;
                           OrganisationNameCcr funderName = (OrganisationNameCcr) objArray[2];
                           ProvisionFunding funding = (ProvisionFunding) objArray[0];
                           if(!(null == funders.get(funderName))) {
                                // We've already created a TaskSeries for this funder, so retrieve it.
                                funders.get(funderName).add(new Task(funding.getFunding().toString(), funding.getStart(), funding.getFinish()));
                           } else {
                                TaskSeries series = new TaskSeries(funderName.getName());
                                series.add(new Task(funding.getFunding().toString(), funding.getStart(), funding.getFinish()));
                                funders.put(funderName, series);
                      TaskSeriesCollection seriesCollection = new TaskSeriesCollection();
                      for(TaskSeries series: funders.values()) {
                      // FIXME - line below ought to accept the seriesCollection as argument but it fails on deployment
                      JFreeChart chart = ChartFactory.createGanttChart("Funding History", "Funding", "Date", seriesCollection, true, true, false);
                      try {
                           this.fundingGanttChart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(600, 400));
                      } catch (IOException e) {
                      return this.fundingGanttChart;

            Eclipse seems to think this is ok, but when I deploy the Ear to JBoss 4.2 I get the following stack trace:

            java.lang.NoClassDefFoundError: org/jfree/data/category/IntervalCategoryDataset
                 at java.lang.Class.getDeclaredMethods0(Native Method)

            If I change nothing, except for to give null as a parameter to ChartFactory.createGanttChart(), a chart with no data is drawn.
            IntervalCategoryDataset is an interface, which has a sub-interface GanttCategoryDataset which is implemented by TaskSeriesCollection which I am using. If I create another TaskSeriesCollection:

            TaskSeriesCollection seriesCollection2 = null;

            And pass that null collection to ChartFactory.createGanttChart(), the application deploys fine (though obviously shows a blank chart).

            What am I doing wrong? Am I simply misunderstanding how interfaces work?



            • 3. Re: How to display a gantt chart with Seam??
              richie wang Newbie

              copy jfreechart.jar ,jcommen.jar to your ear.

              • 4. Re: How to display a gantt chart with Seam??
                lucius yu Newbie

                make sure ur 'deployed-jars-ear.list' config has the jfreechart jar listed or it won't be added to ear lib