package com.digiassn.blogspot.birt;
import java.util.logging.Level;
import org.eclipse.birt.chart.model.ChartWithoutAxes;
import org.eclipse.birt.chart.model.attribute.ChartDimension;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
import org.eclipse.birt.report.model.api.extension.ExtendedElementException;
public class ModifyChart {
   /**
    * @param args
    */
   public static void main(String[] args) {
       try {
           IReportEngine engine = null;
           EngineConfig config = null;
           // Configure the Engine and start the Platform
           config = new EngineConfig();
           config
                   .setEngineHome("C:/Libraries/birt-runtime-2_5_1/ReportEngine");
           // set log config using ( null, Level ) if you do not want a log file
           config.setLogConfig("C:/temp", Level.FINE);
           //start birt platform and create factories
           Platform.startup(config);
           IReportEngineFactory factory = (IReportEngineFactory) Platform
                   .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
           engine = factory.createReportEngine(config);
           engine.changeLogLevel(Level.WARNING);
           //open report design
           IReportRunnable design = engine
           .openReportDesign("C:/contracts/BirtExamples/BirtReportEngine/PieChart.rptdesign");
           //get chart element handle called "PieChart"
           ExtendedItemHandle eih = (ExtendedItemHandle) design.getDesignHandle()
                   .getDesignHandle().findElement("PieChart");
          
           //get the actual chart instance since Charts are extended item handles
           ChartWithoutAxes cwa = (ChartWithoutAxes) eih.getReportItem().getProperty(
                   "chart.instance");
          
           //set title of chart to New Label
           cwa.getTitle().getLabel().getCaption().setValue("New Label");
          
           //set 2d with depth
           cwa.setDimension(ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL);
          
           // Create task to run and render the report,
           IRunAndRenderTask task = engine.createRunAndRenderTask(design);
           // Set rendering options - such as file or stream output,
           // output format, whether it is embeddable, etc
           HTMLRenderOption options = new HTMLRenderOption();
           options.setBaseURL("http://localhost/");
           options.setBaseImageURL("http://localhost/myimages");
           options.setImageDirectory("C:/xampplite/htdocs/myimages");
           options.setSupportedImageFormats("JPG;PNG;BMP;SVG");
           options.setOutputStream(System.out);
           // Set output format
           options.setOutputFormat("html");
           task.setRenderOption(options);
           // run the report and destroy the engine
           // Note - If the program stays resident do not shutdown the Platform or
           // the Engine
           task.run();
           task.close();
      
           task.close();
           Platform.shutdown();
           System.out.println("Finished");
       } catch (ExtendedElementException e) {
           e.printStackTrace();
       } catch (EngineException e) {
           e.printStackTrace();
       } catch (BirtException e) {
           e.printStackTrace();
       }
   }
}
The thing to remember about charts in BIRT reports is that they are Chart types stored withing a ExtendedItemHandler. So you need to find the ExtendedItemHandler first, then get the chart inside of it. Charts can be ChartsWithAxis (bar charts, lines charts), or ChartsWithoutAxis (pie charts). Reference on the chart types can be found here.
ChartWithAxes
ChartWithoutAxes
 
 
 
 Posts
Posts
 
