Jump to content
Changes to the Jaspersoft community edition download ×

Gantt chart

Recommended Posts

By: Franck Andriano - altern

Gantt chart

2005-04-26 08:57



Giulio can you implement it ?



File DefaultChartFactory.java :


else if ( chartName.equals(GANTT) )


Vector valuesY = getSeries("serie0", props,scriptlet); // task name

Vector valuesPercent = getSeries("serie1", props,scriptlet); // task pourcentage


Vector theDateStartSeries = getSeries("serie2", props,scriptlet); // date start

Vector theDateEndSeries = getSeries("serie3", props,scriptlet); // date end


GanttCategoryDataset dataset = null;


if (scriptlet == null)


dataset = getGanttSampleCategoryDataset();




TaskSeriesCollection collection = new TaskSeriesCollection();

Task t = null;


TaskSeries s1 = new TaskSeries(props.getProperty("title"));//we have just a single series of tasks


for (int i=0; i<valuesY.size(); ++i)


t = new Task((String) valuesY.get(i), (Date) theDateStartSeries.get(i), (Date) theDateEndSeries.get(i) );

t.setPercentComplete(Double.parseDouble((String) valuesPercent.get(i)));

s1.add(t); //add the new task to the task series



collection.add(s1); //add the new Series to dataset collection

dataset = collection;



JFreeChart chart = null;


chart = org.jfree.chart.ChartFactory.createGanttChart("",




showLegend, // include legend

showTooltips, // tooltips?

false // URLs?



setChartProperties(props, chart);


CategoryPlot plot = (CategoryPlot) chart.getPlot();

CategoryItemRenderer renderer = plot.getRenderer();

renderer.setSeriesPaint(0, getParameterAsColor("barColor",props, java.awt.Color.blue));


return chart.createBufferedImage(width*quality,height*quality);



protected static GanttCategoryDataset getGanttSampleCategoryDataset()


Task t = null;

TaskSeriesCollection collection = new TaskSeriesCollection();


TaskSeries s1 = new TaskSeries("Project1");//we have just a single series of tasks

t = new Task("Task1", date(2, 10, 2005), date(2,11,2005) );

t.setPercentComplete(Double.parseDouble("0.5")); // 50%

s1.add(t );//add the new task to the task series


t = new Task("Task2", date(2, 11, 2005), date(2,12,2005) );

t.setPercentComplete(Double.parseDouble("0.3")); // 70%

s1.add(t);//add the new task to the task series


collection.add(s1); //add the new Series to collection


return collection;



private static Date date(int day, int month, int year)


// this may look a bit nuts but parameters are passed as strings so I don't want any confusion between dd/mm/yyyy and mm/dd/yyyy

Calendar calendar = Calendar.getInstance();

calendar.set(year, --month, day);//month is 0 based 0 is January, 11 is December

Date result = calendar.getTime();

return result;



File *.jrxml :


<imageExpression class="java.awt.Image"><![CDATA[(java.awt.Image)it.businesslogic.ireport.chart.DefaultChartFactory.drawChart(new String[]{"antialias=true","tooltips=false","legend=false","chartName=Gantt","foregroundAlpha=0.33","subtitle=","plotBackground=[255,255,255]","quality=2","height=207","titlePosition=1","barColor=[0,0,255]","chartBackground=[255,255,255]","width=491","serie3=SERIE_DATE_END","serie2=SERIE_DATE_START","serie1=SERIE_POURCENT","serie0=SERIE_TASK","title=All Tasks"}, (it.businesslogic.ireport.IReportScriptlet)$P{REPORT_SCRIPTLET})]]></imageExpression> </image>




best regards!




By: Franck Andriano - altern

RE: Gantt chart

2005-04-27 06:36


--*-- File AvailableCharts.java (change image png)


ChartDefinition cd7 = new ChartDefinition();

cd7.setNeededSeries(new String[]{"TaskName","TaskPourcentage","DateStart","DateEnd" });


cd7.setIcon( new javax.swing.ImageIcon( AvailableCharts.class.getClass().getResource("/it/businesslogic/ireport/icons/charts/area.png") ) );

cd7.setType("Bar charts");



nsp = new SheetProperty("plotOrientation","Plot orientation",SheetProperty.COMBOBOX_NK,"2");

nsp.getTags().add(new it.businesslogic.ireport.gui.sheet.Tag(1,"Horizontal"));

// nsp.getTags().add(new it.businesslogic.ireport.gui.sheet.Tag(2,"Vertical"));


cd7.getSheetProperties().add(new SheetProperty("barColor","Bar Color", SheetProperty.COLOR ,"[0,0,255]"));

cd7.getSheetProperties().add(new SheetProperty("foregroundAlpha","Foreground Alpha", SheetProperty.NUMBER ,"0.33"));

cd7.getSheetProperties().add(new SheetProperty("valueLabel","Y Label label", SheetProperty.STRING,"" ));

cd7.getSheetProperties().add(new SheetProperty("categoryLabel","X Label", SheetProperty.STRING,"" ));


Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...