Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Setting data using JavaScript on BIRT DE
Setting data using JavaScript on BIRT DE [message #810867] Thu, 01 March 2012 16:21 Go to next message
Claude B is currently offline Claude BFriend
Messages: 32
Registered: February 2012
Member
Hi,

I've created a report which generates a chart using BIRT Designer 3.7.1 and now I want to create the same report with the design engine
My chart contains 3 Bar series each one uses its JavaScript code (see the attached picture for more details)


My question is how can I include a JavaScript code into my Design Engine???

this is a part of my code which creates the chart:

ChartWithAxes cwaLine = ChartWithAxesImpl.create();
	cwaLine.setType( "Line Chart" ); //$NON-NLS-1$
	cwaLine.setSubType( "Overlay" ); //$NON-NLS-1$
	cwaLine.getBlock().getBounds().setWidth(600);
	cwaLine.getBlock().getBounds().setHeight(400);

	// Plot
	cwaLine.getBlock().setBackground( ColorDefinitionImpl.WHITE() );
	Plot p = cwaLine.getPlot();
	p.getClientArea().setBackground( ColorDefinitionImpl.create( 255, 255,
	225 ) );

	// Title
	cwaLine.getTitle().getLabel().getCaption().setValue("Overlay test Line Chart" );
	cwaLine.getTitle().setVisible(true);

	// Legend
	cwaLine.getLegend().setVisible( true );


	// X-Axis
	Axis xAxisPrimary = cwaLine.getPrimaryBaseAxes()[0];
	xAxisPrimary.setType( AxisType.TEXT_LITERAL );
	//xAxisPrimary.getMajorGrid().setTickStyle( TickStyle.BELOW_LITERAL );
	//xAxisPrimary.getOrigin().setType( IntersectionType.MIN_LITERAL );

	// Y-Axis
	Axis yAxisPrimary = cwaLine.getPrimaryOrthogonalAxis( xAxisPrimary );
	yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
	//yAxisPrimary.getMajorGrid().setTickStyle( TickStyle.RIGHT_LITERAL );
	//yAxisPrimary.getLabel().getCaption().setValue("TEST");
	yAxisPrimary.getLabel().setVisible(true);

	// X-Series



	Series seCategory = SeriesImpl.create( );
	// seCategory.setDataSet( categoryValues );

	// Set category expression.
	seCategory.getDataDefinition( )
	.add( QueryImpl.create( "row[\"submit_date\"]" ) );

	SeriesDefinition sdX = SeriesDefinitionImpl.create( );
	sdX.getSeriesPalette( ).shift( 0 );
	sdX.setSorting(SortOption.ASCENDING_LITERAL);
	// Set default grouping.
	SeriesGrouping grouping = sdX.getGrouping( );
	grouping.getAggregateExpression();
	grouping.setEnabled( true );
	grouping.setGroupType( DataType.DATE_TIME_LITERAL );
	grouping.setGroupingUnit( GroupingUnitType.MONTHS_LITERAL );
	grouping.setGroupingInterval( 1 );
	grouping.setAggregateExpression( "Count" ); // Set Count aggregation. //$NON-NLS-1$

	xAxisPrimary.getSeriesDefinitions( ).add( sdX );
	sdX.getSeries( ).add( seCategory );

	// Y-Series
	//LineSeries bs1 = (LineSeries) LineSeriesImpl.create( );
	BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );
	//AreaSeries bs1 = (AreaSeries) AreaSeriesImpl.create( );

	bs1.getDataDefinition( ).add( QueryImpl.create( "row[\"dbid\"]" ) );
	bs1.getLabel( ).setVisible( true );

	
	BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );

	bs2.getDataDefinition( ).add( QueryImpl.create( "row[\"dbid\"]" ) );
	bs2.getLabel( ).setVisible( true );
	
	BarSeries bs3 = (BarSeries) BarSeriesImpl.create( );

	bs3.getDataDefinition( ).add( QueryImpl.create( "row[\"dbid\"]" ) );
	bs3.getLabel( ).setVisible( true );
	

	SeriesDefinition sdY = SeriesDefinitionImpl.create( );
	sdY.getGrouping().setEnabled(false);
	yAxisPrimary.getSeriesDefinitions( ).add( sdY );
	
	
	SeriesDefinition sdY2 = SeriesDefinitionImpl.create( );
	sdY2.getGrouping().setEnabled(false);
	yAxisPrimary.getSeriesDefinitions( ).add( sdY2 );
	
	SeriesDefinition sdY3 = SeriesDefinitionImpl.create( );
	sdY3.getGrouping().setEnabled(false);
	yAxisPrimary.getSeriesDefinitions( ).add( sdY3 );
	

	sdY.getSeries( ).add( bs1 ); 
	sdY2.getSeries( ).add( bs2 ); 
	sdY3.getSeries( ).add( bs3 ); 

return cwaLine;
  • Attachment: BirtDE.JPG
    (Size: 107.84KB, Downloaded 334 times)
