Home » Archived » BIRT » Gantt Chart with BIRT DE
Gantt Chart with BIRT DE [message #808323] |
Mon, 27 February 2012 11:56  |
Eclipse User |
|
|
|
Hello,
I'm trying to generate a Gantt chart with BIRT DE 3.7.1, I started with this tutorial:
www.birt-exchange.org/org/devshare/designing-birt-reports/1420-java-example-of-createing-a-report-with-a-gantt-chart/
and I've made some changes: I've established a connection to a MySQL Database and I'm trying to generate my own Gantt char.
The problem is when I run my report I get no errors but I get a white page instead of may chart
Here is my code:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.ActionType;
import org.eclipse.birt.chart.model.attribute.Anchor;
import org.eclipse.birt.chart.model.attribute.AttributeFactory;
import org.eclipse.birt.chart.model.attribute.AxisType;
import org.eclipse.birt.chart.model.attribute.ChartDimension;
import org.eclipse.birt.chart.model.attribute.DataType;
import org.eclipse.birt.chart.model.attribute.DateFormatDetail;
import org.eclipse.birt.chart.model.attribute.DateFormatSpecifier;
import org.eclipse.birt.chart.model.attribute.DateFormatType;
import org.eclipse.birt.chart.model.attribute.GroupingUnitType;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.Orientation;
import org.eclipse.birt.chart.model.attribute.Position;
import org.eclipse.birt.chart.model.attribute.SortOption;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.attribute.impl.TooltipValueImpl;
import org.eclipse.birt.chart.model.attribute.impl.URLValueImpl;
import org.eclipse.birt.chart.model.component.Axis;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
import org.eclipse.birt.chart.model.data.BaseSampleData;
import org.eclipse.birt.chart.model.data.DataFactory;
import org.eclipse.birt.chart.model.data.NumberDataSet;
import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
import org.eclipse.birt.chart.model.data.Query;
import org.eclipse.birt.chart.model.data.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.SeriesGrouping;
import org.eclipse.birt.chart.model.data.TextDataSet;
import org.eclipse.birt.chart.model.data.impl.ActionImpl;
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.QueryImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesGroupingImpl;
import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.TriggerImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.AreaSeries;
import org.eclipse.birt.chart.model.type.BarSeries;
import org.eclipse.birt.chart.model.type.GanttSeries;
import org.eclipse.birt.chart.model.type.LineSeries;
import org.eclipse.birt.chart.model.type.impl.AreaSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.GanttSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.script.ScriptExpression;
import org.eclipse.birt.data.engine.api.querydefn.ComputedColumn;
import org.eclipse.birt.report.model.api.ComputedColumnHandle;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignFileException;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.ScriptDataSetHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.SimpleMasterPageHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.command.ContentException;
import org.eclipse.birt.report.model.api.command.NameException;
import org.eclipse.birt.report.model.api.elements.structures.PropertyBinding;
import org.eclipse.emf.ecore.util.EcoreUtil;
import com.ibm.icu.util.ULocale;
public class gantt
{
private ReportDesignHandle reportDesignHandle = null;
private ElementFactory elementFactory = null;
private OdaDataSourceHandle odaDataSourceHandle = null;
private String dataSourceName = "datasource";
private String dataSetName = "maindataset";
private SessionHandle sessionHandle =null;
org.eclipse.birt.report.model.api.elements.structures.ComputedColumn cs1, cs2, cs3 = null;
public static void main(String args[])
{
try {
new gantt().createReport();
} catch (Exception e) {
e.printStackTrace();
}
}
public void createReport() throws SemanticException, IOException
{
System.out.println("Start");
init();
createMasterPages();
buildDataSource();
buildDataSet();
createBody();
reportDesignHandle.saveAs("output/desample/gantt.rptdesign");
try
{
reportDesignHandle = sessionHandle.openDesign( "output/desample/gantt.rptdesign" );//$NON-NLS-1$
}
catch ( DesignFileException e )
{
// TODO Auto-generated catch block
e.printStackTrace( );
}
ExtendedItemHandle eih = (ExtendedItemHandle) reportDesignHandle.getBody( )
.getContents( ).get( 0 );
for ( Iterator iter = eih.getColumnBindings( ).iterator( ); iter.hasNext( ); )
{
ComputedColumnHandle cch = (ComputedColumnHandle) iter.next( );
//if( cch.getExpression().contains("_Sum") ){
//cch.drop();
//}else{
System.out.println("opened report "+cch.getExpression());
//}
}
//reportDesignHandle.save();
System.out.println("End");
}
private void init(){
DesignConfig config = new DesignConfig( );
config.setBIRTHome("C:/K/ReportEngine");
IDesignEngine engine = null;
try {
Platform.startup(config);
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
engine = factory.createDesignEngine(config);
} catch (Exception ex) {
ex.printStackTrace();
}
// we need a handle of session of design engine
sessionHandle = engine.newSessionHandle(ULocale.ENGLISH);
reportDesignHandle = sessionHandle.createDesign();
elementFactory = reportDesignHandle.getElementFactory();
}
private void createMasterPages() throws ContentException, NameException
{
SimpleMasterPageHandle simpleMasterPage =
elementFactory.newSimpleMasterPage("Master Page");
reportDesignHandle.getMasterPages().add(simpleMasterPage);
}
void buildDataSource( ) throws SemanticException
{
OdaDataSourceHandle dsHandle = elementFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass",
"com.mysql.jdbc.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:mysql://localhost:3306/test" );
dsHandle.setProperty( "odaUser", "khaled" );
dsHandle.setProperty( "odaPassword", "" );
reportDesignHandle.getDataSources( ).add( dsHandle );
}
void buildDataSet( ) throws SemanticException
{
OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( dataSetName,
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
//String qry = "Select PRODUCTCODE, QUANTITYORDERED from orderdetails where ordernumber = 10104";
String qry = "Select NomTache, Debut, Fin from gantt";
dsHandle.setQueryText( qry );
reportDesignHandle.getDataSets( ).add( dsHandle );
}
private void createBody() throws SemanticException
{
ExtendedItemHandle extendedItemHandle = elementFactory.newExtendedItem("Gantt Chart", "Chart");
extendedItemHandle.setWidth("700px");
extendedItemHandle.setHeight("500px");
extendedItemHandle.setProperty(ExtendedItemHandle.DATA_SET_PROP, dataSetName);
extendedItemHandle.setProperty("outputFormat","PNG");
Chart c = createChart();
extendedItemHandle.getReportItem().setProperty( "chart.instance", c );
reportDesignHandle.getBody().add(extendedItemHandle);
//PropertyHandle computedSet = extendedItemHandle.getColumnBindings( );
//computedSet.clearValue();
cs1 = StructureFactory.createComputedColumn( );
cs1.setName( "NomTache" );
cs1.setExpression( "dataSetRow[\"NomTache\"]");
cs1.setDataType( "string" );
cs1.setAggregateOn(null);
cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "Debut" );
cs2.setExpression( "dataSetRow[\"Debut\"]");
cs2.setDataType( "date-time" );
cs3 = StructureFactory.createComputedColumn( );
cs3.setName( "Fin" );
cs3.setExpression( "dataSetRow[\"Fin\"]");
cs3.setDataType( "date-time" );
extendedItemHandle.addColumnBinding(cs1, true);
extendedItemHandle.addColumnBinding(cs2, true);
extendedItemHandle.addColumnBinding(cs3, true);
}
private Chart createChart() {
ChartWithAxes cwaGantt = ChartWithAxesImpl.create( );
cwaGantt.setType( "Gantt Chart" ); //$NON-NLS-1$
cwaGantt.setSubType( "Standard Gantt Chart" ); //$NON-NLS-1$
cwaGantt.setOrientation( Orientation.HORIZONTAL_LITERAL );
// Plot
cwaGantt.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
cwaGantt.getBlock( ).getOutline( ).setVisible( true );
Plot p = cwaGantt.getPlot( );
p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
255,
225 ) );
// Title
cwaGantt.getTitle( ).getLabel( ).getCaption( ).setValue( "Gantt Chart" ); //$NON-NLS-1$
// Legend
Legend lg = cwaGantt.getLegend( );
lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
// X-Axis
Axis xAxisPrimary = cwaGantt.getPrimaryBaseAxes( )[0];
xAxisPrimary.setCategoryAxis( true );
xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );
// Y-Axis
Axis yAxisPrimary = cwaGantt.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.setType( AxisType.DATE_TIME_LITERAL );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
DateFormatSpecifier dfs = AttributeFactory.eINSTANCE.createDateFormatSpecifier( );
dfs.setDetail( DateFormatDetail.DATE_LITERAL );
dfs.setType( DateFormatType.MEDIUM_LITERAL );
yAxisPrimary.setFormatSpecifier( dfs );
SampleData sd = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "" );//$NON-NLS-1$
sd.getBaseSampleData( ).add( sdBase );
OrthogonalSampleData sdOrthogonal1 = DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal1.setDataSetRepresentation( "" );//$NON-NLS-1$
sdOrthogonal1.setSeriesDefinitionIndex( 0 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal1 );
cwaGantt.setSampleData( sd );
// X-Series
Series seCategory = SeriesImpl.create( );
seCategory.getDataDefinition().add(QueryImpl.create( "row[\"NomTache\"]" ));
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).shift( 0 );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series
GanttSeries taskPhase1 = (GanttSeries) GanttSeriesImpl.create( );
taskPhase1.getLabel( ).setVisible( false );
Query query1 = QueryImpl.create( "row[\"Debut\"]" );//$NON-NLS-1$
Query query2 = QueryImpl.create( "row[\"Fin\"]" );//$NON-NLS-1$
Query query3 = QueryImpl.create( "row[\"Debut\"]" );//$NON-NLS-1$
SeriesGrouping q1 =SeriesGroupingImpl.create( );
q1.setAggregateExpression("Sum");
//q1.setEnabled(true);
q1.setGroupType( DataType.TEXT_LITERAL );
query1.setGrouping(q1);
SeriesGrouping q2 =SeriesGroupingImpl.create( );
q2.setAggregateExpression("Sum");
//q2.setEnabled(true);
q2.setGroupType( DataType.TEXT_LITERAL );
query2.setGrouping(q2);
ArrayList list = new ArrayList( );
list.add( query1 );
list.add( query2 );
list.add( query3 );
taskPhase1.getDataDefinition( ).addAll( list );
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
sdY.getSeriesPalette( ).shift( 0 );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( taskPhase1 );
return cwaGantt;
}
}
Help please
|
|
|
Re: Gantt Chart with BIRT DE [message #808579 is a reply to message #808323] |
Mon, 27 February 2012 18:18   |
Eclipse User |
|
|
|
I am not sure this is the issue but you should not be setting a birt home:
config.setBIRTHome("C:/K/ReportEngine");
Remove that line. Also try changing your buildDataSet to the following:
void buildDataSet( ) throws SemanticException
{
OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( dataSetName,
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
//String qry = "Select PRODUCTCODE, QUANTITYORDERED from orderdetails
where ordernumber = 10104";
String qry = "Select NomTache, Debut, Fin from gantt";
dsHandle.setQueryText( qry );
OdaResultSetColumn column = StructureFactory.createOdaResultSetColumn( );
column.setNativeName( "NomTache" );
column.setColumnName( "NomTache" );
OdaResultSetColumnHandle columnHandle = (OdaResultSetColumnHandle) dsHandle
.getPropertyHandle( OdaDataSetHandle.RESULT_SET_PROP ).addItem(
column );
OdaResultSetColumn column2 = StructureFactory.createOdaResultSetColumn( );
column2.setNativeName( "Debut" );
column2.setColumnName( "Debut" );
OdaResultSetColumnHandle columnHandle2 = (OdaResultSetColumnHandle) dsHandle
.getPropertyHandle( OdaDataSetHandle.RESULT_SET_PROP ).addItem(
column2 );
OdaResultSetColumn column3 = StructureFactory.createOdaResultSetColumn( );
column3.setNativeName( "Fin" );
column3.setColumnName( "Fin" );
OdaResultSetColumnHandle columnHandle3 = (OdaResultSetColumnHandle) dsHandle
.getPropertyHandle( OdaDataSetHandle.RESULT_SET_PROP ).addItem(
column3 );
reportDesignHandle.getDataSets( ).add( dsHandle );
}
Finally after you run it, if the error persists, switch to the xml view
and look on the left margin for the red circle that indicates an error.
Jason
On 2/27/2012 11:56 AM, Claude B wrote:
> Hello,
>
> I'm trying to generate a Gantt chart with BIRT DE 3.7.1, I started with
> this tutorial:
> www.birt-exchange.org/org/devshare/designing-birt-reports/1420-java-example-of-createing-a-report-with-a-gantt-chart/
>
> and I've made some changes: I've established a connection to a MySQL
> Database and I'm trying to generate my own Gantt char.
> The problem is when I run my report I get no errors but I get a white
> page instead of may chart
> Here is my code:
>
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.Iterator;
>
> import org.eclipse.birt.chart.model.Chart;
> import org.eclipse.birt.chart.model.ChartWithAxes;
> import org.eclipse.birt.chart.model.attribute.ActionType;
> import org.eclipse.birt.chart.model.attribute.Anchor;
> import org.eclipse.birt.chart.model.attribute.AttributeFactory;
> import org.eclipse.birt.chart.model.attribute.AxisType;
> import org.eclipse.birt.chart.model.attribute.ChartDimension;
> import org.eclipse.birt.chart.model.attribute.DataType;
> import org.eclipse.birt.chart.model.attribute.DateFormatDetail;
> import org.eclipse.birt.chart.model.attribute.DateFormatSpecifier;
> import org.eclipse.birt.chart.model.attribute.DateFormatType;
> import org.eclipse.birt.chart.model.attribute.GroupingUnitType;
> import org.eclipse.birt.chart.model.attribute.IntersectionType;
> import org.eclipse.birt.chart.model.attribute.LegendItemType;
> import org.eclipse.birt.chart.model.attribute.Orientation;
> import org.eclipse.birt.chart.model.attribute.Position;
> import org.eclipse.birt.chart.model.attribute.SortOption;
> import org.eclipse.birt.chart.model.attribute.TickStyle;
> import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
> import org.eclipse.birt.chart.model.attribute.impl.TooltipValueImpl;
> import org.eclipse.birt.chart.model.attribute.impl.URLValueImpl;
> import org.eclipse.birt.chart.model.component.Axis;
> import org.eclipse.birt.chart.model.component.Series;
> import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
> import org.eclipse.birt.chart.model.data.BaseSampleData;
> import org.eclipse.birt.chart.model.data.DataFactory;
> import org.eclipse.birt.chart.model.data.NumberDataSet;
> import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
> import org.eclipse.birt.chart.model.data.Query;
> import org.eclipse.birt.chart.model.data.SampleData;
> import org.eclipse.birt.chart.model.data.SeriesDefinition;
> import org.eclipse.birt.chart.model.data.SeriesGrouping;
> import org.eclipse.birt.chart.model.data.TextDataSet;
> import org.eclipse.birt.chart.model.data.impl.ActionImpl;
> import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
> import org.eclipse.birt.chart.model.data.impl.QueryImpl;
> import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
> import org.eclipse.birt.chart.model.data.impl.SeriesGroupingImpl;
> import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
> import org.eclipse.birt.chart.model.data.impl.TriggerImpl;
> import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
> import org.eclipse.birt.chart.model.layout.Legend;
> import org.eclipse.birt.chart.model.layout.Plot;
> import org.eclipse.birt.chart.model.type.AreaSeries;
> import org.eclipse.birt.chart.model.type.BarSeries;
> import org.eclipse.birt.chart.model.type.GanttSeries;
> import org.eclipse.birt.chart.model.type.LineSeries;
> import org.eclipse.birt.chart.model.type.impl.AreaSeriesImpl;
> import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
> import org.eclipse.birt.chart.model.type.impl.GanttSeriesImpl;
> import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.core.script.ScriptExpression;
> import org.eclipse.birt.data.engine.api.querydefn.ComputedColumn;
> import org.eclipse.birt.report.model.api.ComputedColumnHandle;
> import org.eclipse.birt.report.model.api.DataSetHandle;
> import org.eclipse.birt.report.model.api.DesignConfig;
> import org.eclipse.birt.report.model.api.DesignFileException;
> import org.eclipse.birt.report.model.api.ElementFactory;
> import org.eclipse.birt.report.model.api.ExtendedItemHandle;
> import org.eclipse.birt.report.model.api.IDesignEngine;
> import org.eclipse.birt.report.model.api.IDesignEngineFactory;
> import org.eclipse.birt.report.model.api.OdaDataSetHandle;
> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
> import org.eclipse.birt.report.model.api.PropertyHandle;
> import org.eclipse.birt.report.model.api.ReportDesignHandle;
> import org.eclipse.birt.report.model.api.ScriptDataSetHandle;
> import org.eclipse.birt.report.model.api.SessionHandle;
> import org.eclipse.birt.report.model.api.SimpleMasterPageHandle;
> import org.eclipse.birt.report.model.api.StructureFactory;
> import org.eclipse.birt.report.model.api.activity.SemanticException;
> import org.eclipse.birt.report.model.api.command.ContentException;
> import org.eclipse.birt.report.model.api.command.NameException;
> import
> org.eclipse.birt.report.model.api.elements.structures.PropertyBinding;
> import org.eclipse.emf.ecore.util.EcoreUtil;
>
> import com.ibm.icu.util.ULocale;
>
>
> public class gantt
>
> {
>
> private ReportDesignHandle reportDesignHandle = null;
>
> private ElementFactory elementFactory = null;
>
> private OdaDataSourceHandle odaDataSourceHandle = null;
>
> private String dataSourceName = "datasource";
>
> private String dataSetName = "maindataset";
> private SessionHandle sessionHandle =null;
>
> org.eclipse.birt.report.model.api.elements.structures.ComputedColumn
> cs1, cs2, cs3 = null;
>
> public static void main(String args[])
>
> {
> try {
>
> new gantt().createReport();
>
> } catch (Exception e) {
>
> e.printStackTrace();
>
> }
>
> }
>
>
> public void createReport() throws SemanticException, IOException
>
> {
> System.out.println("Start");
>
> init();
>
> createMasterPages();
>
> buildDataSource();
>
> buildDataSet();
>
> createBody();
>
> reportDesignHandle.saveAs("output/desample/gantt.rptdesign");
> try
> {
> reportDesignHandle = sessionHandle.openDesign(
> "output/desample/gantt.rptdesign" );//$NON-NLS-1$
> }
> catch ( DesignFileException e )
> {
> // TODO Auto-generated catch block
> e.printStackTrace( );
> }
> ExtendedItemHandle eih = (ExtendedItemHandle) reportDesignHandle.getBody( )
> getContents( ).get( 0 );
> for ( Iterator iter = eih.getColumnBindings( ).iterator( );
> iter.hasNext( ); )
> {
> ComputedColumnHandle cch = (ComputedColumnHandle) iter.next( );
> //if( cch.getExpression().contains("_Sum") ){
> //cch.drop();
> //}else{
> System.out.println("opened report "+cch.getExpression());
> //}
> }
>
> //reportDesignHandle.save();
>
> System.out.println("End");
>
> }
>
>
> private void init(){
>
>
> DesignConfig config = new DesignConfig( );
> config.setBIRTHome("C:/K/ReportEngine");
> IDesignEngine engine = null;
>
> try {
>
> Platform.startup(config);
>
> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
>
> createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
>
> engine = factory.createDesignEngine(config);
>
> } catch (Exception ex) {
>
> ex.printStackTrace();
>
> }
>
>
> // we need a handle of session of design engine
>
> sessionHandle = engine.newSessionHandle(ULocale.ENGLISH);
>
> reportDesignHandle = sessionHandle.createDesign();
>
> elementFactory = reportDesignHandle.getElementFactory();
>
> }
>
>
> private void createMasterPages() throws ContentException, NameException
>
> {
>
> SimpleMasterPageHandle simpleMasterPage =
> elementFactory.newSimpleMasterPage("Master Page");
>
> reportDesignHandle.getMasterPages().add(simpleMasterPage);
>
> }
>
> void buildDataSource( ) throws SemanticException
> {
>
> OdaDataSourceHandle dsHandle = elementFactory.newOdaDataSource(
> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
> dsHandle.setProperty( "odaDriverClass",
> "com.mysql.jdbc.Driver" );
> dsHandle.setProperty( "odaURL", "jdbc:mysql://localhost:3306/test" );
> dsHandle.setProperty( "odaUser", "khaled" );
> dsHandle.setProperty( "odaPassword", "" );
>
> reportDesignHandle.getDataSources( ).add( dsHandle );
>
> }
>
> void buildDataSet( ) throws SemanticException
> {
>
> OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( dataSetName,
> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
> dsHandle.setDataSource( "Data Source" );
> //String qry = "Select PRODUCTCODE, QUANTITYORDERED from orderdetails
> where ordernumber = 10104";
> String qry = "Select NomTache, Debut, Fin from gantt";
>
> dsHandle.setQueryText( qry );
> reportDesignHandle.getDataSets( ).add( dsHandle );
>
> }
>
> private void createBody() throws SemanticException
>
> {
> ExtendedItemHandle extendedItemHandle =
> elementFactory.newExtendedItem("Gantt Chart", "Chart");
> extendedItemHandle.setWidth("700px");
> extendedItemHandle.setHeight("500px");
> extendedItemHandle.setProperty(ExtendedItemHandle.DATA_SET_PROP,
> dataSetName);
> extendedItemHandle.setProperty("outputFormat","PNG");
>
>
>
> Chart c = createChart();
>
> extendedItemHandle.getReportItem().setProperty( "chart.instance", c );
>
> reportDesignHandle.getBody().add(extendedItemHandle);
>
>
> //PropertyHandle computedSet = extendedItemHandle.getColumnBindings( );
> //computedSet.clearValue();
>
>
> cs1 = StructureFactory.createComputedColumn( );
> cs1.setName( "NomTache" );
> cs1.setExpression( "dataSetRow[\"NomTache\"]");
> cs1.setDataType( "string" );
> cs1.setAggregateOn(null);
>
>
> cs2 = StructureFactory.createComputedColumn( );
> cs2.setName( "Debut" );
> cs2.setExpression( "dataSetRow[\"Debut\"]");
> cs2.setDataType( "date-time" );
>
> cs3 = StructureFactory.createComputedColumn( );
> cs3.setName( "Fin" );
> cs3.setExpression( "dataSetRow[\"Fin\"]");
> cs3.setDataType( "date-time" );
>
> extendedItemHandle.addColumnBinding(cs1, true);
> extendedItemHandle.addColumnBinding(cs2, true);
> extendedItemHandle.addColumnBinding(cs3, true);
>
> }
>
> private Chart createChart() {
>
> ChartWithAxes cwaGantt = ChartWithAxesImpl.create( );
> cwaGantt.setType( "Gantt Chart" ); //$NON-NLS-1$
> cwaGantt.setSubType( "Standard Gantt Chart" ); //$NON-NLS-1$
> cwaGantt.setOrientation( Orientation.HORIZONTAL_LITERAL );
> // Plot
> cwaGantt.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
> cwaGantt.getBlock( ).getOutline( ).setVisible( true );
> Plot p = cwaGantt.getPlot( );
> p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
> 255,
> 225 ) );
>
> // Title
> cwaGantt.getTitle( ).getLabel( ).getCaption( ).setValue( "Gantt Chart"
> ); //$NON-NLS-1$
>
> // Legend
> Legend lg = cwaGantt.getLegend( );
> lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
>
> // X-Axis
> Axis xAxisPrimary = cwaGantt.getPrimaryBaseAxes( )[0];
> xAxisPrimary.setCategoryAxis( true );
> xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
> xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );
>
> // Y-Axis
> Axis yAxisPrimary = cwaGantt.getPrimaryOrthogonalAxis( xAxisPrimary );
> yAxisPrimary.setType( AxisType.DATE_TIME_LITERAL );
> yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
>
> DateFormatSpecifier dfs =
> AttributeFactory.eINSTANCE.createDateFormatSpecifier( );
> dfs.setDetail( DateFormatDetail.DATE_LITERAL );
> dfs.setType( DateFormatType.MEDIUM_LITERAL );
> yAxisPrimary.setFormatSpecifier( dfs );
>
> SampleData sd = DataFactory.eINSTANCE.createSampleData( );
> BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
> sdBase.setDataSetRepresentation( "" );//$NON-NLS-1$
> sd.getBaseSampleData( ).add( sdBase );
>
> OrthogonalSampleData sdOrthogonal1 =
> DataFactory.eINSTANCE.createOrthogonalSampleData( );
> sdOrthogonal1.setDataSetRepresentation( "" );//$NON-NLS-1$
> sdOrthogonal1.setSeriesDefinitionIndex( 0 );
> sd.getOrthogonalSampleData( ).add( sdOrthogonal1 );
>
> cwaGantt.setSampleData( sd );
>
>
> // X-Series
> Series seCategory = SeriesImpl.create( );
> seCategory.getDataDefinition().add(QueryImpl.create( "row[\"NomTache\"]"
> ));
>
>
> SeriesDefinition sdX = SeriesDefinitionImpl.create( );
> sdX.getSeriesPalette( ).shift( 0 );
> xAxisPrimary.getSeriesDefinitions( ).add( sdX );
> sdX.getSeries( ).add( seCategory );
>
> // Y-Series
> GanttSeries taskPhase1 = (GanttSeries) GanttSeriesImpl.create( );
>
> taskPhase1.getLabel( ).setVisible( false );
>
> Query query1 = QueryImpl.create( "row[\"Debut\"]" );//$NON-NLS-1$
> Query query2 = QueryImpl.create( "row[\"Fin\"]" );//$NON-NLS-1$
> Query query3 = QueryImpl.create( "row[\"Debut\"]" );//$NON-NLS-1$
>
> SeriesGrouping q1 =SeriesGroupingImpl.create( );
> q1.setAggregateExpression("Sum");
> //q1.setEnabled(true);
> q1.setGroupType( DataType.TEXT_LITERAL );
> query1.setGrouping(q1);
>
>
> SeriesGrouping q2 =SeriesGroupingImpl.create( );
> q2.setAggregateExpression("Sum");
> //q2.setEnabled(true);
> q2.setGroupType( DataType.TEXT_LITERAL );
> query2.setGrouping(q2);
>
>
> ArrayList list = new ArrayList( );
> list.add( query1 );
> list.add( query2 );
> list.add( query3 );
>
> taskPhase1.getDataDefinition( ).addAll( list );
>
>
> SeriesDefinition sdY = SeriesDefinitionImpl.create( );
> sdY.getSeriesPalette( ).shift( 0 );
> yAxisPrimary.getSeriesDefinitions( ).add( sdY );
> sdY.getSeries( ).add( taskPhase1 );
>
>
> return cwaGantt;
> }
> }
>
>
> Help please :cry:
|
|
| | | |
Goto Forum:
Current Time: Fri Jul 11 22:04:20 EDT 2025
Powered by FUDForum. Page generated in 0.09180 seconds
|