Home » Archived » BIRT » Gantt Chart with BIRT DE
Gantt Chart with BIRT DE [message #808323] |
Mon, 27 February 2012 16:56 |
Claude B Messages: 32 Registered: February 2012 |
Member |
|
|
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 23:18 |
|
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:
|
|
| |
Re: Gantt Chart with BIRT DE [message #809377 is a reply to message #808877] |
Tue, 28 February 2012 20:06 |
|
Can you try this report:
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1471-de-api-gantt-report-from-sample-db/
Remove the OdaResultSetColumn fields:
OdaResultSetColumn column = StructureFactory.createOdaResultSetColumn( );
column.setNativeName( "NomTache" );
column.setColumnName( "NomTache" );
OdaResultSetColumnHandle columnHandle = (OdaResultSetColumnHandle) dsHandle
.getPropertyHandle( OdaDataSetHandle.RESULT_SET_PROP ).addItem(
column );
When your report is created open it in the designer and try to preview
the data set. Does it work? If you can create the same report in the
designer and get it working post that design and the design that your
api code creates.
Jason
On 2/28/2012 3:49 AM, Claude B wrote:
> Hi Jason,
>
> I removed the setting BIRT Home line and I changed my data set but I've
> got a new exception when I click on the preview tab, this is the new
> exception Stack Trace:
>
> org.eclipse.birt.report.service.api.ReportServiceException: Error
> happened while running the report.
> at
> org.eclipse.birt.report.service.ReportEngineService.throwDummyException(ReportEngineService.java:1107)
>
> at
> org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:935)
>
> at
> org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(BirtViewerReportService.java:973)
>
> at
> org.eclipse.birt.report.service.actionhandler.BirtGetPageAllActionHandler.__execute(BirtGetPageAllActionHandler.java:131)
>
> at
> org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)
>
> at
> org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)
>
> at
> org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)
>
> at
> org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPageAll(BirtDocumentProcessor.java:183)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)
>
> at
> org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
>
> at
> org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
>
> at
> org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
> at
> org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
>
> at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
> at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
> at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
> at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
> at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
> at
> org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)
>
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
> at
> org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
>
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at
> org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)
>
> at
> org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
>
> at
> org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
>
> at
> org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
>
> at
> org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
>
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at
> org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:317)
>
> at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
> at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
> at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
> at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
> at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
> at org.mortbay.jetty.Server.handle(Server.java:326)
> at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
> at
> org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:939)
>
> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
> at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
> at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
> at
> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
>
> at
> org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
>
> Caused by: org.eclipse.birt.report.engine.api.EngineException: Error
> happened while running the report.
> at
> org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:196)
>
> at
> org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
>
> at
> org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:929)
>
> ... 49 more
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.birt.report.data.adapter.internal.adapter.DataAdapterUtil.mergeHints(DataAdapterUtil.java:332)
>
> at
> org.eclipse.birt.report.data.adapter.internal.adapter.DataAdapterUtil.adaptBaseDataSet(DataAdapterUtil.java:102)
>
> at
> org.eclipse.birt.report.data.adapter.internal.adapter.OdaDataSetAdapter.(OdaDataSetAdapter.java:55)
>
> at
> org.eclipse.birt.report.data.adapter.impl.ModelAdapter.adaptDataSet(ModelAdapter.java:135)
>
> at
> org.eclipse.birt.report.engine.adapter.ModelDteApiAdapter.doDefineDataSet(ModelDteApiAdapter.java:294)
>
> at
> org.eclipse.birt.report.engine.adapter.ModelDteApiAdapter.defineDataSet(ModelDteApiAdapter.java:235)
>
> at
> org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.prepare(AbstractDataEngine.java:149)
>
> at
> org.eclipse.birt.report.engine.executor.ReportExecutor.execute(ReportExecutor.java:122)
>
> at
> org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportExecutor.execute(WrappedReportExecutor.java:60)
>
> at
> org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplciateReportExecutor.execute(SuppressDuplciateReportExecutor.java:42)
>
> at
> org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportExecutor.execute(WrappedReportExecutor.java:60)
>
> at
> org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportExecutor.execute(LocalizedReportExecutor.java:61)
>
> at
> org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:178)
>
> ... 51 more
>
>
>
> I've no errors in the XML view (before and after changing code)
> I forget to tell you that the same code works perfectly with other
> charts (Pie chart, Line chart ...), I'm just modifying the createChart()
> method and the query in buildDataset()
|
|
| |
Goto Forum:
Current Time: Sat May 04 10:10:02 GMT 2024
Powered by FUDForum. Page generated in 0.04301 seconds
|