Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [birt-charting-dev] can't display chart

Hi,

I would recommend to post your questions on the BIRT newsgroups. This mailing list is for developer communications.

To answer your question, can you try this to see if this helps in the code you use to render the report (I couldn't find it in your class):

renderContext.getRenderOption().setImageHandler(new 
HTMLServerImageHandler());

Thanks,

David

-----Original Message-----
From: birt-charting-dev-bounces@xxxxxxxxxxx [mailto:birt-charting-dev-bounces@xxxxxxxxxxx] On Behalf Of Elsa Gómez Saiz
Sent: Friday, May 18, 2007 7:36 PM
To: birt-charting-dev@xxxxxxxxxxx
Subject: [birt-charting-dev] can't display chart

Hi,
I want to display a birt design with the Eclipse-birt preview option.
My design (.rptdesign) has a table and a bar chart.
The problem is when I display the design, because I ONLY see the table.
Why can't I see the bar chart????

I think it's a configuration problem... but really, I've not idea.
Which *.jar there be at the classpath?

Can anybody help me, PLEASE????

Here is my class:

import java.io.IOException;

import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.Chart;
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.Position;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.attribute.impl.GradientImpl ;
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.Query ;
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.BarSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl ;
import org.eclipse.birt.chart.engine.*;
import org.eclipse.birt.chart.reportitem.ChartReportItemImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.GridHandle;
import org.eclipse.birt.report.model.api.DesignEngine;
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.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
import org.eclipse.birt.report.model.api.StyleHandle;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import org.eclipse.birt.report.model.elements.interfaces.IStyleModel;
import org.eclipse.birt.report.model.api.extension.ExtendedElementException;
import org.eclipse.birt.report.model.metadata.MetaDataDictionary;
import org.eclipse.birt.report.model.api.metadata.IMetaDataDictionary;

import com.ibm.icu.util.ULocale;

/**
* Dynamic Table BIRT Design Engine API (DEAPI) demo.
*/

public class DataCharts
{
	ReportDesignHandle designHandle = null;
	ElementFactory designFactory = null;
	IMetaDataDictionary dict = null;
	String[] cols = {"CITY", "CUSTOMERNUMBER"};

	public static void main( String[] args )
	{
		try
		{
			DataCharts bc = new DataCharts();

			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.Driver" );
		dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
		dsHandle.setProperty( "odaUser", "ClassicModels" );
		dsHandle.setProperty( "odaPassword", "" );

		designHandle.getDataSources( ).add( dsHandle );

	}

	void buildDataSet( ) throws SemanticException
	{

		OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ChartData",
				"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
		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_FACTORY );
			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( );

			dict = new DesignEngine( null ).getMetaData( );

			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/CHART.rptdesign" ); //$NON-NLS-1$

			designHandle.close( );
			Platform.shutdown();

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


	private void createBody() throws SemanticException{


		GridHandle grid = designFactory.newGridItem( null, 1 /* cols */, 1 /* row 
*/ );
		designHandle.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 );
		CellHandle cell = (CellHandle) row.getCells( ).get( 0 );
		cell.getContent( ).add(createMultiYSeriesChart());
		createTable();
    }

    protected  ExtendedItemHandle /*Chart*/ 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( );
        }

        //Chart cwaBar = null;
        ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
        cwaBar.setType("Bar Chart");
        //cwaBar.setSubType("Side-by-side");
        cwaBar.setSubType("Stacked-Bar");

        // Plot
        cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
        //cwaBar.getBlock( ).getOutline( ).setVisible( true );
        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( 1 );
        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_PROP,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);
    	}
    }

}

_________________________________________________________________
Moda para esta temporada. Ponte al día de todas las tendencias. 
http://www.msn.es/Mujer/moda/default.asp

_______________________________________________
birt-charting-dev mailing list
birt-charting-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/birt-charting-dev


Back to the top