-
1. Re: How to display a gantt chart with Seam??
javichi_fer Jun 4, 2008 9:12 PM (in response to sandra007)Try using jfreechart directly. For instance:
SFSB:
@Name("chartprocesser") @Stateful @Scope(ScopeType.EVENT) public class ChartProcesserBean implements ChartProcesserLocal { @Remove @Destroy public void remove(){} private byte[] chart; // chart image (.png) as a byte array @Factory(value="chart") public void createChart() { IntervalBarChartDemo1 sample = new IntervalBarChartDemo1(); JFreeChart chart = sample.getOverlaidChart(); try{ this.chart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(800, 400)); } catch (IOException e){ e.printStackTrace(); } }
IntervalBarChartDemo1:
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); data.setCategoryKeys(CATEGORIES); //data.setSeriesKeys(SERIES); final String title = "Salary Comparaison"; final String xTitle = "Bands"; final String yTitle = "Salary"; final CategoryAxis xAxis = new CategoryAxis(xTitle); xAxis.setLabelFont(titleFont); xAxis.setTickLabelFont(labelFont); xAxis.setTickMarksVisible(false); xAxis.setCategoryMargin(0.1); final NumberAxis yAxis = new NumberAxis(yTitle); yAxis.setLabelFont(titleFont); yAxis.setTickLabelFont(labelFont); 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()); renderer.setItemLabelsVisible(true); renderer.setItemMargin(0.04); renderer.setItemLabelPaint(Color.white); final ItemLabelPosition p = new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER ); renderer.setPositiveItemLabelPosition(p); IntervalCategoryItemLabelGenerator generator = new IntervalCategoryItemLabelGenerator("{3}{4}", new DecimalFormat()); renderer.setItemLabelGenerator(generator); final CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setOutlinePaint(Color.white); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinePaint(Color.white); /* CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator( "{2}", new DecimalFormat("0.00")); renderer.setItemLabelGenerator(generator); **/ this.chart = new JFreeChart(title, titleFont, plot, false); this.chart.setBackgroundPaint(Color.white); return this.chart; }
and the XHTML:
<s:graphicImage value="#{chartprocesser.chart}" />
Just change IntervalBarChartDemo1 to create your chart.
Regards
-
2. Re: How to display a gantt chart with Seam??
skunk Oct 21, 2008 11:23 AM (in response to sandra007)Dear Javier,
I am trying to draw a Gantt chart and have been following your guide and also that at:
http://www.java2s.com/Code/Java/Chart/JFreeChartGanttDemo1.htmMy 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()) { seriesCollection.add(series); } // 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); chart.setBorderVisible(true); try { this.fundingGanttChart = ChartUtilities.encodeAsPNG(chart.createBufferedImage(600, 400)); } catch (IOException e) { e.printStackTrace(); } 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?
Thanks,
Dave -
3. Re: How to display a gantt chart with Seam??
wdp109 Jan 7, 2009 7:07 AM (in response to sandra007)copy jfreechart.jar ,jcommen.jar to your ear.
-
4. Re: How to display a gantt chart with Seam??
nepoez.nepoez.gmail.com Mar 27, 2009 8:01 AM (in response to sandra007)make sure ur 'deployed-jars-ear.list' config has the jfreechart jar listed or it won't be added to ear lib