Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Can not create Bar Chart
Can not create Bar Chart [message #646213] Wed, 22 December 2010 17:16 Go to next message
Viet Bui is currently offline Viet BuiFriend
Messages: 2
Registered: December 2010
Junior Member
I programed a report including BC but an error occured.
in preview, only image and text appeared in eclipse
.Please help me !
I used BIRT run time 2.5.2 and Eclipse BIRT
package com.demo.reporteng;

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.Anchor;
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.LineAttributes;
import org.eclipse.birt.chart.model.attribute.LineStyle;
import org.eclipse.birt.chart.model.attribute.Position;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
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.NumberDataSet;
import org.eclipse.birt.chart.model.data.Query;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.TextDataSet;
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.TextDataSetImpl;
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.BarSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
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.LabelHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;

import com.ibm.icu.util.ULocale;

/**
 * Simple BIRT Design Engine API (DEAPI) demo.
 */

public class DemoCreateRPT {
	private OdaDataSourceHandle customerDataSource = null;
	private static ReportDesignHandle design;
	private ElementFactory factory = null;
	private ReportDesignHandle reportDesignHandle = null;
	private String dataSourceName = "Sample BarChart";
	String query = "Select ename,sal from scott.emp";
	public static void main(String[] args) {
		try {
			new DemoCreateRPT().buildReport();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SemanticException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// This function shows how to build a very simple BIRT report with a
	// minimal set of content: a simple grid with an image and a label.

	public 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.

		// Configure the Engine and start the Platform
		DesignConfig config = new DesignConfig();

		config
				.setProperty("BIRT_HOME",
						"F:\\Program\\Tools\\Java\\birt-runtime-2_5_2\\birt-runtime-2_5_2\\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();
		}

		SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);

		// Create a new report design.

		design = session.createDesign();

		// The element factory creates instances of the various BIRT elements.

		factory = design.getElementFactory();

		createDataSources();
		buildDataSet("Data Set","Sample BarChart",query);
		// 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.

		DesignElementHandle element = factory
				.newSimpleMasterPage("Page Master"); //$NON-NLS-1$
		design.getMasterPages().add(element);

		// Create a grid and add it to the "body" slot of the report
		// design.

		GridHandle grid = factory.newGridItem(null, 3 /* cols */, 1 /* row */);
		design.getBody().add(grid);

		// Note: Set the table width to 100% to prevent the label
		// from appearing too narrow in the layout view.

		grid.setWidth("100%"); //$NON-NLS-1$

		// Get the first row.

		RowHandle row = (RowHandle) grid.getRows().get(0);

		// Create an image and add it to the first cell.

		ImageHandle image = factory.newImage(null);
		CellHandle cell = (CellHandle) row.getCells().get(0);
		cell.getContent().add(image);
		image.setURL("\"http://www.eclipse.org/birt/phoenix/tutorial/basic/multichip-4.jpg\"");

		// Create a label and add it to the second cell.

		LabelHandle label = factory.newLabel(null);
		cell = (CellHandle) row.getCells().get(1);
		cell.getContent().add(label);
		label.setText("Hello, world!"); //$NON-NLS-1$

		cell = (CellHandle) row.getCells().get(2);

		ExtendedItemHandle eih = factory.newExtendedItem(null, "Chart");//$NON-NLS-1$
		try {
			eih.setHeight("288pt");//$NON-NLS-1$
			eih.setWidth("252pt");//$NON-NLS-1$
			eih.setProperty(ExtendedItemHandle.DATA_SET_PROP, "Data Set");//$NON-NLS-1$
			eih.getReportItem().setProperty("chart.instance", createHSChart());//$NON-NLS-1$
		} catch (Exception e) {
			e.printStackTrace();
		}
		cell.getContent().add(eih);
		
		design.saveAs("c:/tmp/samplev1.rptdesign"); //$NON-NLS-1$
		design.close();
		System.out.println("Finished");

		// We're done!
	}

	public void createDataSources() {
		// type of the data source

		String extensionID = "org.eclipse.birt.report.data.oda.jdbc";

		String driverClassName = "oracle.jdbc.OracleDriver";

		String driverURL = "jdbc:oracle:thin:@localhost:1521:orcl";

		String userName = "SCOTT";

		String userPassword = "scott";

		// now make a data source with the dataSourceName and extensionID.
		try {

			OdaDataSourceHandle customerDataSource = factory.newOdaDataSource(
					dataSourceName, extensionID);
			customerDataSource.setProperty("odaDriverClass", driverClassName);

			customerDataSource.setProperty("odaURL", driverURL);

			customerDataSource.setProperty("odaUser", userName);

			customerDataSource.setProperty("odaPassword", userPassword);

			System.out.println("odaURL is "
					+ customerDataSource.getProperty("odaURL"));

			System.out.println("odaUser is "
					+ customerDataSource.getProperty("odaUser"));

			System.out.println("odaPassword is "
					+ customerDataSource.getProperty("odaPassword"));

			design.getDataSources().add(customerDataSource);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * Build the query ( data set to use in the report).
	 */
	public void buildDataSet(String dataSetName,String dataSourceName,String qry) 
	throws SemanticException
	{
		OdaDataSetHandle dataSetHandle = design.getElementFactory().newOdaDataSet( dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
		dataSetHandle.setDataSource("Sample BarChart");
		dataSetHandle.setQueryText(qry );
		design.getDataSets( ).add( dataSetHandle );
	}


	public Chart createHSChart() {
		String[] cols = {
				"ENAME","SAL"
		};
		String[][] reportCols = {
				{"ENAME","Employee name"},
				{"ENAME","Salary"}
		};
		ChartWithAxes cwaBar = ChartWithAxesImpl.create();

		cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE());

		Plot p = cwaBar.getPlot();
		p.getClientArea().setBackground(
				ColorDefinitionImpl.create(255, 255, 225));
		cwaBar.getTitle().getLabel().getCaption().setValue("Simple Bar Chart"); //$NON-NLS-1$
		cwaBar.setUnitSpacing(20);

		Legend lg = cwaBar.getLegend();
		LineAttributes lia = lg.getOutline();
		lg.getText().getFont().setSize(16);
		lia.setStyle(LineStyle.SOLID_LITERAL);
		lg.getInsets().set(10, 5, 0, 0);
		lg.getOutline().setVisible(false);
		lg.setAnchor(Anchor.NORTH_LITERAL);
		lg.setItemType(LegendItemType.CATEGORIES_LITERAL);

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

		xAxisPrimary.setType(AxisType.TEXT_LITERAL);
		xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LITERAL);
		xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITERAL);
		xAxisPrimary.getTitle().setVisible(true);
		
		
		// Y-Axis
		Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
		yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL);
		yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
		yAxisPrimary.getLabel().getCaption().getFont().setRotation(90);

		// X-Series
		Series seCategory = SeriesImpl.create( );
		Query query = QueryImpl.create( "row[\"ename\"]" );//$NON-NLS-1$
		seCategory.getDataDefinition( ).add( query );
		
		SeriesDefinition sdX = SeriesDefinitionImpl.create();
		xAxisPrimary.getSeriesDefinitions( ).add( sdX );
		sdX.getSeries().add(seCategory);
		
		

		// Y-Series
		Query querySal = QueryImpl.create( "row[\"sal\"]" );//$NON-NLS-1$
		BarSeries bs = (BarSeries) BarSeriesImpl.create();
		bs.getDataDefinition().add(querySal);
		
		bs.setRiserOutline(null);
		bs.setSeriesIdentifier("Highlight"); //$NON-NLS-1$
		bs.getLabel().setVisible(true);
		bs.setLabelPosition(Position.INSIDE_LITERAL);
		
		SeriesDefinition sdY = SeriesDefinitionImpl.create();
		sdY.getSeriesPalette( ).update( -2 );
		yAxisPrimary.getSeriesDefinitions().add(sdY);
		sdY.getSeries().add(bs);
		
		
		return cwaBar;
	}
	
}

