17/05/2007, 09:54
|
| | Fecha de Ingreso: mayo-2007
Mensajes: 8
Antigüedad: 17 años, 7 meses Puntos: 0 | |
Un poco mas de informacion Hola,
he buscado por todas partes y no he encontrado solución a mi problema.
Mi clase es:
public class BarChart
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;
String[] cols = {"CITY", "CUSTOMERNUMBER"};
OdaDataSetHandle dsHandle = null;
MetaDataDictionary dict;
public static void main( String[] args )
{
try
{
BarChart bc = new BarChart();
bc.buildReport( );
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void buildDataSource( ) throws SemanticException
{
OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
"ChartDataSource", "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Dri ver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );
designHandle.getDataSources( ).add( dsHandle );
}
void buildDataSet( ) throws SemanticException
{
dsHandle = designFactory.newOdaDataSet( "ChartData",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectD ataSet" );
dsHandle.setDataSource( "ChartDataSource" );
String qry = "SELECT CITY, CUSTOMERNUMBER FROM CUSTOMERS WHERE CUSTOMERNUMBER < 125";
dsHandle.setQueryText( qry );
designHandle.getDataSets( ).add( dsHandle );
}
void buildReport( ) throws IOException, SemanticException
{
//Configure the Engine and start the Platform
DesignConfig config = new DesignConfig( );
config.setProperty("BIRT_HOME", "C:/Archivos de programa/birt-runtime-2_1_2/ReportEngine");
IDesignEngine engine = null;
try{
Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTO RY );
engine = factory.createDesignEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
try{
//open a design or a template
designHandle = session.createDesign();
designFactory = designHandle.getElementFactory( );
DesignElementHandle simpleMasterPage = designFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
designHandle.getMasterPages( ).add( simpleMasterPage );
buildDataSource();
buildDataSet();
createBody();
createTable();
// Save the design and close it.
designHandle.saveAs( "E:/stage/MyChart.rptdesign" ); //$NON-NLS-1$
designHandle.close( );
Platform.shutdown();
System.out.println("Finished");
}catch (Exception e){
e.printStackTrace();
}
}
private void createBody() throws SemanticException{
designHandle.getBody().add(createMultiYSeriesChart ());
}
protected ExtendedItemHandle createMultiYSeriesChart( )
{
ExtendedItemHandle eih = designFactory.newExtendedItem ( null, "Chart" );//$NON-NLS-1$
try
{
eih.setHeight( "7.51in" );//$NON-NLS-1$
eih.setWidth( "4.447in" );//$NON-NLS-1$
eih.setProperty ( ExtendedItemHandle.DATA_SET_PROP, "ChartData" );//$NON-NLS-1$
}
catch ( SemanticException e )
{
e.printStackTrace( );
}
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
cwaBar.setType("Bar Chart");
cwaBar.setSubType("Side-by-side");
// Plot
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
Plot p = cwaBar.getPlot( );
p.getClientArea( )
.setBackground( GradientImpl.create( ColorDefinitionImpl.create( 225,
225,
255 ),
ColorDefinitionImpl.create( 255, 255, 225 ),
-35,
false ) );
p.getOutline( ).setVisible( true );
// Title
cwaBar.getTitle( )
.getLabel( )
.getCaption( )
.setValue( "Bar Chart with Multiple Y Series" );//$NON-NLS-1$
// Legend
Legend lg = cwaBar.getLegend( );
lg.getText( ).getFont( ).setSize( 16 );
lg.getText( ).getFont( ).setBold( true );
lg.getInsets( ).set( 10, 5, 0, 0 );
lg.setAnchor( Anchor.NORTH_LITERAL );
lg.setVisible(true);
// 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( ).getCaption( ).setValue( "Eje X" ); //$NON-NLS-1$
xAxisPrimary.setLabelPosition ( Position.BELOW_LITERAL );
xAxisPrimary.setTitlePosition( Position.BELOW_LITERAL );
// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
yAxisPrimary.getTitle( )
.getCaption( )
.setValue( "Eje Y" );//$NON-NLS-1$
// X-Series
Series seCategory = SeriesImpl.create( );
Query query = QueryImpl.create( "row[\"" + (String)cols[0] + "\"]" );//$NON-NLS-1$
seCategory.getDataDefinition( ).add( query );
//seCategory.setDataSet( categoryValues );
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series (1)
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
bs.setSeriesIdentifier( "Sales" );//$NON-NLS-1$
Query query1 = QueryImpl.create( "row[\"" + (String)cols[1] + "\"]" );//$NON-NLS-1$
bs.getDataDefinition( ).add( query1 );
//bs.setDataSet( orthoValues1 );
bs.setRiserOutline( null );
bs.getLabel( ).setVisible( true );
bs.setLabelPosition( Position.INSIDE_LITERAL );
SeriesDefinition sdY1 = SeriesDefinitionImpl.create( );
sdY1.getSeriesPalette( ).update( -2 );
yAxisPrimary.getSeriesDefinitions( ).add( sdY1 );
sdY1.getSeries( ).add( bs );
ChartReportItemImpl crii = null;
try
{
//Add ChartReportItemImpl to ExtendedItemHandle
crii = (ChartReportItemImpl) eih.getReportItem( );
//Add chart instance to ChartReportItemImpl
crii.setProperty( "chart.instance", cwaBar );//$NON-NLS-1$
}
catch ( ExtendedElementException e )
{
e.printStackTrace( );
}
return eih;
}
void createTable(){
try{
TableHandle table = designFactory.newTableItem( "table", cols.length);
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ChartData" ) );
PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;
for( int i=0; i < cols.length; i++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols[i]);
cs1.setExpression("dataSetRow[\"" + (String)cols[i] + "\"]");
computedSet.addItem(cs1);
}
// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
tableheader.setProperty( StyleHandle.BACKGROUND_COLOR_PROP, "Gray" );
tableheader.setProperty(IStyleModel.TEXT_ALIGN_PRO P,DesignChoiceConstants.BACKGROUND_POSITION_CENTER );
for( int i=0; i < cols.length; i++){
LabelHandle label1 = designFactory.newLabel( (String)cols[i] );
label1.setText((String)cols[i]);
CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
cell.getContent( ).add( label1 );
}
// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for( int i=0; i < cols.length; i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols[i] );
data.setResultSetColumn( (String)cols[i]);
cell.getContent( ).add( data );
}
designHandle.getBody( ).add( table );
}catch(Exception e){
System.out.println("Exception at createTable: " + e);
}
}
}
Cuando hago la previsualización de mi diseño solo veo la tabla. No entiendo po qué. Además si después sobre el diseño hago cualquier modificación (por ejemplo: borrar la tabla, añadir una etiqueta o redimensionar el chart con el raton) puedo ver ya el chart. Eso significa que el chart se crea, pero lo que no hace es visualizarse.
Estoy utilizando la version Eclipse 3.2.2 y la version 2.1.2 tanto de BirtRuntime , BirtCharts y "BirtReportDesinger all in one". No se si se puede tratar de un error de estas versiones
POR FAVOR, PUEDE ALGUIEN AYUDARME?????????
Muchas gracias. |