Re: Setting data using JavaScript on BIRT DE [message #810927 is a reply to message #810867] Thu, 01 March 2012 17:38 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You should be able to do this by adding the script expression in the
QueryImpl

QueryImpl.create( "row[\"PRODUCTCODE\"] + \"my product\"" )

Jason

On 3/1/2012 11:21 AM, Claude B wrote:
> Hi,
>
> I've created a report which generates a chart using BIRT Designer 3.7.1 and now I want to create the same report with the design engine
> My chart contains 3 Bar series each one uses its JavaScript code (see the attached picture for more details)
>
>
> My question is how can I include a JavaScript code into my Design Engine???
>
> this is a part of my code which creates the chart:
>
>
> ChartWithAxes cwaLine = ChartWithAxesImpl.create();
> cwaLine.setType( "Line Chart" ); //$NON-NLS-1$
> cwaLine.setSubType( "Overlay" ); //$NON-NLS-1$
> cwaLine.getBlock().getBounds().setWidth(600);
> cwaLine.getBlock().getBounds().setHeight(400);
>
> // Plot
> cwaLine.getBlock().setBackground( ColorDefinitionImpl.WHITE() );
> Plot p = cwaLine.getPlot();
> p.getClientArea().setBackground( ColorDefinitionImpl.create( 255, 255,
> 225 ) );
>
> // Title
> cwaLine.getTitle().getLabel().getCaption().setValue("Overlay test Line Chart" );
> cwaLine.getTitle().setVisible(true);
>
> // Legend
> cwaLine.getLegend().setVisible( true );
>
>
> // X-Axis
> Axis xAxisPrimary = cwaLine.getPrimaryBaseAxes()[0];
> xAxisPrimary.setType( AxisType.TEXT_LITERAL );
> //xAxisPrimary.getMajorGrid().setTickStyle( TickStyle.BELOW_LITERAL );
> //xAxisPrimary.getOrigin().setType( IntersectionType.MIN_LITERAL );
>
> // Y-Axis
> Axis yAxisPrimary = cwaLine.getPrimaryOrthogonalAxis( xAxisPrimary );
> yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
> //yAxisPrimary.getMajorGrid().setTickStyle( TickStyle.RIGHT_LITERAL );
> //yAxisPrimary.getLabel().getCaption().setValue("TEST");
> yAxisPrimary.getLabel().setVisible(true);
>
> // X-Series
>
>
>
> Series seCategory = SeriesImpl.create( );
> // seCategory.setDataSet( categoryValues );
>
> // Set category expression.
> seCategory.getDataDefinition( )
> .add( QueryImpl.create( "row[\"submit_date\"]" ) );
>
> SeriesDefinition sdX = SeriesDefinitionImpl.create( );
> sdX.getSeriesPalette( ).shift( 0 );
> sdX.setSorting(SortOption.ASCENDING_LITERAL);
> // Set default grouping.
> SeriesGrouping grouping = sdX.getGrouping( );
> grouping.getAggregateExpression();
> grouping.setEnabled( true );
> grouping.setGroupType( DataType.DATE_TIME_LITERAL );
> grouping.setGroupingUnit( GroupingUnitType.MONTHS_LITERAL );
> grouping.setGroupingInterval( 1 );
> grouping.setAggregateExpression( "Count" ); // Set Count aggregation. //$NON-NLS-1$
>
> xAxisPrimary.getSeriesDefinitions( ).add( sdX );
> sdX.getSeries( ).add( seCategory );
>
> // Y-Series
> //LineSeries bs1 = (LineSeries) LineSeriesImpl.create( );
> BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );
> //AreaSeries bs1 = (AreaSeries) AreaSeriesImpl.create( );
>
> bs1.getDataDefinition( ).add( QueryImpl.create( "row[\"dbid\"]" ) );
> bs1.getLabel( ).setVisible( true );
>
>
> BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );
>
> bs2.getDataDefinition( ).add( QueryImpl.create( "row[\"dbid\"]" ) );
> bs2.getLabel( ).setVisible( true );
>
> BarSeries bs3 = (BarSeries) BarSeriesImpl.create( );
>
> bs3.getDataDefinition( ).add( QueryImpl.create( "row[\"dbid\"]" ) );
> bs3.getLabel( ).setVisible( true );
>
>
> SeriesDefinition sdY = SeriesDefinitionImpl.create( );
> sdY.getGrouping().setEnabled(false);
> yAxisPrimary.getSeriesDefinitions( ).add( sdY );
>
>
> SeriesDefinition sdY2 = SeriesDefinitionImpl.create( );
> sdY2.getGrouping().setEnabled(false);
> yAxisPrimary.getSeriesDefinitions( ).add( sdY2 );
>
> SeriesDefinition sdY3 = SeriesDefinitionImpl.create( );
> sdY3.getGrouping().setEnabled(false);
> yAxisPrimary.getSeriesDefinitions( ).add( sdY3 );
>
>
> sdY.getSeries( ).add( bs1 );
> sdY2.getSeries( ).add( bs2 );
> sdY3.getSeries( ).add( bs3 );
>
> return cwaLine;
>
Re: Setting data using JavaScript on BIRT DE [message #811397 is a reply to message #810927] Fri, 02 March 2012 09:47 Go to previous messageGo to next message
Claude B is currently offline Claude BFriend
Messages: 32
Registered: February 2012
Member
thanks Jason for your answer but can you explain more because I'm still having problems with this script (what's \"my product\" and where exactly I have to put my script)

I will explain what I want to do exactly:
I have many types of requests and I want to create a bar series for each one (submitted / opened / closed)
so I used this query as a data set: select dbid,submit_date,state from tab1
and I created the chart using the code in the first message and now I have to add scripts for each series
the first script is : if(row["state"]==16778022) {row["dbid"]}
the second one is: if(row["state"]==16778023) {row["dbid"]}
the last one is : if(row["state"]==16778024) {row["dbid"]}
I attached two files the first is the chart before adding scripts and the second after adding scripts
I generated the second one using BIRT designer and now I want to do that using the Design Engine
So what should I put exactly in QueryImpl.create()????
  • Attachment: BirtDE2.JPG
    (Size: 86.07KB, Downloaded 301 times)
  • Attachment: BirtDE1.JPG
    (Size: 98.75KB, Downloaded 284 times)
Re: Setting data using JavaScript on BIRT DE [message #811401 is a reply to message #811397] Fri, 02 March 2012 09:54 Go to previous messageGo to next message
Claude B is currently offline Claude BFriend
Messages: 32
Registered: February 2012
Member
Sorry about the pictures' order:
the file "BirtDE2": chart after adding scripts
the file "BirtDE1": chart before adding scripts

I want to add that I tried QueryImpl.create("if(row[\"state\"]==16778022) {row[\"dbid\"]}");
but I got a bad result (the same as BirtDE1.JPG)
I tried other ones like QueryImpl.create("row[\"dbid\"] + if(row[\"state\"]==16778022) {row[\"dbid\"]}"); but I've got syntax errors in the viewer
Re: Setting data using JavaScript on BIRT DE [message #811879 is a reply to message #811401] Fri, 02 March 2012 23:31 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

\"my product\" was just a string I added using the QueryImpl. You
should be able to put your expression in as a string. What error are yo
getting when you do this? BTW if you are only interested in row["dbid"]
when the stat value is one of those three values, why not just put a
filter on the chart for those three values?

Jason

On 3/2/2012 4:54 AM, Claude B wrote:
> Sorry about the pictures' order: the file "BirtDE2": chart after adding
> scripts
> the file "BirtDE1": chart before adding scripts
>
> I want to add that I tried
> QueryImpl.create("if(row[\"state\"]==16778022) {row[\"dbid\"]}");
> but I got a bad result (the same as BirtDE1.JPG)
> I tried other ones like QueryImpl.create("row[\"dbid\"] +
> if(row[\"state\"]==16778022) {row[\"dbid\"]}"); but I've got syntax
> errors in the viewer
>
Re: Setting data using JavaScript on BIRT DE [message #813422 is a reply to message #811879] Mon, 05 March 2012 08:43 Go to previous messageGo to next message
Claude B is currently offline Claude BFriend
Messages: 32
Registered: February 2012
Member
Hi Jason,
I tried to put a filter at first but the problem is that I had many series, each one had its own condition and actually I don't now how to do that so I tried to but the condition as a JavaScript code for each series and that worked using the designer so I'm asking how to do it using code in the Design Engine.
Can you tell me how to put a filter for each series in a chart???
Re: Setting data using JavaScript on BIRT DE [message #813975 is a reply to message #813422] Mon, 05 March 2012 22:37 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Filters where for the chart datset, so that will not help in this case.
Look at the attached example. I use an expression on in the query. I
also add a filter to the chart extended item handle(although you
probably will not use this approach). Bear in mind that all series have
to have the same number of data points. So if you are filtering in an
expression there still has to be the same number of data points. The
example was done in 2.6.1, remove the setting of birt home if you are
using 3.7 or greater:

Jason

package DEAPI;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;

import org.eclipse.birt.chart.integrate.SimpleActionHandle;
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.AxisType;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.MultiURLValues;
import org.eclipse.birt.chart.model.attribute.Palette;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.TriggerCondition;
import org.eclipse.birt.chart.model.attribute.URLValue;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.attribute.impl.MultiURLValuesImpl;
import org.eclipse.birt.chart.model.attribute.impl.PaletteImpl;
import org.eclipse.birt.chart.model.attribute.impl.TextImpl;
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.Label;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.LabelImpl;
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.OrthogonalSampleData;
import org.eclipse.birt.chart.model.data.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.Trigger;
import org.eclipse.birt.chart.model.data.impl.ActionImpl;
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.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.LineSeries;
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.ActionHandle;
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.Expression;
import org.eclipse.birt.report.model.api.ExpressionType;
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.ModuleUtil;
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.SessionHandle;
import org.eclipse.birt.report.model.api.SimpleMasterPageHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
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.DesignChoiceConstants;
import org.eclipse.birt.report.model.api.elements.structures.Action;
import
org.eclipse.birt.report.model.api.elements.structures.FilterCondition;
import
org.eclipse.birt.report.model.api.elements.structures.PropertyBinding;
import org.eclipse.birt.report.model.parser.DesignSchemaConstants;

import com.ibm.icu.util.ULocale;


public class SimpleChart

{

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 SimpleChart().createReport();

} catch (Exception e) {

e.printStackTrace();

}

}


public void createReport() throws SemanticException, IOException

{
System.out.println("Start");
init();

createMasterPages();

buildDataSource();
buildDataSet();
createBody();
// reportDesignHandle.set


reportDesignHandle.saveAs("output/desample/simplechart.rptdesign");
reportDesignHandle.close( );
// reportDesignHandle.s
Platform.shutdown();
System.out.println("Finished");

}


private void init(){


DesignConfig config = new DesignConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_6_1/birt-runtime-2_6_1/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();
reportDesignHandle.setCreatedBy( "created by Birt 2.6.1" );


reportDesignHandle.getModule().getVersionManager( ).setVersion(
DesignSchemaConstants.REPORT_VERSION );
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",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );

PropertyBinding pb = new PropertyBinding();

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";

dsHandle.setQueryText( qry );
reportDesignHandle.getDataSets( ).add( dsHandle );




}

private void createBody() throws SemanticException

{
ExtendedItemHandle extendedItemHandle =
elementFactory.newExtendedItem("Simple 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( "PRODUCTCODE" );
cs1.setExpression( "dataSetRow[\"PRODUCTCODE\"]");
cs1.setDataType( "string" );
cs1.setAggregateOn(null);


cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "QUANTITYORDERED" );
cs2.setExpression( "dataSetRow[\"QUANTITYORDERED\"]");
cs2.setDataType( "integer" );





extendedItemHandle.addColumnBinding(cs1, true);
extendedItemHandle.addColumnBinding(cs2, true);

addFilterCondition(extendedItemHandle);

}

private Chart createChart() {

ChartWithAxes cwaLine = ChartWithAxesImpl.create();
cwaLine.setType( "Line Chart" ); //$NON-NLS-1$
cwaLine.setSubType( "Overlay" ); //$NON-NLS-1$
cwaLine.getBlock().getBounds().setWidth(600);
cwaLine.getBlock().getBounds().setHeight(400);


// Plot
cwaLine.getBlock().setBackground( ColorDefinitionImpl.WHITE() );
Plot p = cwaLine.getPlot();
p.getClientArea().setBackground( ColorDefinitionImpl.create(
255, 255,
225 ) );

// Title
cwaLine.getTitle().getLabel().getCaption().setValue("Overlay
test Line Chart" );
cwaLine.getTitle().setVisible(true);

// Legend
cwaLine.getLegend().setVisible( true );
Legend lg = cwaLine.getLegend();
lg.setItemType(LegendItemType.CATEGORIES_LITERAL);

// X-Axis
Axis xAxisPrimary = cwaLine.getPrimaryBaseAxes()[0];
xAxisPrimary.setType( AxisType.TEXT_LITERAL );
xAxisPrimary.getMajorGrid().setTickStyle(
TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin().setType( IntersectionType.MIN_LITERAL );

// Y-Axis
Axis yAxisPrimary = cwaLine.getPrimaryOrthogonalAxis(
xAxisPrimary );
yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
yAxisPrimary.getMajorGrid().setTickStyle(
TickStyle.RIGHT_LITERAL );
yAxisPrimary.getLabel().getCaption().setValue("TEST");
yAxisPrimary.getLabel().setVisible(true);

SampleData sd = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase =
DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "Category-A, Category-B"
);//$NON-NLS-1$
sd.getBaseSampleData( ).add( sdBase );


OrthogonalSampleData sdOrthogonal =
DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal.setDataSetRepresentation( "4,12" );//$NON-NLS-1$
sdOrthogonal.setSeriesDefinitionIndex( 0 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal );

cwaLine.setSampleData( sd );

// X-Series



Series seCategory = SeriesImpl.create( );
// seCategory.setDataSet( categoryValues );

// Set category expression.
seCategory.getDataDefinition( )
.add( QueryImpl.create( "row[\"PRODUCTCODE\"]" ) );

SeriesDefinition sdX = SeriesDefinitionImpl.create( );
Palette palx = PaletteImpl.create(10, false);
//sdY.getSeriesPalette( ).shift(1);
sdX.setSeriesPalette(palx);


//sdX.getSeriesPalette( ).shift( 1 );
//sdX.setSorting(SortOption.ASCENDING_LITERAL);
// Set default grouping.
//SeriesGrouping grouping = sdX.getGrouping( );
//grouping.getAggregateExpression();
//grouping.setEnabled( false );
//grouping.setGroupType( DataType.TEXT_LITERAL );
//grouping.setGroupingUnit(
GroupingUnitType.STRING_PREFIX_LITERAL );
//grouping.setGroupingInterval( 1 );
//grouping.setAggregateExpression( "Sum" ); // Set Count
aggregation. //$NON-NLS-1$

xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series
LineSeries bs1 = (LineSeries) LineSeriesImpl.create( );

bs1.getDataDefinition( ).add( QueryImpl.create( "if(
row[\"QUANTITYORDERED\"] > 30 ){row[\"QUANTITYORDERED\"]}" ) );
bs1.getLabel( ).setVisible( true );

try {




Action tst = StructureFactory.createAction( );




MultiURLValues muv = MultiURLValuesImpl.create( );



ActionHandle actionHandle =
ModuleUtil.deserializeAction((InputStream)null);

actionHandle.setLinkType(DesignChoiceConstants.ACTION_LINK_TYPE_HYPERLINK);
//String lnk = "row[\"hyper\"]";
String lnk =
"\"http://www.google.com/#q=\"+row[\"QUANTITYORDERED\"]";
Expression myexpression = new Expression( lnk,
ExpressionType.JAVASCRIPT );

actionHandle.setExpressionProperty("uri", myexpression);
String sBaseUrl = ModuleUtil.serializeAction(actionHandle);

URLValue uv =
URLValueImpl.create(sBaseUrl,null,null,null,null);
Label l = LabelImpl.create( );
l.setCaption( TextImpl.create( "www.google.com" )
);//$NON-NLS-1$
uv.setLabel( l );


muv.getURLValues( ).add( uv );
Trigger triger = TriggerImpl.create(
TriggerCondition.ONCLICK_LITERAL,
ActionImpl.create( ActionType.URL_REDIRECT_LITERAL,
muv ));
bs1.getTriggers( ).add( triger );

} catch (SemanticException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DesignFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}






SeriesDefinition sdY = SeriesDefinitionImpl.create( );
//Palette pal = PaletteImpl.create(10, false);
//sdY.getSeriesPalette( ).shift(1);
//sdY.setSeriesPalette(pal);

sdY.getGrouping().setEnabled(false);
yAxisPrimary.getSeriesDefinitions( ).add( sdY );

sdY.getSeries( ).add( bs1 );


return cwaLine;
}

void addFilterCondition(ExtendedItemHandle eh){
try{

FilterCondition fc = StructureFactory.createFilterCond();
fc.setExpr("row[\"QUANTITYORDERED\"]");
fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_GT);
fc.setValue1("25");

PropertyHandle ph = eh.getPropertyHandle(ExtendedItemHandle.FILTER_PROP);

ph.addItem(fc);
}catch (Exception e){
e.printStackTrace();
}
}
}

On 3/5/2012 3:43 AM, Claude B wrote:
> Hi Jason,
> I tried to put a filter at first but the problem is that I had many
> series, each one had its own condition and actually I don't now how to
> do that so I tried to but the condition as a JavaScript code for each
> series and that worked using the designer so I'm asking how to do it
> using code in the Design Engine.
> Can you tell me how to put a filter for each series in a chart???
Re: Setting data using JavaScript on BIRT DE [message #817024 is a reply to message #813975] Fri, 09 March 2012 14:44 Go to previous messageGo to next message
Claude B is currently offline Claude BFriend
Messages: 32
Registered: February 2012
Member
Hi Jason,

Thanks for your answer, I brought some modifications to my old code to solve the problem and to satisfy new needs.
In fact what I want to do now is:
- create a simple report using BIRT DE (with connection to an SQL server database) and extract data into a JAVA structure (a vector)
- Make some modifications to data in the JAVA structure
- create a new report using data in the JAVA structure as a data set

I've done the first step successfully and now I've my data saved into a vector which contains Java objects having 3 columns:

Column Count =3
Column Name =submit_date
Column Type =DateTime
Column Name =dbid
Column Type =Integer
Column Name =state
Column Type =Integer

01-04-2011 13:21:39 , 33557279 , 16778024
01-05-2011 12:44:35 , 33557282 , 16778024
01-05-2011 15:58:05 , 33557287 , 16778024
01-06-2011 07:13:21 , 33557289 , 16778024
01-07-2011 13:01:21 , 33557301 , 16778024
01-17-2011 12:39:26 , 33557326 , 16778024
01-19-2011 16:00:44 , 33557335 , 16778024
01-11-2011 09:20:30 , 33557308 , 16778024

I'll ignore the second step for the moment
Now I've problems with the third step: creating chart from JAVA objects datasets
Here is my code:

public void createReport() throws SemanticException, IOException

{
System.out.println("Start");



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();



SimpleMasterPageHandle simpleMasterPage =
elementFactory.newSimpleMasterPage("Master Page");

reportDesignHandle.getMasterPages().add(simpleMasterPage);

ExtendedItemHandle extendedItemHandle = elementFactory.newExtendedItem("Simple Chart", "Chart");
extendedItemHandle.setWidth("700px");
extendedItemHandle.setHeight("500px");
extendedItemHandle.setProperty(ExtendedItemHandle.DATA_SET_PROP, dataSetName);
extendedItemHandle.setProperty("outputFormat","PNG");



Chart c = createChart();

bindChart((ChartWithAxes) c);

extendedItemHandle.getReportItem().setProperty( "chart.instance", c );

reportDesignHandle.getBody().add(extendedItemHandle);

reportDesignHandle.saveAs("rapports/rapport3.rptdesign");

System.out.println("End");

}


I didn't changed the createChart() method
and here is the bindChart() method

public static void bindChart(ChartWithAxes cmb){

	Vector V = new Vector();
	try {
		V = DataExtract.executeReport();
	} catch (EngineException e) {
		e.printStackTrace();
	}
	System.out.println(V);
	
	CDateTime[] col1Value = new CDateTime[V.size()];
	double[] col2Value = new double[V.size()];
	for(int j=0;j<V.size();j++)
	{
		col1Value[j] = ((SupportRequest)V.elementAt(j)).getSubmit_date();
		System.out.println("-------" + col1Value[j]);
		col2Value[j] = ((SupportRequest)V.elementAt(j)).getDbid();
		System.out.println("-------" + col2Value[j]);
	}
	System.out.println("-------" + col1Value);
	System.out.println("-------" + col2Value);
	
	DateTimeDataSet categoryValues = DateTimeDataSetImpl.create(col1Value);
	NumberDataSet orthoValuesDataSet1 = NumberDataSetImpl.create(col2Value);
	


	Axis xaxis = cmb.getPrimaryBaseAxes()[0];
	Axis yaxis = cmb.getPrimaryOrthogonalAxis(xaxis);

	SeriesDefinition sdx = (SeriesDefinition)xaxis.getSeriesDefinitions().get(0);
	SeriesDefinition sdy = (SeriesDefinition)yaxis.getSeriesDefinitions().get(0);

	((Series)sdx.getSeries().get(0)).setDataSet(categoryValues);
	((Series)sdy.getSeries().get(0)).setDataSet(orthoValuesDataSet1);
	//((Series)sdy.getSeries().get(1)).setDataSet(orthoValues2);

}


When I execute my program I get a NullPointerException in this line:
reportDesignHandle.saveAs("rapports/rapport3.rptdesign");

here is the Stack Trace:

01-09-java.lang.NullPointerException
at org.eclipse.birt.chart.factory.Generator.getRowExpressions(Generator.java:1659)
at org.eclipse.birt.chart.factory.Generator.getRowExpressions(Generator.java:520)
at org.eclipse.birt.chart.reportitem.ChartReportItemImpl.getRowExpressions(ChartReportItemImpl.java:963)
at org.eclipse.birt.report.model.util.BoundColumnsMgr.dealExtendedItem(BoundColumnsMgr.java:219)
at org.eclipse.birt.report.model.writer.BoundColumnsWriterMgr.dealExtendedItem(BoundColumnsWriterMgr.java:426)
at org.eclipse.birt.report.model.writer.ModuleWriterImpl.visitExtendedItem(ModuleWriterImpl.java:1869)
at org.eclipse.birt.report.model.elements.ExtendedItem.apply(ExtendedItem.java:136)
at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeChildren(ModuleWriterImpl.java:2917)
at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeContents(ModuleWriterImpl.java:2902)
at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeContents(ModuleWriterImpl.java:2936)
at org.eclipse.birt.report.model.writer.DesignWriterImpl.writeSlot(DesignWriterImpl.java:172)
at org.eclipse.birt.report.model.writer.DesignWriterImpl.visitReportDesign(DesignWriterImpl.java:77)
at org.eclipse.birt.report.model.elements.ReportDesign.apply(ReportDesign.java:65)
at org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeFile(ModuleWriterImpl.java:326)
at org.eclipse.birt.report.model.writer.ModuleWriterImpl.write(ModuleWriterImpl.java:294)
at org.eclipse.birt.report.model.api.ModuleHandleImpl.save(ModuleHandleImpl.java:1451)
at org.eclipse.birt.report.model.api.ModuleHandleImpl.saveAs(ModuleHandleImpl.java:1471)
at calcul.FinalCreateChart.createReport(FinalCreateChart.java:225)
at calcul.FinalCreateChart.main(FinalCreateChart.java:128)
2012 15:09:02

Please help me to fix this error or if you have an other idea about how to generate a report from data in local classes using BIRT Design Engine 3.7.1
Re: Setting data using JavaScript on BIRT DE [message #817248 is a reply to message #817024] Fri, 09 March 2012 21:01 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Are the java objects available at the time the report runs? BTW why not
just create a scripted data set and use the chart normal binding. See
the attached file.

Jason

On 3/9/2012 9:44 AM, Claude B wrote:
> Hi Jason,
>
> Thanks for your answer, I brought some modifications to my old code to
> solve the problem and to satisfy new needs.
> In fact what I want to do now is:
> - create a simple report using BIRT DE (with connection to an SQL server
> database) and extract data into a JAVA structure (a vector)
> - Make some modifications to data in the JAVA structure
> - create a new report using data in the JAVA structure as a data set
>
> I've done the first step successfully and now I've my data saved into a
> vector which contains Java objects having 3 columns:
>
> Column Count =3
> Column Name =submit_date
> Column Type =DateTime
> Column Name =dbid
> Column Type =Integer
> Column Name =state
> Column Type =Integer
>
> 01-04-2011 13:21:39 , 33557279 , 16778024
> 01-05-2011 12:44:35 , 33557282 , 16778024
> 01-05-2011 15:58:05 , 33557287 , 16778024
> 01-06-2011 07:13:21 , 33557289 , 16778024
> 01-07-2011 13:01:21 , 33557301 , 16778024
> 01-17-2011 12:39:26 , 33557326 , 16778024
> 01-19-2011 16:00:44 , 33557335 , 16778024
> 01-11-2011 09:20:30 , 33557308 , 16778024
>
> I'll ignore the second step for the moment
> Now I've problems with the third step: creating chart from JAVA objects
> datasets
> Here is my code:
>
>
> public void createReport() throws SemanticException, IOException
>
> {
> System.out.println("Start");
>
>
>
> 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();
>
>
>
> SimpleMasterPageHandle simpleMasterPage =
> elementFactory.newSimpleMasterPage("Master Page");
>
> reportDesignHandle.getMasterPages().add(simpleMasterPage);
>
> ExtendedItemHandle extendedItemHandle =
> elementFactory.newExtendedItem("Simple Chart", "Chart");
> extendedItemHandle.setWidth("700px");
> extendedItemHandle.setHeight("500px");
> extendedItemHandle.setProperty(ExtendedItemHandle.DATA_SET_PROP,
> dataSetName);
> extendedItemHandle.setProperty("outputFormat","PNG");
>
>
>
> Chart c = createChart();
>
> bindChart((ChartWithAxes) c);
>
> extendedItemHandle.getReportItem().setProperty( "chart.instance", c );
>
> reportDesignHandle.getBody().add(extendedItemHandle);
>
> reportDesignHandle.saveAs("rapports/rapport3.rptdesign");
>
> System.out.println("End");
>
> }
>
>
> I didn't changed the createChart() method
> and here is the bindChart() method
>
>
> public static void bindChart(ChartWithAxes cmb){
>
> Vector V = new Vector();
> try {
> V = DataExtract.executeReport();
> } catch (EngineException e) {
> e.printStackTrace();
> }
> System.out.println(V);
>
> CDateTime[] col1Value = new CDateTime[V.size()];
> double[] col2Value = new double[V.size()];
> for(int j=0;j<V.size();j++)
> {
> col1Value[j] = ((SupportRequest)V.elementAt(j)).getSubmit_date();
> System.out.println("-------" + col1Value[j]);
> col2Value[j] = ((SupportRequest)V.elementAt(j)).getDbid();
> System.out.println("-------" + col2Value[j]);
> }
> System.out.println("-------" + col1Value);
> System.out.println("-------" + col2Value);
>
> DateTimeDataSet categoryValues = DateTimeDataSetImpl.create(col1Value);
> NumberDataSet orthoValuesDataSet1 = NumberDataSetImpl.create(col2Value);
>
>
>
> Axis xaxis = cmb.getPrimaryBaseAxes()[0];
> Axis yaxis = cmb.getPrimaryOrthogonalAxis(xaxis);
>
> SeriesDefinition sdx =
> (SeriesDefinition)xaxis.getSeriesDefinitions().get(0);
> SeriesDefinition sdy =
> (SeriesDefinition)yaxis.getSeriesDefinitions().get(0);
>
> ((Series)sdx.getSeries().get(0)).setDataSet(categoryValues);
> ((Series)sdy.getSeries().get(0)).setDataSet(orthoValuesDataSet1);
> //((Series)sdy.getSeries().get(1)).setDataSet(orthoValues2);
>
> }
>
>
> When I execute my program I get a NullPointerException in this line:
> reportDesignHandle.saveAs("rapports/rapport3.rptdesign");
>
> here is the Stack Trace:
>
> 01-09-java.lang.NullPointerException
> at
> org.eclipse.birt.chart.factory.Generator.getRowExpressions(Generator.java:1659)
>
> at
> org.eclipse.birt.chart.factory.Generator.getRowExpressions(Generator.java:520)
>
> at
> org.eclipse.birt.chart.reportitem.ChartReportItemImpl.getRowExpressions(ChartReportItemImpl.java:963)
>
> at
> org.eclipse.birt.report.model.util.BoundColumnsMgr.dealExtendedItem(BoundColumnsMgr.java:219)
>
> at
> org.eclipse.birt.report.model.writer.BoundColumnsWriterMgr.dealExtendedItem(BoundColumnsWriterMgr.java:426)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriterImpl.visitExtendedItem(ModuleWriterImpl.java:1869)
>
> at
> org.eclipse.birt.report.model.elements.ExtendedItem.apply(ExtendedItem.java:136)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeChildren(ModuleWriterImpl.java:2917)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeContents(ModuleWriterImpl.java:2902)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeContents(ModuleWriterImpl.java:2936)
>
> at
> org.eclipse.birt.report.model.writer.DesignWriterImpl.writeSlot(DesignWriterImpl.java:172)
>
> at
> org.eclipse.birt.report.model.writer.DesignWriterImpl.visitReportDesign(DesignWriterImpl.java:77)
>
> at
> org.eclipse.birt.report.model.elements.ReportDesign.apply(ReportDesign.java:65)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriterImpl.writeFile(ModuleWriterImpl.java:326)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriterImpl.write(ModuleWriterImpl.java:294)
>
> at
> org.eclipse.birt.report.model.api.ModuleHandleImpl.save(ModuleHandleImpl.java:1451)
>
> at
> org.eclipse.birt.report.model.api.ModuleHandleImpl.saveAs(ModuleHandleImpl.java:1471)
>
> at calcul.FinalCreateChart.createReport(FinalCreateChart.java:225)
> at calcul.FinalCreateChart.main(FinalCreateChart.java:128)
> 2012 15:09:02
>
> Please help me to fix this error or if you have an other idea about how
> to generate a report from data in local classes using BIRT Design Engine
> 3.7.1
Re: Setting data using JavaScript on BIRT DE [message #817975 is a reply to message #817248] Sun, 11 March 2012 00:05 Go to previous messageGo to next message
Claude B is currently offline Claude BFriend
Messages: 32
Registered: February 2012
Member
thank you Jason for the example, I think this is what I was looking for (scripted data source), I'll try to apply it to my report
Re: Setting data using JavaScript on BIRT DE [message #832482 is a reply to message #817248] Fri, 30 March 2012 07:48 Go to previous messageGo to next message
Ritu Goel is currently offline Ritu GoelFriend
Messages: 6
Registered: March 2012
Junior Member
Hi Jason,

I had created a sample_chart.rptdesign file and had put a bar chart in that without creating Data Sources and Data Sets.
Now with API/ java coding, I am opening this design file and creating data sources and data sets there. Both data sources and data sets are creating successfully but the problem is I am not able to bind columns with X and Y series.

Its showing error :
Errors in Report
Line 78: A data definition entry for X Series is undefined.
Line 78: A data definition entry for Y Series is undefined.


Please find attachment for java class file.


Please help me in this regard.
Thanks in advance


Re: Setting data using JavaScript on BIRT DE [message #832899 is a reply to message #832482] Fri, 30 March 2012 18:31 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Look at this sample.

Jason

On 3/30/2012 3:48 AM, Ritu Goel wrote:
> Hi Jason,
>
> I had created a sample_chart.rptdesign file and had put a bar chart in that without creating Data Sources and Data Sets.
> Now with API/ java coding, I am opening this design file and creating data sources and data sets there. Both data sources and data sets are creating successfully but the problem is I am not able to bind columns with X and Y series.
>
> Its showing error :
> Errors in Report
> Line 78: A data definition entry for X Series is undefined.
> Line 78: A data definition entry for Y Series is undefined.
>
>
> Please find attachment for java class file.
>
>
> Please help me in this regard.
> Thanks in advance
>
>
>
Re: Setting data using JavaScript on BIRT DE [message #841331 is a reply to message #832899] Wed, 11 April 2012 07:00 Go to previous messageGo to next message
Ritu Goel is currently offline Ritu GoelFriend
Messages: 6
Registered: March 2012
Junior Member
Hi Jason,
I had referred this example only to edit my bar chart but in this example, a new chart is created but what I need is to edit a already created chart through api. I had created a blank bar chart in design file and then I need to open that design file and attach created data sources and then bind X and Y axis with data .
If possible, please provide some example of editing bar chart i.e attaching data sources and Binding data on X axis and Y axis during run time through api.


Thanks & Regards
Ritu Goel
Re: Setting data using JavaScript on BIRT DE [message #841334 is a reply to message #817024] Wed, 11 April 2012 07:04 Go to previous messageGo to next message
SMHJamali Missing name is currently offline SMHJamali Missing nameFriend
Messages: 3
Registered: April 2012
Junior Member
Hi
I'm using birt-runtime-2_6_2.
I want to build rptdesign file from code by using design engine API. I don't use eclipse designer.
When control of application reach to this line
design.saveAs("path/sample.rptdesign")


my application throw an unknown exception with no stacktrace and current executing method return; so that rest of method isn't executed.

i had same situation with method
odaDS.setStringProperty("odaPassword", getText("db-password"));

on another pc. I changed my pc and run the code again. now when I call saveAs method of design Engin, execution of current method breaks and an exception throws with no stack trace.

Any help appreciated
S.M.H.Jamali


[Updated on: Wed, 11 April 2012 07:05]

Report message to a moderator

Re: Setting data using JavaScript on BIRT DE [message #841671 is a reply to message #832899] Wed, 11 April 2012 16:04 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

It is not a lot different to modify a chart in the report. For example
in the following snippet I change the grouping on an existing chart:

SessionHandle sessionHandle = engine.newSessionHandle( (ULocale) null );


try
{
designHandle = sessionHandle.openDesign(
"report/NonGroupOnXSeries.rptdesign" );//$NON-NLS-1$
}
catch ( DesignFileException e )
{
// TODO Auto-generated catch block
e.printStackTrace( );
}

ExtendedItemHandle eih = (ExtendedItemHandle) designHandle.getBody( )
.getContents( ).get( 0 );

Chart cm = null;
try
{
cm = (Chart) eih.getReportItem( ).getProperty( "chart.instance" );
//$NON-NLS-1$
}
catch ( ExtendedElementException e )
{
// TODO Auto-generated catch block
e.printStackTrace( );
}

cm.getTitle( ).getLabel( ).getCaption( ).setValue( "Group On X Series"
);//$NON-NLS-1$

cm.getTitle( ).getLabel( ).getCaption( ).getFont().setSize(12);
cm.getTitle( ).getLabel( ).getCaption( ).getFont().setRotation(45);

SeriesDefinition sdX = (SeriesDefinition) ( (Axis) ( (ChartWithAxes) cm )
.getAxes( ).get( 0 ) ).getSeriesDefinitions( ).get( 0 );

sdX.setSorting( SortOption.ASCENDING_LITERAL );
sdX.getGrouping( ).setEnabled( true );
sdX.getGrouping( ).setAggregateExpression( "Sum" );//$NON-NLS-1$
sdX.getGrouping( ).setGroupType( DataType.NUMERIC_LITERAL );
sdX.getGrouping( ).setGroupingInterval( 1 );


try
{
designHandle.saveAs( "report/GroupOnXSeries.rptdesign" );//$NON-NLS-1$
}
catch ( IOException e )
{
e.printStackTrace( );
}


You can see I get the chart model from chart.instance. In your case you
should use my previous example to create your data source and use this
example to get the extended item handle and add your bindings to it
first, then use chart.inistance to get the chart model. Then use the
previous example to see how to set the query for the category and bar
series values.

Jason

On 3/30/2012 2:31 PM, Jason Weathersby wrote:
> Look at this sample.
>
> Jason
>
> On 3/30/2012 3:48 AM, Ritu Goel wrote:
>> Hi Jason,
>>
>> I had created a sample_chart.rptdesign file and had put a bar chart in
>> that without creating Data Sources and Data Sets.
>> Now with API/ java coding, I am opening this design file and creating
>> data sources and data sets there. Both data sources and data sets are
>> creating successfully but the problem is I am not able to bind columns
>> with X and Y series.
>>
>> Its showing error :
>> Errors in Report
>> Line 78: A data definition entry for X Series is undefined.
>> Line 78: A data definition entry for Y Series is undefined.
>>
>>
>> Please find attachment for java class file.
>>
>>
>> Please help me in this regard.
>> Thanks in advance
>>
>>
>>
>
Re: Setting data using JavaScript on BIRT DE [message #841678 is a reply to message #841334] Wed, 11 April 2012 16:06 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Can you post your code?

Jason

On 4/11/2012 3:04 AM, SMHJamali Mising name wrote:
> Hi I'm using birt-runtime-2_6_2.
> I want to build rptdesign file from code by using design engine API. I
> don't use eclipse designer.
> When control of application reach to this line
>
> design.saveAs("path/sample.rptdesign")
>
>
> my application throw an unknown exception with no stacktrace and current
> executing method return; so that rest of method isn't executed.
>
> i had same situation with method
> odaDS.setStringProperty("odaPassword", getText("db-password"));
>
> on another pc. I changed my pc and run the code again. now when I call
> saveAs method of design Engin, execution of current method breaks and an
> exception throws with no stack trace.
> Any help appreciated
> S.M.H.Jamali
>
>
>
Re: Setting data using JavaScript on BIRT DE [message #841701 is a reply to message #841671] Wed, 11 April 2012 16:36 Go to previous messageGo to next message
SMHJamali Missing name is currently offline SMHJamali Missing nameFriend
Messages: 3
Registered: April 2012
Junior Member
I attach my code. can you please review it. I think this code is like yours but saveAs method that is wrote at the end of method doesn't work.

Thanks
Re: Setting data using JavaScript on BIRT DE [message #841795 is a reply to message #841701] Wed, 11 April 2012 18:34 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

It does not look like you set up the bindings on the table. Take a look
at this example:

package DEAPI;


//Java Libraries
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;

//BIRT Libraries
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.ActionHandle;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.ColumnHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.GridHandle;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.ImageHandle;
import org.eclipse.birt.report.model.api.JoinConditionHandle;
import org.eclipse.birt.report.model.api.JointDataSetHandle;
import org.eclipse.birt.report.model.api.LabelHandle;
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.ReportElementHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.SimpleMasterPageHandle;
import org.eclipse.birt.report.model.api.SortKeyHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.StyleHandle;
import org.eclipse.birt.report.model.api.TableHandle;

import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import org.eclipse.birt.report.model.api.elements.structures.Action;
import
org.eclipse.birt.report.model.api.elements.structures.AggregationArgument;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import org.eclipse.birt.report.model.api.elements.structures.EmbeddedImage;
import
org.eclipse.birt.report.model.api.elements.structures.FilterCondition;
import org.eclipse.birt.report.model.api.elements.structures.HideRule;
import org.eclipse.birt.report.model.api.elements.structures.HighlightRule;
import org.eclipse.birt.report.model.api.elements.structures.IncludeScript;
import org.eclipse.birt.report.model.api.elements.structures.JoinCondition;
import org.eclipse.birt.report.model.api.elements.structures.MapRule;
import org.eclipse.birt.report.model.api.elements.structures.ParamBinding;
import
org.eclipse.birt.report.model.api.elements.structures.PropertyBinding;
import org.eclipse.birt.report.model.api.elements.structures.SortKey;
import org.eclipse.birt.report.model.api.elements.structures.TOC;
import org.eclipse.birt.report.model.api.activity.SemanticException;

import org.eclipse.birt.report.model.elements.interfaces.IJointDataSetModel;
import org.eclipse.birt.report.model.elements.JointDataSet;
import org.eclipse.birt.report.model.elements.ReportDesign;
import org.eclipse.birt.report.model.elements.ReportItem;
import org.eclipse.birt.report.model.elements.Style;

import com.ibm.icu.util.ULocale;
import org.apache.commons.codec.binary.Base64;



public class SimpleTable
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;


public static void main( String[] args )
{
try
{
SimpleTable de = new SimpleTable();
de.buildReport();
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}


public void setup()
{
// Setup code here
}

public void processAll()
{
// Running code here
try
{
buildReport( );
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private void buildDataSource( ) throws SemanticException
{
OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource("Data
Source", "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );

PropertyBinding pb = new PropertyBinding();

designHandle.getDataSources( ).add( dsHandle );
long currid = dsHandle.getID();
//pb.setName("odaUser");
//pb.setID(currid);
//pb.setValue("params[\"NewParameter\"].value");
//PropertyHandle ph = designHandle.getPropertyHandle("propertyBindings");
//ph.addItem(pb);
}

private void buildDataSet( ) throws SemanticException
{
OdaDataSetHandle dsHandle = designFactory.newOdaDataSet(
"ds","org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select * from customers";

dsHandle.setQueryText( qry );

designHandle.getDataSets( ).add( dsHandle );
}



private void buildReport( ) throws IOException, SemanticException
{
// Create a session handle. This is used to manage all open designs.
// Your app need create the session only once.

//Set the Platform Context in Design Config
DesignConfig config = new DesignConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine");
IDesignEngine designEngine = null;

// Startup the Platform and use factory object to create the Design Engine
try
{
Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
designEngine = factory.createDesignEngine( config );
}
catch( Exception ex)
{
ex.printStackTrace();
}

// Create session handle to open, create, modify report designs
SessionHandle session = designEngine.newSessionHandle( ULocale.ENGLISH );

// Build Report Design
try
{
// Create a new report design handle.
designHandle = session.createDesign( );

// The element factory creates instances of the various BIRT elements.
designFactory = designHandle.getElementFactory( );

// Create a simple master page that describes how the report will
// appear when printed.
//
// Note: The report will fail to load in the BIRT designer
// unless you create a master page.
SimpleMasterPageHandle element = designFactory.newSimpleMasterPage(
"Page Master" ); //$NON-NLS-1$
designHandle.getMasterPages( ).add( element );

// Build DataSource
try
{

buildDataSource();
buildDataSet();
}
catch (Exception e)
{
e.printStackTrace();
}

TableHandle table = designFactory.newTableItem( "table", 3 );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ds" ) );

PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1, cs2, cs3, cs4, cs5;

// Colum 1 : CustomerName
cs1 = StructureFactory.createComputedColumn();
cs1.setName("CustomerName");
cs1.setExpression("dataSetRow[\"CUSTOMERNAME\"]");
computedSet.addItem(cs1);

// Colum 2 : CustomerCity
cs2 = StructureFactory.createComputedColumn();
cs2.setName("CustomerCity");
cs2.setExpression("dataSetRow[\"CITY\"]");
//cs2.setDataType(dataType)
computedSet.addItem(cs2);

// Colum 3 : CustomerCountry
cs3 = StructureFactory.createComputedColumn();
cs3.setName("CustomerCountry");
cs3.setExpression("dataSetRow[\"COUNTRY\"]");
computedSet.addItem(cs3);

// Colum 4 : CustomerCreditLimit
cs4 = StructureFactory.createComputedColumn();
cs4.setName("CustomerCreditLimit");
cs4.setExpression("dataSetRow[\"CREDITLIMIT\"]");
computedSet.addItem(cs4);

// Colum 5 : CustomerCreditLimitSum
cs5 = StructureFactory.createComputedColumn();
cs5.setName("CustomerCreditLimitSum");
cs5.setExpression("dataSetRow[\"CREDITLIMIT\"]");
cs5.setAggregateFunction("sum");
computedSet.addItem(cs5);

// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );

ColumnHandle ch = (ColumnHandle)table.getColumns().get(0);
ch.setProperty("width", "50%");

LabelHandle label1 = designFactory.newLabel("Label1" );


label1.setText("Customer");
CellHandle cell = (CellHandle) tableheader.getCells( ).get( 0 );
cell.getContent( ).add( label1 );

LabelHandle label2 = designFactory.newLabel("Label2" );
label2.setText("City");
cell = (CellHandle) tableheader.getCells( ).get( 1 );
cell.getContent( ).add( label2 );

LabelHandle label3 = designFactory.newLabel("Label3" );
label3.setText("Credit Limit");
cell = (CellHandle) tableheader.getCells( ).get( 2 );
cell.getContent( ).add( label3 );




// table detail (Detail Row)
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
cell = (CellHandle) tabledetail.getCells( ).get( 0 );
DataItemHandle data = designFactory.newDataItem( "data1" );
//designFactory.newTextItem(name)
data.setResultSetColumn("CustomerName");
cell.getContent( ).add( data );

cell = (CellHandle) tabledetail.getCells( ).get( 1 );
data = designFactory.newDataItem( "data2" );
data.setResultSetColumn("CustomerCity");
cell.getContent( ).add( data );

cell = (CellHandle) tabledetail.getCells( ).get( 2 );
data = designFactory.newDataItem( "data3" );
data.setResultSetColumn("CustomerCreditLimit");
cell.getContent( ).add( data );



designHandle.getBody().add(table);
// Save the design and close it.
designHandle.saveAs( "output/desample/simpletable.rptdesign" );
//$NON-NLS-1$
designHandle.close( );
Platform.shutdown();
}
catch( Exception ex)
{
ex.printStackTrace();
}
}

public void cleanup()
{


}

public String propertyBase() {
return "ls.brain.node";
}
}


Jason

On 4/11/2012 12:36 PM, SMHJamali Mising name wrote:
> I attach my code. can you please review it. I think this code is like yours but saveAs method that is wrote at the end of method doesn't work.
>
> Thanks
Re: Setting data using JavaScript on BIRT DE [message #842435 is a reply to message #841795] Thu, 12 April 2012 09:43 Go to previous messageGo to next message
SMHJamali Missing name is currently offline SMHJamali Missing nameFriend
Messages: 3
Registered: April 2012
Junior Member
Sir Jason Weathersby ,
Thanks for your fast helps.
My problem solved. My application needs commons-codec-1.4.jar but there was a bug that caused no stacktrace appear.

Thanks
Re: Setting data using JavaScript on BIRT DE [message #847268 is a reply to message #841671] Tue, 17 April 2012 06:38 Go to previous messageGo to next message
Ritu Goel is currently offline Ritu GoelFriend
Messages: 6
Registered: March 2012
Junior Member
Hi Jason
I am attaching code, please take a look at that. In this code, I am opening design file and creating data sources ans data sets. Then I am binding data of resultset wit X and Y series of Bar chart created during design time. But Its still showing error that:
Data definition for X and Y series is undefined.
Please let me know what steps I am missing here.


public class RenderChart {

static IDesignEngine dEngine = null;

public static void main(String args[])
{

ReportDesignHandle reportDesignHandle = null;
ElementFactory elementFactory = null;

EngineConfig conf = null;
ReportEngine eng = null;

conf = new EngineConfig();

//Create new Report engine based off of the configuration
eng = new ReportEngine( conf );

// Create a design engine configuration object.
DesignConfig dConfig = new DesignConfig( );


SessionHandle session = null;

String name = "C:/Users/456144/Desktop/BIRT Program/BIRT Report/src/chart_report.rptdesign";

try {

Platform.startup(dConfig);
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);

dEngine = factory.createDesignEngine(dConfig);
session = dEngine.newSessionHandle(null);
reportDesignHandle = session.openDesign(name);
elementFactory = reportDesignHandle.getElementFactory();
} catch (Exception ex) {

ex.printStackTrace();

}


System.out.println("File is opened");

try
{
String qry = "SELECT CLASSICMODELS.HOST1.OS_TYPE, COUNT(CLASSICMODELS.HOST1.OS_TYPE) AS NOS FROM HOST1 GROUP BY CLASSICMODELS.HOST1.OS_TYPE";


String dataSourceName = "Sample Derby";
String dataSetName ="OS Utilization";

//Adding Data Source method
addDataSource(reportDesignHandle,dataSourceName,"org.apache.derby.jdbc.EmbeddedDriver","jdbc:derby:C:/Users/456144/Desktop/BIRT Program/BirtSample","ClassicModels","");


System.out.println("Datasource is set"+dataSourceName);


//Building and binding dataset
buildDataSet(reportDesignHandle,dataSetName,dataSourceName,qry);
System.out.println("Dataset is set"+dataSetName);


elementFactory = reportDesignHandle.getElementFactory();


ExtendedItemHandle eih = (ExtendedItemHandle) reportDesignHandle.getBody().getContents().get(0);



//opening bar chart and binding data sets

editingChart(reportDesignHandle,eih );

System.out.println("Called MutiYserieschart");



}
catch(Exception e)
{
e.printStackTrace();
}
}

public static void addDataSource(ReportDesignHandle hdl,String dsName,String driver,String url,String user, String pwd)
throws SemanticException
{
OdaDataSourceHandle dataSetHandle = OdaDataSourceHandle)hdl.findDataSource(dsName);

if (dataSetHandle == null )
{
dataSetHandle = hdl.getElementFactory().newOdaDataSource(
dsName, "org.eclipse.birt.report.data.oda.jdbc" );



dataSetHandle.setProperty( "odaDriverClass",driver);
dataSetHandle.setProperty( "odaURL", url);
dataSetHandle.setProperty( "odaUser", user);
dataSetHandle.setProperty( "odaPassword", pwd );
PropertyBinding pb = new PropertyBinding();
hdl.getDataSources().add(dataSetHandle);
}
}

void print(String msg)
{
System.out.println(msg);
}


/**
* Build the query ( data set to use in the report).
*/

static void buildDataSet(ReportDesignHandle reportDesignHandle,String dataSetName,String dataSourceName,String qry)
throws SemanticException
{

OdaDataSetHandle dataSetHandle = reportDesignHandle.getElementFactory().newOdaDataSet(
dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );

dataSetHandle.setDataSource( dataSourceName );
dataSetHandle.setQueryText( qry );

PropertyHandle computedSet = dataSetHandle.getPropertyHandle( OdaDataSetHandle.COMPUTED_COLUMNS_PROP );

reportDesignHandle.getDataSets( ).add( dataSetHandle );


}

//Editing Chart method

static void editingChart(ReportDesignHandle reportDesignHandle ,ExtendedItemHandle eih)
{

Chart cwaBar=null;
try
{
eih.setDataSet(reportDesignHandle.findDataSet("OS Utilization"));
System.out.println("This is the Multiyaxis chart");
cwaBar = (Chart) eih.getReportItem().getProperty("chart.instance");



// X-Axis
Axis xAxisPrimary = ((ChartWithAxes) cwaBar).getPrimaryBaseAxes()[0];


//Y axis
Axis yAxisPrimary = ((ChartWithAxes) cwaBar).getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getLabel().getCaption().setValue("Osvalue");





// Create sample data.
SampleData sdt = DataFactory.eINSTANCE.createSampleData();
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData();
sdBase.setDataSetRepresentation("Category-A, Category-B" );
sdt.getBaseSampleData().add( sdBase );
OrthogonalSampleData sdOrthogonal = DataFactory.eINSTANCE.createOrthogonalSampleData();

sdOrthogonal.setDataSetRepresentation("4,12");
sdOrthogonal.setSeriesDefinitionIndex(0);
sdt.getOrthogonalSampleData().add( sdOrthogonal );
cwaBar.setSampleData(sdt);




// X-Series
Series seCategory = SeriesImpl.create( );
seCategory.setSeriesIdentifier("Type");
Query query = QueryImpl.create( "row[\"OS_TYPE\"]" );//$NON-NLS-1$
seCategory.getDataDefinition( ).add( query );
System.out.println(seCategory.getDataDefinition().get(0));

SeriesDefinition sdX = SeriesDefinitionImpl.create();
Palette palx = PaletteImpl.create(10, false);

sdX.setSeriesPalette(palx);

//Grouping
SeriesGrouping grouping = sdX.getGrouping( );
grouping.getAggregateExpression();
grouping.setEnabled( false );
grouping.setGroupType( DataType.TEXT_LITERAL );
grouping.setGroupingUnit( GroupingUnitType.STRING_PREFIX_LITERAL );
grouping.setGroupingInterval( 1 );
grouping.setAggregateExpression( "Sum" ); // Set Count aggregation.
//$NON-NLS-1$



sdX.getQuery().setDefinition(seCategory.getSeriesIdentifier().toString());
xAxisPrimary.getSeriesDefinitions( ).add(sdX);
sdX.getSeries( ).add( seCategory );





// Y-Series (1)
BarSeries bs = (BarSeries) BarSeriesImpl.create( );

//$NON-NLS-1$
Query query1 = QueryImpl.create( "row[\"NOS\"]" );//$NON-NLS-1$
bs.getDataDefinition( ).add( query1 );
Boolean test1 = bs.getDataDefinition( ).add( query1 );
System.out.println( bs.getDataDefinition( ).get(0));
System.out.println("value is:"+test1);
System.out.println(bs.getDataSet());

SeriesDefinition sdY1 = SeriesDefinitionImpl.create();
sdY1 = yAxisPrimary.getSeriesDefinitions().get(0);
sdY1.getGrouping().setEnabled(true);

sdY1.getQuery().setDefinition( bs.getSeriesIdentifier().toString());
yAxisPrimary.getSeriesDefinitions( ).add( sdY1 );
sdY1.getSeries( ).add( bs );
System.out.println("Everything is added");



try
{
reportDesignHandle.saveAs( "C:/Users/456144/Desktop/BIRT Program/BIRT Report/chart_report3.rptdesign" );
System.out.println("File is saved");
reportDesignHandle.close( );
Platform.shutdown();

System.out.println("Finished");
}
catch ( IOException e )
{
e.printStackTrace( );
}


}
catch(Exception e)
{
e.printStackTrace();
}


}

}


Please help in this regard.
Thanks
Ritu
Re: Setting data using JavaScript on BIRT DE [message #847725 is a reply to message #847268] Tue, 17 April 2012 15:38 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

What error are you getting? I noticed in your code you are not adding
column bindings to your chart extended report item like:

ExtendedItemHandle extendedItemHandle =
elementFactory.newExtendedItem("Simple 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);



cs1 = StructureFactory.createComputedColumn( );
cs1.setName( "PRODUCTCODE" );
cs1.setExpression( "dataSetRow[\"PRODUCTCODE\"]");
cs1.setDataType( "string" );
cs1.setAggregateOn(null);


cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "QUANTITYORDERED" );
cs2.setExpression( "dataSetRow[\"QUANTITYORDERED\"]");
cs2.setDataType( "integer" );

extendedItemHandle.addColumnBinding(cs1, true);
extendedItemHandle.addColumnBinding(cs2, true);

Jason

On 4/17/2012 2:38 AM, Ritu Goel wrote:
> Hi Jason
> I am attaching code, please take a look at that. In this code, I am
> opening design file and creating data sources ans data sets. Then I am
> binding data of resultset wit X and Y series of Bar chart created during
> design time. But Its still showing error that:
> Data definition for X and Y series is undefined. Please let me know what
> steps I am missing here.
>
>
> public class RenderChart {
>
> static IDesignEngine dEngine = null;
>
> public static void main(String args[])
> {
>
> ReportDesignHandle reportDesignHandle = null;
> ElementFactory elementFactory = null;
> EngineConfig conf = null;
> ReportEngine eng = null;
>
> conf = new EngineConfig();
> //Create new Report engine based off of the configuration
> eng = new ReportEngine( conf );
> // Create a design engine configuration object.
> DesignConfig dConfig = new DesignConfig( );
>
> SessionHandle session = null;
> String name = "C:/Users/456144/Desktop/BIRT Program/BIRT
> Report/src/chart_report.rptdesign";
>
> try {
>
> Platform.startup(dConfig);
> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
> .createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
>
> dEngine = factory.createDesignEngine(dConfig);
> session = dEngine.newSessionHandle(null);
> reportDesignHandle = session.openDesign(name);
> elementFactory = reportDesignHandle.getElementFactory();
> } catch (Exception ex) {
>
> ex.printStackTrace();
>
> }
>
> System.out.println("File is opened");
> try
> {
> String qry = "SELECT CLASSICMODELS.HOST1.OS_TYPE,
> COUNT(CLASSICMODELS.HOST1.OS_TYPE) AS NOS FROM HOST1 GROUP BY
> CLASSICMODELS.HOST1.OS_TYPE";
>
>
> String dataSourceName = "Sample Derby";
> String dataSetName ="OS Utilization";
>
> //Adding Data Source method
> addDataSource(reportDesignHandle,dataSourceName,"org.apache.derby.jdbc.EmbeddedDriver","jdbc:derby:C:/Users/456144/Desktop/BIRT
> Program/BirtSample","ClassicModels","");
>
>
> System.out.println("Datasource is set"+dataSourceName);
>
>
> //Building and binding dataset
> buildDataSet(reportDesignHandle,dataSetName,dataSourceName,qry);
> System.out.println("Dataset is set"+dataSetName);
>
>
> elementFactory = reportDesignHandle.getElementFactory();
>
>
> ExtendedItemHandle eih = (ExtendedItemHandle)
> reportDesignHandle.getBody().getContents().get(0);
>
>
>
> //opening bar chart and binding data sets
>
> editingChart(reportDesignHandle,eih );
>
> System.out.println("Called MutiYserieschart");
>
>
>
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
> }
>
> public static void addDataSource(ReportDesignHandle hdl,String
> dsName,String driver,String url,String user, String pwd) throws
> SemanticException
> {
> OdaDataSourceHandle dataSetHandle =
> OdaDataSourceHandle)hdl.findDataSource(dsName);
>
> if (dataSetHandle == null )
> {
> dataSetHandle = hdl.getElementFactory().newOdaDataSource(
> dsName, "org.eclipse.birt.report.data.oda.jdbc" );
>
>
>
> dataSetHandle.setProperty( "odaDriverClass",driver);
> dataSetHandle.setProperty( "odaURL", url);
> dataSetHandle.setProperty( "odaUser", user);
> dataSetHandle.setProperty( "odaPassword", pwd );
> PropertyBinding pb = new PropertyBinding();
> hdl.getDataSources().add(dataSetHandle);
> }
> }
>
> void print(String msg)
> {
> System.out.println(msg);
> }
>
>
> /**
> * Build the query ( data set to use in the report).
> */
>
> static void buildDataSet(ReportDesignHandle reportDesignHandle,String
> dataSetName,String dataSourceName,String qry) throws SemanticException
> {
>
> OdaDataSetHandle dataSetHandle =
> reportDesignHandle.getElementFactory().newOdaDataSet(
> dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
>
> dataSetHandle.setDataSource( dataSourceName );
> dataSetHandle.setQueryText( qry );
>
> PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
> OdaDataSetHandle.COMPUTED_COLUMNS_PROP );
>
> reportDesignHandle.getDataSets( ).add( dataSetHandle );
>
>
> }
>
> //Editing Chart method
> static void editingChart(ReportDesignHandle reportDesignHandle
> ,ExtendedItemHandle eih)
> {
>
> Chart cwaBar=null;
> try
> {
> eih.setDataSet(reportDesignHandle.findDataSet("OS Utilization"));
> System.out.println("This is the Multiyaxis chart");
> cwaBar = (Chart) eih.getReportItem().getProperty("chart.instance");
> // X-Axis
> Axis xAxisPrimary = ((ChartWithAxes) cwaBar).getPrimaryBaseAxes()[0];
> //Y axis
> Axis yAxisPrimary = ((ChartWithAxes)
> cwaBar).getPrimaryOrthogonalAxis(xAxisPrimary);
> yAxisPrimary.getLabel().getCaption().setValue("Osvalue");
> // Create sample data.
> SampleData sdt = DataFactory.eINSTANCE.createSampleData();
> BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData();
> sdBase.setDataSetRepresentation("Category-A, Category-B" );
> sdt.getBaseSampleData().add( sdBase );
> OrthogonalSampleData sdOrthogonal =
> DataFactory.eINSTANCE.createOrthogonalSampleData();
>
> sdOrthogonal.setDataSetRepresentation("4,12");
> sdOrthogonal.setSeriesDefinitionIndex(0);
> sdt.getOrthogonalSampleData().add( sdOrthogonal );
> cwaBar.setSampleData(sdt);
>
> // X-Series
> Series seCategory = SeriesImpl.create( );
> seCategory.setSeriesIdentifier("Type");
> Query query = QueryImpl.create( "row[\"OS_TYPE\"]" );//$NON-NLS-1$
> seCategory.getDataDefinition( ).add( query );
> System.out.println(seCategory.getDataDefinition().get(0));
>
> SeriesDefinition sdX = SeriesDefinitionImpl.create();
> Palette palx = PaletteImpl.create(10, false);
>
> sdX.setSeriesPalette(palx);
>
> //Grouping
> SeriesGrouping grouping = sdX.getGrouping( );
> grouping.getAggregateExpression();
> grouping.setEnabled( false );
> grouping.setGroupType( DataType.TEXT_LITERAL );
> grouping.setGroupingUnit( GroupingUnitType.STRING_PREFIX_LITERAL );
> grouping.setGroupingInterval( 1 );
> grouping.setAggregateExpression( "Sum" ); // Set Count aggregation.
> //$NON-NLS-1$
> sdX.getQuery().setDefinition(seCategory.getSeriesIdentifier().toString());
> xAxisPrimary.getSeriesDefinitions( ).add(sdX);
> sdX.getSeries( ).add( seCategory );
>
>
>
> // Y-Series (1)
> BarSeries bs = (BarSeries) BarSeriesImpl.create( );
> //$NON-NLS-1$
> Query query1 = QueryImpl.create( "row[\"NOS\"]" );//$NON-NLS-1$
> bs.getDataDefinition( ).add( query1 );
> Boolean test1 = bs.getDataDefinition( ).add( query1 );
> System.out.println( bs.getDataDefinition( ).get(0));
> System.out.println("value is:"+test1);
> System.out.println(bs.getDataSet());
> SeriesDefinition sdY1 = SeriesDefinitionImpl.create();
> sdY1 = yAxisPrimary.getSeriesDefinitions().get(0);
> sdY1.getGrouping().setEnabled(true);
> sdY1.getQuery().setDefinition( bs.getSeriesIdentifier().toString());
> yAxisPrimary.getSeriesDefinitions( ).add( sdY1 );
> sdY1.getSeries( ).add( bs );
> System.out.println("Everything is added");
>
>
> try
> {
> reportDesignHandle.saveAs( "C:/Users/456144/Desktop/BIRT Program/BIRT
> Report/chart_report3.rptdesign" );
> System.out.println("File is saved");
> reportDesignHandle.close( );
> Platform.shutdown();
> System.out.println("Finished");
> }
> catch ( IOException e )
> {
> e.printStackTrace( );
> }
>
>
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
>
> }
>
> }
>
>
> Please help in this regard.
> Thanks
> Ritu
Re: Setting data using JavaScript on BIRT DE [message #848281 is a reply to message #847725] Wed, 18 April 2012 04:43 Go to previous messageGo to next message
Ritu Goel is currently offline Ritu GoelFriend
Messages: 6
Registered: March 2012
Junior Member
Hi Jason,

Regarding column bindings, I am getting these column bindings in my result.rpt design file but error coming is :

Errors in Report
Line 66: A data definition entry for X Series is undefined.
Line 66: A data definition entry for Y Series is undefined.



I am not able to bind data with series value

Help me in this regard

Thanks
Ritu
Re: Setting data using JavaScript on BIRT DE [message #849102 is a reply to message #848281] Wed, 18 April 2012 22:13 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

That is most likely because you did not set the bindings on the chart.
If you open the birt designer and build a report that contains a chart
you will see in addition to your columns on the data set that the chart
will have a set of bindings in the properties view for columns that are
available to the chart. Run your code and post the rptdesign.

Jason

On 4/18/2012 12:43 AM, Ritu Goel wrote:
> Hi Jason,
>
> Regarding column bindings, I am getting these column bindings in my
> result.rpt design file but error coming is :
>
> Errors in Report
> Line 66: A data definition entry for X Series is undefined.
> Line 66: A data definition entry for Y Series is undefined.
>
>
>
> I am not able to bind data with series value
>
> Help me in this regard
>
> Thanks Ritu
Re: Setting data using JavaScript on BIRT DE [message #849374 is a reply to message #849102] Thu, 19 April 2012 05:02 Go to previous messageGo to next message
Ritu Goel is currently offline Ritu GoelFriend
Messages: 6
Registered: March 2012
Junior Member
Hi Jason
I am attaching output .rpt design file after running code. Please check this and let me know what I am missing in code.


Thanks in advance.
Ritu
Re: Setting data using JavaScript on BIRT DE [message #850418 is a reply to message #849374] Fri, 20 April 2012 02:54 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Ritu,

If you are opening an existing chart you will have to clear at least the
category seriesdefintion as a chart can only have one. I took your code
changed the data set a bit so I could run it and cleared the
definitions. See below.

package DEAPI;

import java.io.IOException;

import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.DataType;
import org.eclipse.birt.chart.model.attribute.GroupingUnitType;
import org.eclipse.birt.chart.model.attribute.Palette;
import org.eclipse.birt.chart.model.attribute.impl.PaletteImpl;
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.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.impl.QueryImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.type.BarSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.model.api.DesignConfig;
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.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import
org.eclipse.birt.report.model.api.elements.structures.PropertyBinding;

public class RenderChart {

static IDesignEngine dEngine = null;
static
org.eclipse.birt.report.model.api.elements.structures.ComputedColumn cs1;
static
org.eclipse.birt.report.model.api.elements.structures.ComputedColumn cs2
= null;
public static void main(String args[])
{

ReportDesignHandle reportDesignHandle = null;
ElementFactory elementFactory = null;
EngineConfig conf = null;
ReportEngine eng = null;

conf = new EngineConfig();
//Create new Report engine based off of the configuration
eng = new ReportEngine( conf );
// Create a design engine configuration object.
DesignConfig dConfig = new DesignConfig( );

SessionHandle session = null;
String name = "output/desample/chart_report.rptdesign";

try {

Platform.startup(dConfig);
IDesignEngineFactory factory = (IDesignEngineFactory) Platform

..createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);

dEngine = factory.createDesignEngine(dConfig);
session = dEngine.newSessionHandle(null);
reportDesignHandle = session.openDesign(name);
elementFactory = reportDesignHandle.getElementFactory();
} catch (Exception ex) {

ex.printStackTrace();

}

System.out.println("File is opened");
try
{
String qry = "SELECT CLASSICMODELS.HOST1.OS_TYPE,
COUNT(CLASSICMODELS.HOST1.OS_TYPE) AS NOS FROM HOST1 GROUP BY
CLASSICMODELS.HOST1.OS_TYPE";
qry = "Select * from orderdetails where ordernumber = 10101";

String dataSourceName = "Sample Derby";
String dataSetName ="OS Utilization";

//Adding Data Source method

addDataSource(reportDesignHandle,dataSourceName,"org.apache.derby.jdbc.EmbeddedDriver","jdbc:derby:C:/Users/456144/Desktop/BIRT
Program/BirtSample","ClassicModels","");


System.out.println("Datasource is set"+dataSourceName);


//Building and binding dataset
buildDataSet(reportDesignHandle,dataSetName,dataSourceName,qry);
System.out.println("Dataset is set"+dataSetName);


elementFactory = reportDesignHandle.getElementFactory();


ExtendedItemHandle eih = (ExtendedItemHandle)
reportDesignHandle.getBody().getContents().get(0);



//opening bar chart and binding data sets

editingChart(reportDesignHandle,eih );

System.out.println("Called MutiYserieschart");



}
catch(Exception e)
{
e.printStackTrace();
}
}

public static void addDataSource(ReportDesignHandle hdl,String
dsName,String driver,String url,String user, String pwd) throws
SemanticException
{
//OdaDataSourceHandle dataSetHandle =
(OdaDataSourceHandle)hdl.findDataSource(dsName);

//if (dataSetHandle == null )
//{
//dataSetHandle = hdl.getElementFactory().newOdaDataSource(
// dsName, "org.eclipse.birt.report.data.oda.jdbc" );



//dataSetHandle.setProperty( "odaDriverClass",driver);
//dataSetHandle.setProperty( "odaURL", url);
//dataSetHandle.setProperty( "odaUser", user);
//dataSetHandle.setProperty( "odaPassword", pwd );
//PropertyBinding pb = new PropertyBinding();
//hdl.getDataSources().add(dataSetHandle);


OdaDataSourceHandle dsHandle = hdl.getElementFactory().newOdaDataSource(
dsName, "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );
hdl.getDataSources().add(dsHandle);
//}
}

void print(String msg)
{
System.out.println(msg);
}




/**
* Build the query ( data set to use in the report).
*/

static void buildDataSet(ReportDesignHandle reportDesignHandle,String
dataSetName,String dataSourceName,String qry) throws SemanticException
{

OdaDataSetHandle dataSetHandle =
reportDesignHandle.getElementFactory().newOdaDataSet(
dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );

dataSetHandle.setDataSource( dataSourceName );
dataSetHandle.setQueryText( qry );

PropertyHandle computedSet = dataSetHandle.getPropertyHandle(
OdaDataSetHandle.COMPUTED_COLUMNS_PROP );

reportDesignHandle.getDataSets( ).add( dataSetHandle );


}

//Editing Chart method
static void editingChart(ReportDesignHandle reportDesignHandle
,ExtendedItemHandle eih)
{

Chart cwaBar=null;
try
{
eih.setProperty(ExtendedItemHandle.DATA_SET_PROP, "OS
Utilization");//reportDesignHandle.findDataSet("OS Utilization"));


cs1 = StructureFactory.createComputedColumn( );
cs1.setName( "NOS" );
cs1.setExpression( "dataSetRow[\"QUANTITYORDERED\"]");
cs1.setDataType( "integer" );
cs1.setAggregateOn(null);


cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "OS_TYPE" );
cs2.setExpression( "dataSetRow[\"PRODUCTCODE\"]");
cs2.setDataType( "string" );

eih.addColumnBinding(cs1, true);
eih.addColumnBinding(cs2, true);


System.out.println("This is the Multiyaxis chart");
cwaBar = (Chart) eih.getReportItem().getProperty("chart.instance");
// X-Axis
Axis xAxisPrimary = ((ChartWithAxes) cwaBar).getPrimaryBaseAxes()[0];
//Y axis
Axis yAxisPrimary = ((ChartWithAxes)
cwaBar).getPrimaryOrthogonalAxis(xAxisPrimary);


//Clear existing definitions
xAxisPrimary.getSeriesDefinitions( ).clear();
yAxisPrimary.getSeriesDefinitions( ).clear();


yAxisPrimary.getLabel().getCaption().setValue("Osvalue");
// Create sample data.
SampleData sdt = DataFactory.eINSTANCE.createSampleData();
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData();
sdBase.setDataSetRepresentation("Category-A, Category-B" );
sdt.getBaseSampleData().add( sdBase );
OrthogonalSampleData sdOrthogonal =
DataFactory.eINSTANCE.createOrthogonalSampleData();

sdOrthogonal.setDataSetRepresentation("4,12");
sdOrthogonal.setSeriesDefinitionIndex(0);
sdt.getOrthogonalSampleData().add( sdOrthogonal );
cwaBar.setSampleData(sdt);

// X-Series
Series seCategory = SeriesImpl.create( );
seCategory.setSeriesIdentifier("Type");
Query query = QueryImpl.create( "row[\"OS_TYPE\"]" );//$NON-NLS-1$
seCategory.getDataDefinition( ).add( query );
System.out.println(seCategory.getDataDefinition().get(0));

SeriesDefinition sdX = SeriesDefinitionImpl.create();
Palette palx = PaletteImpl.create(10, false);

sdX.setSeriesPalette(palx);

//Grouping
SeriesGrouping grouping = sdX.getGrouping( );
grouping.getAggregateExpression();
grouping.setEnabled( false );
grouping.setGroupType( DataType.TEXT_LITERAL );
grouping.setGroupingUnit( GroupingUnitType.STRING_PREFIX_LITERAL );
grouping.setGroupingInterval( 1 );
grouping.setAggregateExpression( "Sum" ); // Set Count aggregation.
//$NON-NLS-1$


sdX.getQuery().setDefinition(seCategory.getSeriesIdentifier().toString());



xAxisPrimary.getSeriesDefinitions( ).add(sdX);

sdX.getSeries( ).add( seCategory );



// Y-Series (1)
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
//$NON-NLS-1$
Query query1 = QueryImpl.create( "row[\"NOS\"]" );//$NON-NLS-1$
//bs.getDataDefinition( ).add( query1 );
Boolean test1 = bs.getDataDefinition( ).add( query1 );
System.out.println( bs.getDataDefinition( ).get(0));
System.out.println("value is:"+test1);
System.out.println(bs.getDataSet());
SeriesDefinition sdY1 = SeriesDefinitionImpl.create();

sdY1.getGrouping().setEnabled(true);
sdY1.getQuery().setDefinition( bs.getSeriesIdentifier().toString());
yAxisPrimary.getSeriesDefinitions( ).add( sdY1 );
sdY1.getSeries( ).add( bs );

sdY1.getSeriesPalette( ).shift(1);
System.out.println("Everything is added");


try
{
reportDesignHandle.saveAs( "output/desample/chart_report3.rptdesign" );
System.out.println("File is saved");
reportDesignHandle.close( );
Platform.shutdown();
System.out.println("Finished");
}
catch ( IOException e )
{
e.printStackTrace( );
}


}
catch(Exception e)
{
e.printStackTrace();
}

}

}

Jason


n 4/19/2012 1:02 AM, Ritu Goel wrote:
> Hi Jason
> I am attaching output .rpt design file after running code. Please check this and let me know what I am missing in code.
>
>
> Thanks in advance.
> Ritu
Re: Setting data using JavaScript on BIRT DE [message #850525 is a reply to message #850418] Fri, 20 April 2012 05:25 Go to previous message
Ritu Goel is currently offline Ritu GoelFriend
Messages: 6
Registered: March 2012
Junior Member
Hi Jason
Thanks a ton for your prompt help . I am very obliged to you for your instant replies.

Thanks once again. Smile
Ritu
Previous Topic:Birt and JSF
Next Topic:Dynamically changing the date format on the X axis
Goto Forum:
  


Current Time: Thu Mar 28 12:51:50 GMT 2024

Powered by FUDForum. Page generated in 0.05650 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top