[Updated on: Wed, 22 December 2010 17:20]

Report message to a moderator

Re: Can not create Bar Chart [message #646247 is a reply to message #646213] Wed, 22 December 2010 21:12 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

It looks like you did not add the bindings to the chart. The bindings
acts as a middle for datasets and report items. Take a look at this
example:
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.AxisType;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.Palette;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
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.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.impl.QueryImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
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.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.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.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.Proper tyBinding;

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.Comput edColumn
cs1, cs2 = 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.saveAs("output/desample/simplechart.rptdesign ");
reportDesignHandle.close( );
Platform.shutdown();
System.out.println("Finished");

}


private void init(){


DesignConfig config = new DesignConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_5_2/birt-runtime-2_5_2/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",
"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_P ROP,
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);


}

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(
"row[\"QUANTITYORDERED\"]" ) );
bs1.getLabel( ).setVisible( true );


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

Jason

On 12/22/2010 12:16 PM, Viet Bui wrote:
> I programed a report including BC but an error occured
> Please help me !
> I used BIRT run time 2.5.2 and Eclipse BIRT
>
> package com.demo.reporteng;
>
> 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.Anchor;
> 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.LineAttributes;
> import org.eclipse.birt.chart.model.attribute.LineStyle;
> import org.eclipse.birt.chart.model.attribute.Position;
> import org.eclipse.birt.chart.model.attribute.TickStyle;
> import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
> 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.NumberDataSet;
> import org.eclipse.birt.chart.model.data.Query;
> import org.eclipse.birt.chart.model.data.SeriesDefinition;
> import org.eclipse.birt.chart.model.data.TextDataSet;
> 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.TextDataSetImpl;
> 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.BarSeries;
> import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.report.model.api.CellHandle;
> import org.eclipse.birt.report.model.api.DesignConfig;
> import org.eclipse.birt.report.model.api.DesignElementHandle;
> import org.eclipse.birt.report.model.api.ElementFactory;
> import org.eclipse.birt.report.model.api.ExtendedItemHandle;
> 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.LabelHandle;
> import org.eclipse.birt.report.model.api.OdaDataSetHandle;
> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
> import org.eclipse.birt.report.model.api.ReportDesignHandle;
> import org.eclipse.birt.report.model.api.RowHandle;
> import org.eclipse.birt.report.model.api.SessionHandle;
> import org.eclipse.birt.report.model.api.activity.SemanticException ;
> import
> org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
>
> import com.ibm.icu.util.ULocale;
>
> /**
> * Simple BIRT Design Engine API (DEAPI) demo.
> */
>
> public class DemoCreateRPT {
> private OdaDataSourceHandle customerDataSource = null;
> private static ReportDesignHandle design;
> private ElementFactory factory = null;
> private ReportDesignHandle reportDesignHandle = null;
> private String dataSourceName = "Sample BarChart";
> String query = "Select ename,sal from scott.emp";
> public static void main(String[] args) {
> try {
> new DemoCreateRPT().buildReport();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (SemanticException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> // This function shows how to build a very simple BIRT report with a
> // minimal set of content: a simple grid with an image and a label.
>
> public 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.
>
> // Configure the Engine and start the Platform
> DesignConfig config = new DesignConfig();
>
> config
> .setProperty("BIRT_HOME",
> " F:\\Program\\Tools\\Java\\birt-runtime-2_5_2\\birt-runtime-2 _5_2\\ReportEngine ");
>
> IDesignEngine engine = null;
> try {
> Platform.startup(config);
> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
> .createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_E NGINE_FACTORY);
> engine = factory.createDesignEngine(config);
>
> } catch (Exception ex) {
> ex.printStackTrace();
> }
>
> SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
>
> // Create a new report design.
>
> design = session.createDesign();
>
> // The element factory creates instances of the various BIRT elements.
>
> factory = design.getElementFactory();
>
> createDataSources();
> buildDataSet("Data Set","Sample BarChart",query);
> // 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.
>
> DesignElementHandle element = factory
> .newSimpleMasterPage("Page Master"); //$NON-NLS-1$
> design.getMasterPages().add(element);
>
> // Create a grid and add it to the "body" slot of the report
> // design.
>
> GridHandle grid = factory.newGridItem(null, 3 /* cols */, 1 /* row */);
> design.getBody().add(grid);
>
> // Note: Set the table width to 100% to prevent the label
> // from appearing too narrow in the layout view.
>
> grid.setWidth("100%"); //$NON-NLS-1$
>
> // Get the first row.
>
> RowHandle row = (RowHandle) grid.getRows().get(0);
>
> // Create an image and add it to the first cell.
>
> ImageHandle image = factory.newImage(null);
> CellHandle cell = (CellHandle) row.getCells().get(0);
> cell.getContent().add(image);
> image.setURL("\" http://www.eclipse.org/birt/phoenix/tutorial/basic/multichip -4.jpg\"");
>
>
> // Create a label and add it to the second cell.
>
> LabelHandle label = factory.newLabel(null);
> cell = (CellHandle) row.getCells().get(1);
> cell.getContent().add(label);
> label.setText("Hello, world!"); //$NON-NLS-1$
>
> cell = (CellHandle) row.getCells().get(2);
>
> ExtendedItemHandle eih = factory.newExtendedItem(null,
> "Chart");//$NON-NLS-1$
> try {
> eih.setHeight("288pt");//$NON-NLS-1$
> eih.setWidth("252pt");//$NON-NLS-1$
> eih.setProperty(ExtendedItemHandle.DATA_SET_PROP, "Data Set");//$NON-NLS-1$
> eih.getReportItem().setProperty("chart.instance",
> createHSChart());//$NON-NLS-1$
> } catch (Exception e) {
> e.printStackTrace();
> }
> cell.getContent().add(eih);
>
> design.saveAs("c:/tmp/samplev1.rptdesign"); //$NON-NLS-1$
> design.close();
> System.out.println("Finished");
>
> // We're done!
> }
>
> public void createDataSources() {
> // type of the data source
>
> String extensionID = "org.eclipse.birt.report.data.oda.jdbc";
>
> String driverClassName = "oracle.jdbc.OracleDriver";
>
> String driverURL = "jdbc:oracle:thin:@localhost:1521:orcl";
>
> String userName = "SCOTT";
>
> String userPassword = "scott";
>
> // now make a data source with the dataSourceName and extensionID.
> try {
>
> OdaDataSourceHandle customerDataSource = factory.newOdaDataSource(
> dataSourceName, extensionID);
> customerDataSource.setProperty("odaDriverClass", driverClassName);
>
> customerDataSource.setProperty("odaURL", driverURL);
>
> customerDataSource.setProperty("odaUser", userName);
>
> customerDataSource.setProperty("odaPassword", userPassword);
>
> System.out.println("odaURL is "
> + customerDataSource.getProperty("odaURL"));
>
> System.out.println("odaUser is "
> + customerDataSource.getProperty("odaUser"));
>
> System.out.println("odaPassword is "
> + customerDataSource.getProperty("odaPassword"));
>
> design.getDataSources().add(customerDataSource);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> /**
> * Build the query ( data set to use in the report).
> */
> public void buildDataSet(String dataSetName,String dataSourceName,String
> qry) throws SemanticException
> {
> OdaDataSetHandle dataSetHandle =
> design.getElementFactory().newOdaDataSet(
> dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet " );
> dataSetHandle.setDataSource("Sample BarChart");
> dataSetHandle.setQueryText(qry );
> design.getDataSets( ).add( dataSetHandle );
> }
>
>
> public Chart createHSChart() {
> String[] cols = {
> "ENAME","SAL"
> };
> String[][] reportCols = {
> {"ENAME","Employee name"},
> {"ENAME","Salary"}
> };
> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
>
> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
>
> Plot p = cwaBar.getPlot();
> p.getClientArea().setBackground(
> ColorDefinitionImpl.create(255, 255, 225));
> cwaBar.getTitle().getLabel().getCaption().setValue("Simple Bar Chart");
> //$NON-NLS-1$
> cwaBar.setUnitSpacing(20);
>
> Legend lg = cwaBar.getLegend();
> LineAttributes lia = lg.getOutline();
> lg.getText().getFont().setSize(16);
> lia.setStyle(LineStyle.SOLID_LITERAL);
> lg.getInsets().set(10, 5, 0, 0);
> lg.getOutline().setVisible(false);
> lg.setAnchor(Anchor.NORTH_LITERAL);
> lg.setItemType(LegendItemType.CATEGORIES_LITERAL);
>
> // X-Axis
>
> Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];
>
> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
> xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LIT ERAL);
> xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
> xAxisPrimary.getTitle().setVisible(true);
>
>
> // Y-Axis
> Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
> yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
> yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
> yAxisPrimary.getLabel().getCaption().getFont().setRotation(9 0);
>
> // X-Series
> Series seCategory = SeriesImpl.create( );
> Query query = QueryImpl.create( "row[\"ename\"]" );//$NON-NLS-1$
> seCategory.getDataDefinition( ).add( query );
>
> SeriesDefinition sdX = SeriesDefinitionImpl.create();
> xAxisPrimary.getSeriesDefinitions( ).add( sdX );
> sdX.getSeries().add(seCategory);
>
>
>
> // Y-Series
> Query querySal = QueryImpl.create( "row[\"sal\"]" );//$NON-NLS-1$
> BarSeries bs = (BarSeries) BarSeriesImpl.create();
> bs.getDataDefinition().add(querySal);
>
> bs.setRiserOutline(null);
> bs.setSeriesIdentifier("Highlight"); //$NON-NLS-1$
> bs.getLabel().setVisible(true);
> bs.setLabelPosition(Position.INSIDE_LITERAL);
>
> SeriesDefinition sdY = SeriesDefinitionImpl.create();
> sdY.getSeriesPalette( ).update( -2 );
> yAxisPrimary.getSeriesDefinitions().add(sdY);
> sdY.getSeries().add(bs);
>
>
> return cwaBar;
> }
>
> }
>
Re: Can not create Bar Chart [message #646274 is a reply to message #646247] Thu, 23 December 2010 02:32 Go to previous messageGo to next message
Viet Bui is currently offline Viet BuiFriend
Messages: 2
Registered: December 2010
Junior Member
Thank for reply Jason.
i have modified it but the error is still occured
can you show me how to add binding
Thanks !
Image Error
http://ca9.upanh.com/18.315.22746004.eDk0/error.jpg
Is this binding ?
cs1 = StructureFactory.createComputedColumn();
			cs1.setName("Employee Name");
			cs1.setExpression("dataSetRow[\"ENAME\"]");
			cs1.setDataType("string");
			
			cs2 = StructureFactory.createComputedColumn();
			cs2.setName("Salary");
			cs2.setExpression("dataSetRow[\"SAL\"]");
			cs2.setDataType("decimal");


My code :
[code]
package com.demo.reporteng;

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.Anchor;
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.LineAttributes;
import org.eclipse.birt.chart.model.attribute.LineStyle;
import org.eclipse.birt.chart.model.attribute.Position;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
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.NumberDataSet;
import org.eclipse.birt.chart.model.data.Query;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.TextDataSet;
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.TextDataSetImpl;
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.BarSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.Expression;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
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.LabelHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
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.Comput edColumn;
import org.eclipse.birt.report.model.api.elements.structures.Proper tyBinding;

import com.ibm.icu.util.ULocale;

/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/

public class DemoCreateRPT {
private OdaDataSourceHandle customerDataSource = null;
private static ReportDesignHandle design;
private ElementFactory factory = null;
private ReportDesignHandle reportDesignHandle = null;
private String dataSourceName = "Data Source V";
String query = "Select ENAME,SAL from SCOTT.EMP";
ComputedColumn cs1,cs2 = null;
public static void main(String[] args) {
try {
new DemoCreateRPT().buildReport();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SemanticException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

// This function shows how to build a very simple BIRT report with a
// minimal set of content: a simple grid with an image and a label.

public 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.

// Configure the Engine and start the Platform
DesignConfig config = new DesignConfig();

config
.setProperty("BIRT_HOME",
" F:\\Program\\Tools\\Java\\birt-runtime-2_5_2\\birt-runtime-2 _5_2\\ReportEngine ");
IDesignEngine engine = null;
try {
Platform.startup(config);
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_E NGINE_FACTORY);
engine = factory.createDesignEngine(config);

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

SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);

// Create a new report design.

design = session.createDesign();

// The element factory creates instances of the various BIRT elements.

factory = design.getElementFactory();

createDataSources();
buildDataSet("Data Set",dataSourceName,query);
// 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.

DesignElementHandle element = factory
.newSimpleMasterPage("Page Master"); //$NON-NLS-1$
design.getMasterPages().add(element);

// Create a grid and add it to the "body" slot of the report
// design.

GridHandle grid = factory.newGridItem(null, 3 /* cols */, 1 /* row */);
design.getBody().add(grid);

// Note: Set the table width to 100% to prevent the label
// from appearing too narrow in the layout view.

grid.setWidth("100%"); //$NON-NLS-1$

// Get the first row.

RowHandle row = (RowHandle) grid.getRows().get(0);

// Create an image and add it to the first cell.

ImageHandle image = factory.newImage(null);
CellHandle cell = (CellHandle) row.getCells().get(0);
cell.getContent().add(image);
image.setURL("\" http://www.eclipse.org/birt/phoenix/tutorial/basic/multichip -4.jpg\"");

// Create a label and add it to the second cell.

LabelHandle label = factory.newLabel(null);
cell = (CellHandle) row.getCells().get(1);
cell.getContent().add(label);
label.setText("Hello, world!"); //$NON-NLS-1$

cell = (CellHandle) row.getCells().get(2);

ExtendedItemHandle eih = factory.newExtendedItem(null, "Chart");//$NON-NLS-1$
try {
eih.setHeight("288pt");//$NON-NLS-1$
eih.setWidth("252pt");//$NON-NLS-1$
eih.setProperty(ExtendedItemHandle.DATA_SET_PROP, "Data Set");//$NON-NLS-1$

cs1 = StructureFactory.createComputedColumn();
cs1.setName("Employee Name");
cs1.setExpression("dataSetRow[\"ENAME\"]");
cs1.setDataType("string");

cs2 = StructureFactory.createComputedColumn();
cs2.setName("Salary");
cs2.setExpression("dataSetRow[\"SAL\"]");
cs2.setDataType("decimal");

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

eih.getReportItem().setProperty("chart.instance", createHSChart());//$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
cell.getContent().add(eih);

design.saveAs("c:/tmp/samplev2.rptdesign"); //$NON-NLS-1$
design.close();
System.out.println("Finished");

// We're done!
}

public void createDataSources() {
// type of the data source

String extensionID = "org.eclipse.birt.report.data.oda.jdbc";

String driverClassName = "oracle.jdbc.OracleDriver";

String driverURL = "jdbc:oracle:thin:@localhost:1521:orcl";

String userName = "SCOTT";

String userPassword = "scott";

// now make a data source with the dataSourceName and extensionID.
try {

OdaDataSourceHandle customerDataSource = factory.newOdaDataSource(
dataSourceName, extensionID);
customerDataSource.setProperty("odaDriverClass", driverClassName);

customerDataSource.setProperty("odaURL", driverURL);

customerDataSource.setProperty("odaUser", userName);

customerDataSource.setProperty("odaPassword", userPassword);

System.out.println("odaURL is "
+ customerDataSource.getProperty("odaURL"));

System.out.println("odaUser is "
+ customerDataSource.getProperty("odaUser"));

System.out.println("odaPassword is "
+ customerDataSource.getProperty("odaPassword"));

design.getDataSources().add(customerDataSource);
PropertyBinding pb = new PropertyBinding();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Build the query ( data set to use in the report).
*/
public void buildDataSet(String dataSetName,String dataSourceName,String qry)
throws SemanticException
{
OdaDataSetHandle dataSetHandle = design.getElementFactory().newOdaDataSet( dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet " );
dataSetHandle.setDataSource(dataSourceName);
dataSetHandle.setQueryText(qry );
design.getDataSets( ).add( dataSetHandle );
}


public Chart createHSChart() {
String[] cols = {
"ENAME","SAL"
};
String[][] reportCols = {
{"ENAME","Employee name"},
{"ENAME","Salary"}
};


ChartWithAxes cwaBar = ChartWithAxesImpl.create();

cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;

Plot p = cwaBar.getPlot();
p.getClientArea().setBackground(
ColorDefinitionImpl.create(255, 255, 225));
cwaBar.getTitle().getLabel().getCaption().setValue("Simple Bar Chart"); //$NON-NLS-1$
cwaBar.setUnitSpacing(20);

Legend lg = cwaBar.getLegend();
LineAttributes lia = lg.getOutline();
lg.getText().getFont().setSize(16);
lia.setStyle(LineStyle.SOLID_LITERAL);
lg.getInsets().set(10, 5, 0, 0);
lg.getOutline().setVisible(false);
lg.setAnchor(Anchor.NORTH_LITERAL);
lg.setItemType(LegendItemType.CATEGORIES_LITERAL);

// X-Axis

Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];

xAxisPrimary.setType(AxisType.TEXT_LITERAL);
xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LIT ERAL);
xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
xAxisPrimary.getTitle().setVisible(true);


// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
yAxisPrimary.getLabel().getCaption().getFont().setRotation(9 0);

// X-Series
Series seCategory = SeriesImpl.create( );
Query query = QueryImpl.create( "row[\"ENAME\"]" );//$NON-NLS-1$
seCategory.getDataDefinition( ).add( query );

SeriesDefinition sdX = SeriesDefinitionImpl.create();
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries().add(seCategory);



// Y-Series
Query querySal = QueryImpl.create( "row[\"SAL\"]" );//$NON-NLS-1$
BarSeries bs = (BarSeries) BarSeriesImpl.create();
bs.getDataDefinition().add(querySal);

bs.setRiserOutline(null);
bs.setSeriesIdentifier("Highlight"); //$NON-NLS-1$
bs.getLabel().setVisible(true);
bs.setLabelPosition(Position.INSIDE_LITERAL);

SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getSeriesPalette( ).update( -2 );
yAxisPrimary.getSeriesDefinitions().add(sdY);
sdY.getSeries().add(bs);


return cwaBar;
}

}

[Updated on: Thu, 23 December 2010 04:02]

Report message to a moderator

Re: Can not create Bar Chart [message #646396 is a reply to message #646274] Thu, 23 December 2010 17:26 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Try this:


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.Anchor;
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.LineAttributes;
import org.eclipse.birt.chart.model.attribute.LineStyle;
import org.eclipse.birt.chart.model.attribute.Position;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
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.TextDataSet;
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.TextDataSetImpl;
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.BarSeries;
import org.eclipse.birt.chart.model.type.LineSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.Expression;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
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.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.RowHandle;
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.Comput edColumn;
import
org.eclipse.birt.report.model.api.elements.structures.Proper tyBinding;
import
org.eclipse.birt.report.model.api.elements.structures.Result SetColumn;

import com.ibm.icu.util.ULocale;

/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/

public class BuildBar {
private OdaDataSourceHandle customerDataSource = null;
private static ReportDesignHandle design;
private ElementFactory factory = null;
private ReportDesignHandle reportDesignHandle = null;
private String dataSourceName = "Data Source V";
String query = "Select ENAME,SAL from SCOTT.EMP";
ComputedColumn cs1,cs2 = null;
public static void main(String[] args) {
try {
new BuildBar().buildReport();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SemanticException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

// This function shows how to build a very simple BIRT report with a
// minimal set of content: a simple grid with an image and a label.

public 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.

// Configure the Engine and start the Platform
DesignConfig config = new DesignConfig();

config
.setProperty("BIRT_HOME",

" c:\\birt\\birt-runtime-2_5_2\\birt-runtime-2_5_2\\ReportEngi ne ");
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();
}

SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);

// Create a new report design.

design = session.createDesign();

// The element factory creates instances of the various BIRT
elements.

factory = design.getElementFactory();

createDataSources();
buildDataSet("Data Set",dataSourceName,query);
// 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.

DesignElementHandle element = factory
.newSimpleMasterPage("Page Master"); //$NON-NLS-1$
design.getMasterPages().add(element);

// Create a grid and add it to the "body" slot of the report
// design.

GridHandle grid = factory.newGridItem(null, 3 /* cols */, 1 /*
row */);
design.getBody().add(grid);

// Note: Set the table width to 100% to prevent the label
// from appearing too narrow in the layout view.

grid.setWidth("100%"); //$NON-NLS-1$

// Get the first row.

RowHandle row = (RowHandle) grid.getRows().get(0);

// Create an image and add it to the first cell.

ImageHandle image = factory.newImage(null);
CellHandle cell = (CellHandle) row.getCells().get(0);
cell.getContent().add(image);

image.setURL("\" http://www.eclipse.org/birt/phoenix/tutorial/basic/multichip -4.jpg\"");

// Create a label and add it to the second cell.

LabelHandle label = factory.newLabel(null);
cell = (CellHandle) row.getCells().get(1);
cell.getContent().add(label);
label.setText("Hello, world!"); //$NON-NLS-1$

cell = (CellHandle) row.getCells().get(2);

ExtendedItemHandle eih = factory.newExtendedItem(null,
"Chart");//$NON-NLS-1$
try {
eih.setHeight("288pt");//$NON-NLS-1$
eih.setWidth("252pt");//$NON-NLS-1$
eih.setProperty(ExtendedItemHandle.DATA_SET_PROP, "Data
Set");//$NON-NLS-1$

cs1 = StructureFactory.createComputedColumn();
cs1.setName("Employee Name");
cs1.setExpression("dataSetRow[\"ENAME\"]");
cs1.setDataType("string");

cs2 = StructureFactory.createComputedColumn();
cs2.setName("Salary");
cs2.setExpression("dataSetRow[\"SAL\"]");
cs2.setDataType("decimal");

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

eih.getReportItem().setProperty("chart.instance",
createChart());//$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
cell.getContent().add(eih);

design.saveAs("report/samplev4.rptdesign"); //$NON-NLS-1$
design.close();
System.out.println("Finished");

// We're done!
}

public void createDataSources() {
// type of the data source

String extensionID = "org.eclipse.birt.report.data.oda.jdbc";

String driverClassName = "oracle.jdbc.OracleDriver";

String driverURL = "jdbc:oracle:thin:@localhost:1521:orcl";

String userName = "SCOTT";

String userPassword = "scott";

// now make a data source with the dataSourceName and extensionID.
try {

OdaDataSourceHandle customerDataSource =
factory.newOdaDataSource(
dataSourceName, extensionID);
customerDataSource.setProperty("odaDriverClass",
driverClassName);

customerDataSource.setProperty("odaURL", driverURL);

customerDataSource.setProperty("odaUser", userName);

customerDataSource.setProperty("odaPassword", userPassword);

System.out.println("odaURL is "
+ customerDataSource.getProperty("odaURL"));

System.out.println("odaUser is "
+ customerDataSource.getProperty("odaUser"));

System.out.println("odaPassword is "
+ customerDataSource.getProperty("odaPassword"));

design.getDataSources().add(customerDataSource);
PropertyBinding pb = new PropertyBinding();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Build the query ( data set to use in the report).
*/
public void buildDataSet(String dataSetName,String
dataSourceName,String qry) throws SemanticException
{
OdaDataSetHandle dataSetHandle =
design.getElementFactory().newOdaDataSet(
dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet " );
dataSetHandle.setDataSource(dataSourceName);
dataSetHandle.setQueryText(qry );



design.getDataSets( ).add( dataSetHandle );
}


private Chart createHSChart() {

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

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


// 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();
LineAttributes lia = lg.getOutline();
lg.getText().getFont().setSize(16);
lia.setStyle(LineStyle.SOLID_LITERAL);
lg.getInsets().set(10, 5, 0, 0);
lg.getOutline().setVisible(false);
lg.setAnchor(Anchor.NORTH_LITERAL);
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);

// X-Series



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

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

SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).update( ColorDefinitionImpl.GREEN( ) );
sdX.getSeriesPalette( ).shift( 0 );
//sdX.setSorting(SortOption.ASCENDING_LITERAL);
// Set default grouping.
//SeriesGrouping grouping = sdX.getGrouping( );
//grouping.getAggregateExpression();
//grouping.setEnabled( true );
//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
BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );

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


SeriesDefinition sdY = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).update( ColorDefinitionImpl.GREEN( ) );
sdX.getSeriesPalette( ).shift( 0 );
//sdY.getGrouping().setEnabled(false);
yAxisPrimary.getSeriesDefinitions( ).add( sdY );

sdY.getSeries( ).add( bs1 );


return cwaLine;
}

}

Jason

On 12/22/2010 9:32 PM, Viet Bui wrote:
> 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.Anchor;
> 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.LineAttributes;
> import org.eclipse.birt.chart.model.attribute.LineStyle;
> import org.eclipse.birt.chart.model.attribute.Position;
> import org.eclipse.birt.chart.model.attribute.TickStyle;
> import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
> 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.NumberDataSet;
> import org.eclipse.birt.chart.model.data.Query;
> import org.eclipse.birt.chart.model.data.SeriesDefinition;
> import org.eclipse.birt.chart.model.data.TextDataSet;
> 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.TextDataSetImpl;
> 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.BarSeries;
> import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.report.model.api.CellHandle;
> import org.eclipse.birt.report.model.api.DesignConfig;
> import org.eclipse.birt.report.model.api.DesignElementHandle;
> import org.eclipse.birt.report.model.api.ElementFactory;
> import org.eclipse.birt.report.model.api.Expression;
> import org.eclipse.birt.report.model.api.ExtendedItemHandle;
> 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.LabelHandle;
> import org.eclipse.birt.report.model.api.OdaDataSetHandle;
> import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
> import org.eclipse.birt.report.model.api.ReportDesignHandle;
> import org.eclipse.birt.report.model.api.RowHandle;
> 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.Comput edColumn;
> import
> org.eclipse.birt.report.model.api.elements.structures.Proper tyBinding;
>
> import com.ibm.icu.util.ULocale;
>
> /**
> * Simple BIRT Design Engine API (DEAPI) demo.
> */
>
> public class DemoCreateRPT {
> private OdaDataSourceHandle customerDataSource = null;
> private static ReportDesignHandle design;
> private ElementFactory factory = null;
> private ReportDesignHandle reportDesignHandle = null;
> private String dataSourceName = "Data Source V";
> String query = "Select ENAME,SAL from SCOTT.EMP";
> ComputedColumn cs1,cs2 = null;
> public static void main(String[] args) {
> try {
> new DemoCreateRPT().buildReport();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (SemanticException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> // This function shows how to build a very simple BIRT report with a
> // minimal set of content: a simple grid with an image and a label.
>
> public 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.
>
> // Configure the Engine and start the Platform
> DesignConfig config = new DesignConfig();
>
> config
> .setProperty("BIRT_HOME",
>
> " F:\\Program\\Tools\\Java\\birt-runtime-2_5_2\\birt-runtime-2 _5_2\\ReportEngine ");
>
> IDesignEngine engine = null;
> try {
> Platform.startup(config);
> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
>
> .createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_E NGINE_FACTORY);
> engine = factory.createDesignEngine(config);
>
> } catch (Exception ex) {
> ex.printStackTrace();
> }
>
> SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
>
> // Create a new report design.
>
> design = session.createDesign();
>
> // The element factory creates instances of the various BIRT
> elements.
>
> factory = design.getElementFactory();
>
> createDataSources();
> buildDataSet("Data Set",dataSourceName,query);
> // 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.
>
> DesignElementHandle element = factory
> .newSimpleMasterPage("Page Master"); //$NON-NLS-1$
> design.getMasterPages().add(element);
>
> // Create a grid and add it to the "body" slot of the report
> // design.
>
> GridHandle grid = factory.newGridItem(null, 3 /* cols */, 1 /*
> row */);
> design.getBody().add(grid);
>
> // Note: Set the table width to 100% to prevent the label
> // from appearing too narrow in the layout view.
>
> grid.setWidth("100%"); //$NON-NLS-1$
>
> // Get the first row.
>
> RowHandle row = (RowHandle) grid.getRows().get(0);
>
> // Create an image and add it to the first cell.
>
> ImageHandle image = factory.newImage(null);
> CellHandle cell = (CellHandle) row.getCells().get(0);
> cell.getContent().add(image);
>
> image.setURL("\" http://www.eclipse.org/birt/phoenix/tutorial/basic/multichip -4.jpg\"");
>
>
> // Create a label and add it to the second cell.
>
> LabelHandle label = factory.newLabel(null);
> cell = (CellHandle) row.getCells().get(1);
> cell.getContent().add(label);
> label.setText("Hello, world!"); //$NON-NLS-1$
>
> cell = (CellHandle) row.getCells().get(2);
>
> ExtendedItemHandle eih = factory.newExtendedItem(null,
> "Chart");//$NON-NLS-1$
> try {
> eih.setHeight("288pt");//$NON-NLS-1$
> eih.setWidth("252pt");//$NON-NLS-1$
> eih.setProperty(ExtendedItemHandle.DATA_SET_PROP, "Data
> Set");//$NON-NLS-1$
>
> cs1 = StructureFactory.createComputedColumn();
> cs1.setName("Employee Name");
> cs1.setExpression("dataSetRow[\"ENAME\"]");
> cs1.setDataType("string");
>
> cs2 = StructureFactory.createComputedColumn();
> cs2.setName("Salary");
> cs2.setExpression("dataSetRow[\"SAL\"]");
> cs2.setDataType("decimal");
>
> eih.addColumnBinding(cs1, true);
> eih.addColumnBinding(cs2, true);
>
> eih.getReportItem().setProperty("chart.instance",
> createHSChart());//$NON-NLS-1$
> } catch (Exception e) {
> e.printStackTrace();
> }
> cell.getContent().add(eih);
>
> design.saveAs("c:/tmp/samplev2.rptdesign"); //$NON-NLS-1$
> design.close();
> System.out.println("Finished");
>
> // We're done!
> }
>
> public void createDataSources() {
> // type of the data source
>
> String extensionID = "org.eclipse.birt.report.data.oda.jdbc";
>
> String driverClassName = "oracle.jdbc.OracleDriver";
>
> String driverURL = "jdbc:oracle:thin:@localhost:1521:orcl";
>
> String userName = "SCOTT";
>
> String userPassword = "scott";
>
> // now make a data source with the dataSourceName and extensionID.
> try {
>
> OdaDataSourceHandle customerDataSource =
> factory.newOdaDataSource(
> dataSourceName, extensionID);
> customerDataSource.setProperty("odaDriverClass",
> driverClassName);
>
> customerDataSource.setProperty("odaURL", driverURL);
>
> customerDataSource.setProperty("odaUser", userName);
>
> customerDataSource.setProperty("odaPassword", userPassword);
>
> System.out.println("odaURL is "
> + customerDataSource.getProperty("odaURL"));
>
> System.out.println("odaUser is "
> + customerDataSource.getProperty("odaUser"));
>
> System.out.println("odaPassword is "
> + customerDataSource.getProperty("odaPassword"));
>
> design.getDataSources().add(customerDataSource);
> PropertyBinding pb = new PropertyBinding();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> /**
> * Build the query ( data set to use in the report).
> */
> public void buildDataSet(String dataSetName,String
> dataSourceName,String qry) throws SemanticException
> {
> OdaDataSetHandle dataSetHandle =
> design.getElementFactory().newOdaDataSet(
> dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet " );
> dataSetHandle.setDataSource(dataSourceName);
> dataSetHandle.setQueryText(qry );
> design.getDataSets( ).add( dataSetHandle );
> }
>
>
> public Chart createHSChart() {
> String[] cols = {
> "ENAME","SAL"
> };
> String[][] reportCols = {
> {"ENAME","Employee name"},
> {"ENAME","Salary"}
> };
>
>
> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
>
> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
>
> Plot p = cwaBar.getPlot();
> p.getClientArea().setBackground(
> ColorDefinitionImpl.create(255, 255, 225));
> cwaBar.getTitle().getLabel().getCaption().setValue("Simple Bar
> Chart"); //$NON-NLS-1$
> cwaBar.setUnitSpacing(20);
>
> Legend lg = cwaBar.getLegend();
> LineAttributes lia = lg.getOutline();
> lg.getText().getFont().setSize(16);
> lia.setStyle(LineStyle.SOLID_LITERAL);
> lg.getInsets().set(10, 5, 0, 0);
> lg.getOutline().setVisible(false);
> lg.setAnchor(Anchor.NORTH_LITERAL);
> lg.setItemType(LegendItemType.CATEGORIES_LITERAL);
>
> // X-Axis
>
> Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];
>
> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
> xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LIT ERAL);
> xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
> xAxisPrimary.getTitle().setVisible(true);
>
>
> // Y-Axis
> Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
> yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
> yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
> yAxisPrimary.getLabel().getCaption().getFont().setRotation(9 0);
>
> // X-Series
> Series seCategory = SeriesImpl.create( );
> Query query = QueryImpl.create( "row[\"ENAME\"]" );//$NON-NLS-1$
> seCategory.getDataDefinition( ).add( query );
>
> SeriesDefinition sdX = SeriesDefinitionImpl.create();
> xAxisPrimary.getSeriesDefinitions( ).add( sdX );
> sdX.getSeries().add(seCategory);
>
>
>
> // Y-Series
> Query querySal = QueryImpl.create( "row[\"SAL\"]" );//$NON-NLS-1$
> BarSeries bs = (BarSeries) BarSeriesImpl.create();
> bs.getDataDefinition().add(querySal);
>
> bs.setRiserOutline(null);
> bs.setSeriesIdentifier("Highlight"); //$NON-NLS-1$
> bs.getLabel().setVisible(true);
> bs.setLabelPosition(Position.INSIDE_LITERAL);
>
> SeriesDefinition sdY = SeriesDefinitionImpl.create();
> sdY.getSeriesPalette( ).update( -2 );
> yAxisPrimary.getSeriesDefinitions().add(sdY);
> sdY.getSeries().add(bs);
>
>
> return cwaBar;
> }
>
> }
Previous Topic:Format for setting eSpreadsheet date parameter with callback
Next Topic:The selected driver cannot parse the given JNDI Data Source URL.
Goto Forum:
  


Current Time: Thu Apr 18 18:26:16 GMT 2024

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

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

Back to the top