Home » Archived » BIRT » working examples pie chart, line chart
working examples pie chart, line chart [message #259769] |
Mon, 29 October 2007 10:25  |
Eclipse User |
|
|
|
Originally posted by: markus.schlautmann.viadee.de
Hi,
are there any working examples for a pie chart and a line chart?
I need the java source files where the .rptdesign is created. I have to
create those charts with de deapi, the reapi and the chart api.
Thanks in advance
Best regards
Markus Schlautmann
|
|
| | |
Re: working examples pie chart, line chart [message #259920 is a reply to message #259864] |
Tue, 30 October 2007 05:58   |
Eclipse User |
|
|
|
Hi Markus,
What do you mean the preview is broken? Can you post a screenshot of the
problem?
To add a chart into a report, you need to create an extendeditemhandle and
set your chart model into it:
ExtendedItemHandle eih = elementFactory.newExtendedItem( null,
"Chart" );//$NON-NLS-1$
eih.getReportItem( ).setProperty( "chart.instance", chartModel );
There are some examples of this in the chart examples plugin source code.
Thanks,
David
"Markus Schlautmann" <Markus.Schlautmann@gmx.de> wrote in message
news:fg5gsa$d8m$1@build.eclipse.org...
> Scott,
>
> thats great. i have not found this before. the preview is somehow
> broken, but the sourcecode is ok.
> all the examples return a chart, how can i add a chart object to a
> report? i can not add a chart object to a cell of a grid.
> what step is missing?
>
> Best Regards
> Markus Schlautmann
>
> Scott Rosenbaum schrieb:
>> Markus,
>>
>> Windows => Show View => Other => Report and Chart Design => Chart
>> Examples
>>
>> Pick the chart you want from the tree on the left. When you find the
>> one you want, click open in the upper right corner and you will see the
>> source code used to build the chart.
>>
>> Scott Rosenbaum
>>
>>
>>
>>> there any working examples for a pie chart and a line chart?
>>> I need the java source files where the .rptdesign is created. I have
>>> to
>>> create those charts with de deapi, the reapi and the chart api.
>>
>>
|
|
|
Re: working examples pie chart, line chart [message #259993 is a reply to message #259920] |
Tue, 30 October 2007 18:12   |
Eclipse User |
|
|
|
Originally posted by: Markus.Schlautmann.gmx.de
Hi David,
i meant that i could not see anything on the preview. I tried to take
some screenshots but now it works perfektly. if it will happen again i
will take a screenshot of it.
i have a problem with your code. i tried it abd now i can add a pie
chart to a grid. but it will not appear in the .rptdesign. in the
..rptdesign appears only a grid with an empty cell.
i have a question to the following code:
---
ExtendedItemHandle eih = designFactory.newExtendedItem( null, "Pie
Chart" );
---
where can i find all the allowed strings for the newExtendedItem mehtod?
You used "Chart", i have to use "Pie Chart", what else can i use? is
there a howto somewhere in the internet?
but now my main problem:
i do the following after creating the chart:
try
{
GridHandle grid = designFactory.newGridItem(null, 1, 1);
designHandle.getBody().add(grid);
//Kopf soll über die ganze Seitenbreite gehen
grid.setWidth("100%");
/*row with 1 picture in each column*/
RowHandle row = (RowHandle) grid.getRows().get(0);
CellHandle cell = (CellHandle) row.getCells().get(0);
ExtendedItemHandle eih = designFactory.newExtendedItem( null, "Pie
Chart" );
eih.getReportItem( ).setProperty( "chart.instance", cwoaPie );
cell.getContent().add(eih);
}catch(Exception e)
{
System.out.println("hallo");
}
i will paste my complete code below:
package main2;
import java.util.logging.Level;
import org.eclipse.birt.chart.model.ChartWithoutAxes;
import org.eclipse.birt.chart.model.attribute.ChartDimension;
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.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.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
import org.eclipse.birt.chart.model.impl.ChartWithoutAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.type.PieSeries;
import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
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.engine.api.PDFRenderOption;
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.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import com.ibm.icu.util.ULocale;
public class CreateReport3
{
//Konstanten für das Ausgabeverzeichnis, den Dateinamen und Birt Runtime
final String output_path = "F:/stuff/eclipse/reports";
final String image_dir = "images";
final String engine_path =
"F:/stuff/eclipse/birt-runtime-2_2_1/ReportEngine";
final String filename = "pojo";
final String row_layout = "no_alternating_colours";
final String output_format = "pdf";
final String dimension = "";
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
IDesignEngine engine = null;
//Main erzeugt die Daten und führt die Reporterzeugung aus
public static void main(String[] args)
{
//start reporting
CreateReport3 de = new CreateReport3();
de.buildReport();
}
void buildReport()
{
configurePlatform();
buildBasicReport();
buildPieChartReport();
stopSavePlatform();
convertReport(output_format);
}
void configurePlatform()
{
try
{
System.out.println("starting configurePlatform() method");
DesignConfig config = new DesignConfig();
config.setProperty("BIRT_HOME", engine_path);
Platform.startup(config);
IDesignEngineFactory factory = (IDesignEngineFactory)
Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_ DESIGN_ENGINE_FACTORY);
engine = factory.createDesignEngine(config);
SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
designHandle = session.createDesign();
designFactory = designHandle.getElementFactory();
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished configurePlatform() method");
System.out.println();
}
void stopSavePlatform()
{
try
{
System.out.println("starting stopSavePlatform() method");
/*save file*/
designHandle.saveAs(output_path + "/" + filename + ".rptdesign");
designHandle.close();
Platform.shutdown();
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished stopSavePlatform() method");
System.out.println("");
}
void buildBasicReport()
{
try
{
System.out.println("starting buildBasicReport method");
DesignElementHandle element = designFactory.newSimpleMasterPage("Page
Master");
designHandle.getMasterPages().add(element);
/*table with 2 columns, 1 row*/
GridHandle grid = designFactory.newGridItem(null, 2, 1);
designHandle.getBody().add(grid);
//Kopf soll über die ganze Seitenbreite gehen
grid.setWidth("100%");
/*row with 1 picture in each column*/
RowHandle row = (RowHandle) grid.getRows().get(0);
//erstes Bild wird der Tabelle hinzugefügt
ImageHandle image = designFactory.newImage(null);
CellHandle cell = (CellHandle) row.getCells().get(0);
cell.getContent().add(image);
image.setFile("\"images/logo_viadee.gif\"");
//zweites Bild wird der Tabelle hinzugefügt
ImageHandle image2 = designFactory.newImage(null);
cell = (CellHandle) row.getCells().get(1);
cell.getContent().add(image2);
image2.setFile("\"images/logo_viadee2.jpg\"");
row = (RowHandle) grid.getRows().get(1);
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished buildBasicReport() method");
System.out.println("");
}
void buildPieChartReport()
{
System.out.println("starting buildPieChartReport method");
ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( );
cwoaPie.setDimension( ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL );
cwoaPie.setType( "Pie Chart" );
cwoaPie.setSubType( "Standard Pie Chart" );
// Plot
cwoaPie.setSeriesThickness( 10 );
// Legend
Legend lg = cwoaPie.getLegend( );
lg.getOutline( ).setVisible( true );
// Title
cwoaPie.getTitle( ).getLabel( ).getCaption( ).setValue( "Pie Chart" );
// Data Set
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
"New York", "Boston", "Chicago", "San Francisco", "Dallas"} );
NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{
54.65, 21, 75.95, 91.28, 37.43
} );
SampleData sdata = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "" );
sdata.getBaseSampleData( ).add( sdBase );
OrthogonalSampleData sdOrthogonal =
DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal.setDataSetRepresentation( "" );
sdOrthogonal.setSeriesDefinitionIndex( 0 );
sdata.getOrthogonalSampleData( ).add( sdOrthogonal );
cwoaPie.setSampleData( sdata );
// Base Series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );
SeriesDefinition sd = SeriesDefinitionImpl.create( );
cwoaPie.getSeriesDefinitions( ).add( sd );
sd.getSeriesPalette( ).shift( 0 );
sd.getSeries( ).add( seCategory );
// Orthogonal Series
PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
sePie.setDataSet( seriesOneValues );
sePie.setSeriesIdentifier( "Cities" );
sePie.setExplosion( 5 );
SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
sd.getSeriesDefinitions( ).add( sdCity );
sdCity.getSeries( ).add( sePie );
try
{
GridHandle grid = designFactory.newGridItem(null, 1, 1);
designHandle.getBody().add(grid);
//Kopf soll über die ganze Seitenbreite gehen
grid.setWidth("100%");
/*row with 1 picture in each column*/
RowHandle row = (RowHandle) grid.getRows().get(0);
CellHandle cell = (CellHandle) row.getCells().get(0);
ExtendedItemHandle eih = designFactory.newExtendedItem( null, "Pie
Chart" );
eih.getReportItem( ).setProperty( "chart.instance", cwoaPie );
cell.getContent().add(eih);
}catch(Exception e)
{
System.out.println("hallo");
}
System.out.println("Finished buildPieChartReport() method");
System.out.println("");
}
void convertReport(String format)
{
System.out.println("starting convertReport() method");
EngineConfig config = new EngineConfig( );
IReportEngine engine = null;
IReportRunnable design = null;
try{
//Laufzeitumgebung starten
config = new EngineConfig( );
config.setEngineHome(engine_path);
//config.setLogConfig("F:/stuff/eclipse/log", Level.ALL);
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
engine.changeLogLevel( Level.WARNING );
}catch( Exception e){
e.printStackTrace();
}
try
{
//vorher hoffentlich erstelltes design öffnen
design = engine.openReportDesign(output_path + "/" + filename
+".rptdesign");
}catch(Exception e)
{
e.printStackTrace();
}
try
{
if(!format.equals("pdf") && !format.equals("html") &&
!format.equals("both"))
{
System.out.println("output format is not correct, switching to
default: pdf");
format = "pdf";
}
if(format.equals("pdf") || format.equals("both"))
{
System.out.println("starting pdf");
IRunAndRenderTask pdf_task = engine.createRunAndRenderTask(design);
//Optionen für den pdf_task setzen
PDFRenderOption pdf_options = new PDFRenderOption();
pdf_options.setOutputFileName(output_path + "/" + filename + ".pdf");
pdf_options.setOutputFormat("pdf");
pdf_task.setRenderOption(pdf_options);
pdf_task.run();
pdf_task.close();
System.out.println("Finished pdf");
}
if(format.equals("html") || format.equals("both"))
{
System.out.println("starting html");
IRunAndRenderTask html_task = engine.createRunAndRenderTask(design);
//Optionen für den html_task
HTMLRenderOption html_options = new HTMLRenderOption();
html_options.setOutputFileName(output_path + "/" + filename + ".html");
html_options.setOutputFormat("html");
html_options.setImageDirectory("image");
html_options.setBaseImageURL("images");
html_task.setRenderOption(html_options);
html_task.run();
html_task.close();
System.out.println("Finished html");
}
}
catch ( Exception e )
{
System.out.println("*****ERROR*****");
e.printStackTrace();
}
engine.destroy();
Platform.shutdown();
System.out.println("Finished convertReport() method");
System.out.println("");
}
}
David Michonneau schrieb:
> Hi Markus,
>
> What do you mean the preview is broken? Can you post a screenshot of the
> problem?
>
> To add a chart into a report, you need to create an extendeditemhandle and
> set your chart model into it:
>
> ExtendedItemHandle eih = elementFactory.newExtendedItem( null,
> "Chart" );//$NON-NLS-1$
>
> eih.getReportItem( ).setProperty( "chart.instance", chartModel );
>
> There are some examples of this in the chart examples plugin source code.
>
> Thanks,
>
> David
>
>
>
>
>
> "Markus Schlautmann" <Markus.Schlautmann@gmx.de> wrote in message
> news:fg5gsa$d8m$1@build.eclipse.org...
>> Scott,
>>
>> thats great. i have not found this before. the preview is somehow
>> broken, but the sourcecode is ok.
>> all the examples return a chart, how can i add a chart object to a
>> report? i can not add a chart object to a cell of a grid.
>> what step is missing?
>>
>> Best Regards
>> Markus Schlautmann
>>
>> Scott Rosenbaum schrieb:
>>> Markus,
>>>
>>> Windows => Show View => Other => Report and Chart Design => Chart
>>> Examples
>>>
>>> Pick the chart you want from the tree on the left. When you find the
>>> one you want, click open in the upper right corner and you will see the
>>> source code used to build the chart.
>>>
>>> Scott Rosenbaum
>>>
>>>
>>>
>>>> there any working examples for a pie chart and a line chart?
>>>> I need the java source files where the .rptdesign is created. I have
>>>> to
>>>> create those charts with de deapi, the reapi and the chart api.
>>>
>
>
|
|
| |
Re: working examples pie chart, line chart [message #260026 is a reply to message #259993] |
Wed, 31 October 2007 05:24   |
Eclipse User |
|
|
|
The string is the extensionName of the report item extension (see the
reportItemModel extension point). In that case it is "Chart". If you create
an extended item, you can use the name of the extension to create it using
this method. Now only crosstab and charts are extended items in BIRT.
All types of chart use the same extended item, so you don't need to change
it.
If you are unable to load the item, it probably means you are not in an OSGi
environment, so it can't load extension plugins. Please take a look at the
example in the chart examples plugin to see how this works.
Thanks,
David
"Markus Schlautmann" <Markus.Schlautmann@gmx.de> wrote in message
news:fg8a7o$6a3$1@build.eclipse.org...
> Hi David,
>
> i meant that i could not see anything on the preview. I tried to take
> some screenshots but now it works perfektly. if it will happen again i
> will take a screenshot of it.
>
> i have a problem with your code. i tried it abd now i can add a pie
> chart to a grid. but it will not appear in the .rptdesign. in the
> .rptdesign appears only a grid with an empty cell.
>
>
> i have a question to the following code:
> ---
> ExtendedItemHandle eih = designFactory.newExtendedItem( null, "Pie
> Chart" );
> ---
> where can i find all the allowed strings for the newExtendedItem mehtod?
> You used "Chart", i have to use "Pie Chart", what else can i use? is
> there a howto somewhere in the internet?
>
> but now my main problem:
>
> i do the following after creating the chart:
>
>
> try
> {
> GridHandle grid = designFactory.newGridItem(null, 1, 1);
> designHandle.getBody().add(grid);
>
> //Kopf soll
|
|
| | | |
Re: the exception [message #260078 is a reply to message #260063] |
Wed, 31 October 2007 10:16   |
Eclipse User |
|
|
|
Originally posted by: markus.schlautmann.viadee.de
David,
i'm confused.
I'm doing the following:
// Data Set
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
"New York", "Boston", "Chicago", "San Francisco", "Dallas"} );
NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{
54.65, 21, 75.95, 91.28, 37.43 } );
// Base Series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );
SeriesDefinition sd = SeriesDefinitionImpl.create( );
cwoaPie.getSeriesDefinitions( ).add( sd );
sd.getSeriesPalette( ).shift( 0 );
sd.getSeries( ).add( seCategory );
// Orthogonal Series
PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
sePie.setDataSet( seriesOneValues );
sePie.setSeriesIdentifier( "Cities" );
sePie.setExplosion( 5 );
SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
sd.getSeriesDefinitions( ).add( sdCity );
sdCity.getSeries( ).add( sePie );
Addionally to these Datasets i have to define a column binding?
Best Regards
Markus Schlautmann
|
|
|
Re: working examples pie chart, line chart [message #260128 is a reply to message #260056] |
Wed, 31 October 2007 16:31   |
Eclipse User |
|
|
|
Markus,
Been away a bit, but in the examples that you picked up earlier, there is
an example of inserting a pie chart into a report in the SalesReport example.
Perhaps that will help?
Scott
> Hi David,
>
> I'm sorry but i have to bother you again.
> I checked the examples from exclipse, the book "integrating and
> extending
> birt" and examples from the internet. I don't understand why my chart
> is
> not working.
> I'm creating a chart, i'm adding dataset (TextDataSet and
> NumberDataSet)
> to the series, i'm creating an extendedItemHandler and then add this
> extendedItem to a grid. All in all nothing special.
> There are no exceptions until i try to save the design. Then i get a
> NullPointerException. I will paste the exception at the end of my
> posting.
> After all i don't think that it is a code issue.
> You mentioned something with the osgi environment in your last post.
> How can i check this? I have installed the latest java-sdk-version,
> eclipse3.3.1, via the eclipse software updates i installed all of
> birt.
> I downloaded birt-runtime-2_2_1 and extracted it. The path to the birt
> runtime is configured with BIRT_HOME in my application.
> Do i need some additional plugins for this runtime for creating this
> extendedItems?
>
> Thank you very much for your efforts!
>
> Best Regards
> Markus Schlautmann
|
|
|
Re: the exception [message #260222 is a reply to message #260078] |
Thu, 01 November 2007 11:09   |
Eclipse User |
|
|
|
If the chart is inside a report, you cannot use hard-coded data. You must
use the data from the report. So define column bindings, and add references
to them in the chart model. Then the report will automatically populate the
chart data using the data from the db.
If you really need hard-coded data, you can use a scripted dataset then at
the report level, and use the dataset in the chart, but you still need to
define bindings like I mentioned.
Thanks,
David
"Markus Schlautmann" <markus.schlautmann@viadee.de> wrote in message
news:1f91890f3fe5b0dde64de2a0836fd623$1@www.eclipse.org...
> David,
>
> i'm confused.
> I'm doing the following:
>
> // Data Set
> TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
> "New York", "Boston", "Chicago", "San Francisco", "Dallas"} );
>
> NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{
> 54.65, 21, 75.95, 91.28, 37.43 } );
>
>
> // Base Series
> Series seCategory = SeriesImpl.create( );
> seCategory.setDataSet( categoryValues );
>
> SeriesDefinition sd = SeriesDefinitionImpl.create( );
> cwoaPie.getSeriesDefinitions( ).add( sd );
> sd.getSeriesPalette( ).shift( 0 );
> sd.getSeries( ).add( seCategory );
>
> // Orthogonal Series
> PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
> sePie.setDataSet( seriesOneValues );
> sePie.setSeriesIdentifier( "Cities" ); sePie.setExplosion( 5 );
>
> SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
> sd.getSeriesDefinitions( ).add( sdCity );
> sdCity.getSeries( ).add( sePie );
>
>
> Addionally to these Datasets i have to define a column binding?
>
> Best Regards
> Markus Schlautmann
>
>
|
|
|
nearly working [message #260444 is a reply to message #260222] |
Fri, 02 November 2007 14:16   |
Eclipse User |
|
|
|
Originally posted by: Markus.Schlautmann.gmx.de
David,
thank you very much for spending so much time in this group!
i hope this will be my last question in this thread.
i tried it as you told me. I created a data source and a data set and
defined column bindings.
My report compiles without errors now, but i get warnings:
starting buildPieChartReport method
02.11.2007 18:52:07
org.eclipse.birt.chart.reportitem.ChartReportItemImpl getPropertyDefinitions
WARNING: Request for property definitions received before model was created.
02.11.2007 18:52:07
org.eclipse.birt.chart.reportitem.ChartReportItemImpl getPropertyDefinitions
WARNING: Request for property definitions received before model was created.
02.11.2007 18:52:07
org.eclipse.birt.chart.reportitem.ChartReportItemImpl getPropertyDefinitions
WARNING: Request for property definitions received before model was created.
02.11.2007 18:52:07
org.eclipse.birt.chart.reportitem.ChartReportItemImpl getPropertyDefinitions
WARNING: Request for property definitions received before model was created.
02.11.2007 18:52:07
org.eclipse.birt.chart.reportitem.ChartReportItemImpl getPropertyDefinitions
WARNING: Request for property definitions received before model was created.
Finished buildPieChartReport() method
This happens every time i access the extended item handle, like
eih.setHeight() or eih.setWidth()......
How can i solve this?
I think this is nothing critical, the report design looks fine now, the
chart is in my design. The design is compiled without errors or warnings
into pdf. But in my pdf is no chart. What have i done wrong?
Best Regards
Markus Schlautmann
----
package main2;
import java.util.Vector;
import interfaces.IChart;
public class DataProviderChart implements IChart
{
private Vector<String> xValues;
private Vector<Float> yValues;
private String chartCaption;
private String xCaption;
private String yCaption;
public DataProviderChart()
{
chartCaption = "Mein Charttitel";
xCaption = "das ist die xAchse";
yCaption = "das ist die yAchse";
xValues = new Vector<String>();
yValues = new Vector<Float>();
xValues.add("one");
xValues.add("two");
xValues.add("three");
yValues.add(25.5f);
yValues.add(35.765f);
yValues.add(15.777f);
}
public Vector<String> getxValues()
{
return xValues;
}
public Vector<Float> getyValues()
{
return yValues;
}
public String getChartCaption()
{
return chartCaption;
}
public String getxCaption()
{
return xCaption;
}
public String getyCaption()
{
return yCaption;
}
}
----
----
package main2;
import interfaces.ITable;
import interfaces.IChart;
import java.util.Map;
import java.util.logging.Level;
import org.eclipse.birt.chart.device.IDeviceRenderer;
import org.eclipse.birt.chart.factory.GeneratedChartState;
import org.eclipse.birt.chart.factory.Generator;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.ChartWithoutAxes;
import org.eclipse.birt.chart.model.attribute.Bounds;
import org.eclipse.birt.chart.model.attribute.ChartDimension;
import org.eclipse.birt.chart.model.attribute.DataPointComponent;
import org.eclipse.birt.chart.model.attribute.DataPointComponentTyp e;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
import org.eclipse.birt.chart.model.attribute.impl.DataPointCompone ntImpl;
import org.eclipse.birt.chart.model.attribute.impl.GradientImpl;
import
org.eclipse.birt.chart.model.attribute.impl.JavaNumberFormat SpecifierImpl;
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.impl.ChartWithoutAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.type.BarSeries;
import org.eclipse.birt.chart.model.type.PieSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
import org.eclipse.birt.chart.util.PluginSettings;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
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.engine.api.PDFRenderOption;
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.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.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.ScriptDataSetHandle;
import org.eclipse.birt.report.model.api.ScriptDataSourceHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.StyleHandle;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
import org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
import org.eclipse.birt.report.model.api.elements.structures.Highli ghtRule;
import
org.eclipse.birt.report.model.api.elements.structures.Result SetColumn;
import com.ibm.icu.util.ULocale;
public class CreateReport3 implements DesignChoiceConstants
{
final String output_path = "F:/stuff/eclipse/reports";
final String image_dir = "images";
final String engine_path =
"F:/stuff/eclipse/birt-runtime-2_2_1/ReportEngine";
final String filename = "pojo";
final String row_layout = "no_alternating_colours";
final String output_format = "pdf";
final String dimension = "";
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
IDesignEngine engine = null;
public static void main(String[] args)
{
DataProviderChart dataProviderChart = new DataProviderChart();
CreateReport3 de = new CreateReport3();
de.buildReport(dataProviderChart);
}
void buildReport(IChart dataProvider)
{
configurePlatform();
buildDataSource();
buildDataSet(dataProvider);
buildBasicReport();
buildPieChartReport();
stopSavePlatform();
convertReport(output_format, dataProvider);
}
void configurePlatform()
{
try
{
System.out.println("starting configurePlatform() method");
DesignConfig config = new DesignConfig();
config.setProperty("BIRT_HOME", engine_path);
Platform.startup(config);
IDesignEngineFactory factory = (IDesignEngineFactory)
Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_ DESIGN_ENGINE_FACTORY);
engine = factory.createDesignEngine(config);
SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
designHandle = session.createDesign();
designFactory = designHandle.getElementFactory();
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished configurePlatform() method");
System.out.println();
}
void buildDataSource()
{
try
{
System.out.println("starting buildDataSource() method");
ScriptDataSourceHandle dsHandle =
designFactory.newScriptDataSource("Data Source");
designHandle.getDataSources().add(dsHandle);
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished buildDataSource() Method");
System.out.println("");
}
void buildDataSet(IChart dataProvider)
{
try
{
System.out.println("starting buildDataSet() method");
ScriptDataSetHandle dsHandle = designFactory.newScriptDataSet("ds");
dsHandle.setDataSource("Data Source");
dsHandle.setOpen("data = dataProvider.getyValues(); \n" +
"data2 = dataProvider.getxValues(); \n " +
"totalrows = data.size(); \n" +
"currentrow = 1;\n");
dsHandle.setFetch("if(currentrow >= totalrows) \n" +
"{return(false);} \n" +
"var favrow = data.get(currentrow); \n" +
"row[\"abc0\"] = favrow; \n"+
"var favrow2 = data2.get(currentrow); \n" +
"row[\"cba0\"] = favrow2 \n;"+
"currentrow = currentrow + 1; \n" +
"return(true); \n");
dsHandle.setClose("data = null; \n data2 = null; \n");
PropertyHandle computedSet =
dsHandle.getPropertyHandle(ScriptDataSetHandle.RESULT_SET_PR OP);
ResultSetColumn resultColumn =
StructureFactory.createResultSetColumn();
resultColumn = StructureFactory.createResultSetColumn();
resultColumn.setPosition(1);
resultColumn.setColumnName("abc0");
resultColumn.setDataType(COLUMN_DATA_TYPE_FLOAT);
computedSet.addItem(resultColumn);
resultColumn = StructureFactory.createResultSetColumn();
resultColumn.setPosition(2);
resultColumn.setColumnName("cba0");
resultColumn.setDataType(COLUMN_DATA_TYPE_STRING);
computedSet.addItem(resultColumn);
designHandle.getDataSets().add(dsHandle);
System.out.println("Finished buildDataSet() method");
System.out.println("");
}catch(Exception e)
{
e.printStackTrace();
}
}
void stopSavePlatform()
{
try
{
System.out.println("starting stopSavePlatform() method");
/*save file*/
designHandle.saveAs(output_path + "/" + filename + ".rptdesign");
designHandle.close();
Platform.shutdown();
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished stopSavePlatform() method");
System.out.println("");
}
void buildBasicReport()
{
try
{
System.out.println("starting buildBasicReport method");
DesignElementHandle element = designFactory.newSimpleMasterPage("Page
Master");
designHandle.getMasterPages().add(element);
/*table with 2 columns, 1 row*/
GridHandle grid = designFactory.newGridItem(null, 2, 1);
designHandle.getBody().add(grid);
//Kopf soll über die ganze Seitenbreite gehen
grid.setWidth("100%");
/*row with 1 picture in each column*/
RowHandle row = (RowHandle) grid.getRows().get(0);
//erstes Bild wird der Tabelle hinzugefügt
ImageHandle image = designFactory.newImage(null);
CellHandle cell = (CellHandle) row.getCells().get(0);
cell.getContent().add(image);
image.setFile("\"images/logo_viadee.gif\"");
//zweites Bild wird der Tabelle hinzugefügt
ImageHandle image2 = designFactory.newImage(null);
cell = (CellHandle) row.getCells().get(1);
cell.getContent().add(image2);
image2.setFile("\"images/logo_viadee2.jpg\"");
row = (RowHandle) grid.getRows().get(1);
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished buildBasicReport() method");
System.out.println("");
}
void buildPieChartReport()
{
try
{
System.out.println("starting buildPieChartReport method");
ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( );
cwoaPie.setDimension(
ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL );
cwoaPie.setType( "Pie Chart" );
cwoaPie.setSubType( "Standard Pie Chart" );
// Plot
cwoaPie.setSeriesThickness( 10 );
// Legend
Legend lg = cwoaPie.getLegend( );
lg.getOutline( ).setVisible( true );
// Title
cwoaPie.getTitle( ).getLabel( ).getCaption( ).setValue( "Pie Chart" );
// Base Series
Series seCategory = SeriesImpl.create( );
Query query = QueryImpl.create( "row[\"cba0\"]" );
seCategory.getDataDefinition().add(query);
SeriesDefinition sd = SeriesDefinitionImpl.create( );
cwoaPie.getSeriesDefinitions( ).add( sd );
sd.getSeriesPalette( ).shift( 0 );
sd.getSeries( ).add( seCategory );
// Orthogonal Series
PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
Query query2 = QueryImpl.create( "row[\"abc0\"]" );
sePie.getDataDefinition().add(query2);
sePie.setSeriesIdentifier( "Cities" );
sePie.setExplosion( 5 );
SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
sd.getSeriesDefinitions( ).add( sdCity );
sdCity.getSeries( ).add( sePie );
GridHandle grid = designFactory.newGridItem(null, 1, 1);
designHandle.getBody().add(grid);
grid.setWidth("100%");
/*row with 1 picture in each column*/
RowHandle row = (RowHandle) grid.getRows().get(0);
CellHandle cell = (CellHandle) row.getCells().get(0);
ExtendedItemHandle eih = designFactory.newExtendedItem( null, "Chart" );
eih.setDataSet(designHandle.findDataSet("ds"));
eih.setHeight( "500pt" );
eih.setWidth( "500pt" );
PropertyHandle computedSet = eih.getColumnBindings( );
ComputedColumn cs1 = StructureFactory.createComputedColumn();
cs1.setExpression( "dataSetRow[\"abc0\"]" );
cs1.setName("abc0");
cs1.setDataType(COLUMN_DATA_TYPE_FLOAT);
computedSet.addItem( cs1 );
ComputedColumn cs2 = StructureFactory.createComputedColumn();
cs2.setExpression( "dataSetRow[\"cba0\"]" );
cs2.setName("cba0");
cs2.setDataType(COLUMN_DATA_TYPE_STRING);
computedSet.addItem( cs2 );
eih.getReportItem( ).setProperty( "chart.instance", cwoaPie );
cell.getContent().add(eih);
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Finished buildPieChartReport() method");
System.out.println("");
}
void convertReport(String format, IChart dataProvider)
{
System.out.println("starting convertReport() method");
EngineConfig config = new EngineConfig( );
IReportEngine engine = null;
IReportRunnable design = null;
try{
//Laufzeitumgebung starten
config = new EngineConfig( );
config.setEngineHome(engine_path);
//config.setLogConfig("F:/stuff/eclipse/log", Level.ALL);
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
engine.changeLogLevel( Level.WARNING );
}catch( Exception e){
e.printStackTrace();
}
try
{
//vorher hoffentlich erstelltes design öffnen
design = engine.openReportDesign(output_path + "/" + filename
+".rptdesign");
}catch(Exception e)
{
e.printStackTrace();
}
try
{
if(!format.equals("pdf") && !format.equals("html") &&
!format.equals("both"))
{
System.out.println("output format is not correct, switching to
default: pdf");
format = "pdf";
}
if(format.equals("pdf") || format.equals("both"))
{
System.out.println("starting pdf");
IRunAndRenderTask pdf_task = engine.createRunAndRenderTask(design);
//Das Datenobjekt dem pdf-Task hinzugefügen
Map<String, Object> appContext = pdf_task.getAppContext();
appContext.put("dataProvider", dataProvider);
pdf_task.setAppContext(appContext);
//Optionen für den pdf_task setzen
PDFRenderOption pdf_options = new PDFRenderOption();
pdf_options.setOutputFileName(output_path + "/" + filename + ".pdf");
pdf_options.setOutputFormat("pdf");
pdf_task.setRenderOption(pdf_options);
pdf_task.run();
pdf_task.close();
System.out.println("Finished pdf");
}
if(format.equals("html") || format.equals("both"))
{
System.out.println("starting html");
IRunAndRenderTask html_task = engine.createRunAndRenderTask(design);
//Datenobjekt dem html_task hinzufügen
Map<String, Object> appContext = html_task.getAppContext();
appContext.put("dataProvider", dataProvider);
html_task.setAppContext(appContext);
//Optionen für den html_task
HTMLRenderOption html_options = new HTMLRenderOption();
html_options.setOutputFileName(output_path + "/" + filename + ".html");
html_options.setOutputFormat("html");
html_options.setImageDirectory("image");
html_options.setBaseImageURL("images");
html_task.setRenderOption(html_options);
html_task.run();
html_task.close();
System.out.println("Finished html");
}
}
catch ( Exception e )
{
System.out.println("*****ERROR*****");
e.printStackTrace();
System.out.println("");
System.out.println(e.getMessage());
}
engine.destroy();
Platform.shutdown();
System.out.println("Finished convertReport() method");
System.out.println("");
}
}
----
David Michonneau schrieb:
> If the chart is inside a report, you cannot use hard-coded data. You must
> use the data from the report. So define column bindings, and add references
> to them in the chart model. Then the report will automatically populate the
> chart data using the data from the db.
>
> If you really need hard-coded data, you can use a scripted dataset then at
> the report level, and use the dataset in the chart, but you still need to
> define bindings like I mentioned.
>
> Thanks,
>
> David
>
> "Markus Schlautmann" <markus.schlautmann@viadee.de> wrote in message
> news:1f91890f3fe5b0dde64de2a0836fd623$1@www.eclipse.org...
>> David,
>>
>> i'm confused.
>> I'm doing the following:
>>
>> // Data Set
>> TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
>> "New York", "Boston", "Chicago", "San Francisco", "Dallas"} );
>>
>> NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{
>> 54.65, 21, 75.95, 91.28, 37.43 } );
>>
>>
>> // Base Series
>> Series seCategory = SeriesImpl.create( );
>> seCategory.setDataSet( categoryValues );
>>
>> SeriesDefinition sd = SeriesDefinitionImpl.create( );
>> cwoaPie.getSeriesDefinitions( ).add( sd );
>> sd.getSeriesPalette( ).shift( 0 );
>> sd.getSeries( ).add( seCategory );
>>
>> // Orthogonal Series
>> PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
>> sePie.setDataSet( seriesOneValues );
>> sePie.setSeriesIdentifier( "Cities" ); sePie.setExplosion( 5 );
>>
>> SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
>> sd.getSeriesDefinitions( ).add( sdCity );
>> sdCity.getSeries( ).add( sePie );
>>
>>
>> Addionally to these Datasets i have to define a column binding?
>>
>> Best Regards
>> Markus Schlautmann
>>
>>
>
>
|
|
|
Re: nearly working [message #260604 is a reply to message #260444] |
Mon, 05 November 2007 08:09   |
Eclipse User |
|
|
|
I think you need to hook the chart in the report before you start setting
those properties.
For the pdf issue, I am not sure what it could be.
Thanks,
David
"Markus Schlautmann" <Markus.Schlautmann@gmx.de> wrote in message
news:fgfpie$8o7$1@build.eclipse.org...
> David,
>
> thank you very much for spending so much time in this group!
> i hope this will be my last question in this thread.
> i tried it as you told me. I created a data source and a data set and
> defined column bindings.
> My report compiles without errors now, but i get warnings:
>
> starting buildPieChartReport method
> 02.11.2007 18:52:07
> org.eclipse.birt.chart.reportitem.ChartReportItemImpl
> getPropertyDefinitions
> WARNING: Request for property definitions received before model was
> created.
> 02.11.2007 18:52:07
> org.eclipse.birt.chart.reportitem.ChartReportItemImpl
> getPropertyDefinitions
> WARNING: Request for property definitions received before model was
> created.
> 02.11.2007 18:52:07
> org.eclipse.birt.chart.reportitem.ChartReportItemImpl
> getPropertyDefinitions
> WARNING: Request for property definitions received before model was
> created.
> 02.11.2007 18:52:07
> org.eclipse.birt.chart.reportitem.ChartReportItemImpl
> getPropertyDefinitions
> WARNING: Request for property definitions received before model was
> created.
> 02.11.2007 18:52:07
> org.eclipse.birt.chart.reportitem.ChartReportItemImpl
> getPropertyDefinitions
> WARNING: Request for property definitions received before model was
> created.
> Finished buildPieChartReport() method
>
> This happens every time i access the extended item handle, like
> eih.setHeight() or eih.setWidth()......
> How can i solve this?
>
> I think this is nothing critical, the report design looks fine now, the
> chart is in my design. The design is compiled without errors or warnings
> into pdf. But in my pdf is no chart. What have i done wrong?
>
> Best Regards
> Markus Schlautmann
>
>
> ----
> package main2;
> import java.util.Vector;
>
> import interfaces.IChart;
>
> public class DataProviderChart implements IChart
> {
> private Vector<String> xValues;
> private Vector<Float> yValues;
> private String chartCaption;
> private String xCaption;
> private String yCaption;
>
> public DataProviderChart()
> {
> chartCaption = "Mein Charttitel";
> xCaption = "das ist die xAchse";
> yCaption = "das ist die yAchse";
>
> xValues = new Vector<String>();
> yValues = new Vector<Float>();
>
> xValues.add("one");
> xValues.add("two");
> xValues.add("three");
>
> yValues.add(25.5f);
> yValues.add(35.765f);
> yValues.add(15.777f);
> }
>
> public Vector<String> getxValues()
> {
> return xValues;
> }
>
> public Vector<Float> getyValues()
> {
> return yValues;
> }
>
> public String getChartCaption()
> {
> return chartCaption;
> }
>
> public String getxCaption()
> {
> return xCaption;
> }
>
> public String getyCaption()
> {
> return yCaption;
> }
> }
> ----
>
> ----
>
> package main2;
>
> import interfaces.ITable;
> import interfaces.IChart;
>
> import java.util.Map;
> import java.util.logging.Level;
>
> import org.eclipse.birt.chart.device.IDeviceRenderer;
> import org.eclipse.birt.chart.factory.GeneratedChartState;
> import org.eclipse.birt.chart.factory.Generator;
> import org.eclipse.birt.chart.model.ChartWithAxes;
> import org.eclipse.birt.chart.model.ChartWithoutAxes;
> import org.eclipse.birt.chart.model.attribute.Bounds;
> import org.eclipse.birt.chart.model.attribute.ChartDimension;
> import org.eclipse.birt.chart.model.attribute.DataPointComponent;
> import org.eclipse.birt.chart.model.attribute.DataPointComponentTyp e;
> import org.eclipse.birt.chart.model.attribute.LegendItemType;
> import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
> import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
> import org.eclipse.birt.chart.model.attribute.impl.DataPointCompone ntImpl;
> import org.eclipse.birt.chart.model.attribute.impl.GradientImpl;
> import
> org.eclipse.birt.chart.model.attribute.impl.JavaNumberFormat SpecifierImpl;
> 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.impl.ChartWithoutAxesImpl;
> import org.eclipse.birt.chart.model.layout.Legend;
> import org.eclipse.birt.chart.model.type.BarSeries;
> import org.eclipse.birt.chart.model.type.PieSeries;
> import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
> import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
> import org.eclipse.birt.chart.util.PluginSettings;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.report.engine.api.EngineConfig;
> 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.engine.api.PDFRenderOption;
> 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.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.PropertyHandle;
> import org.eclipse.birt.report.model.api.ReportDesignHandle;
> import org.eclipse.birt.report.model.api.RowHandle;
> import org.eclipse.birt.report.model.api.ScriptDataSetHandle;
> import org.eclipse.birt.report.model.api.ScriptDataSourceHandle;
> import org.eclipse.birt.report.model.api.SessionHandle;
> import org.eclipse.birt.report.model.api.StructureFactory;
> import org.eclipse.birt.report.model.api.StyleHandle;
> import org.eclipse.birt.report.model.api.TableHandle;
> import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
> import
> org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
> import
> org.eclipse.birt.report.model.api.elements.structures.Highli ghtRule;
> import
> org.eclipse.birt.report.model.api.elements.structures.Result SetColumn;
>
> import com.ibm.icu.util.ULocale;
>
> public class CreateReport3 implements DesignChoiceConstants
> {
> final String output_path = "F:/stuff/eclipse/reports";
> final String image_dir = "images";
> final String engine_path =
> "F:/stuff/eclipse/birt-runtime-2_2_1/ReportEngine";
> final String filename = "pojo";
> final String row_layout = "no_alternating_colours";
> final String output_format = "pdf";
> final String dimension = "";
>
> ReportDesignHandle designHandle = null;
> ElementFactory designFactory = null;
> IDesignEngine engine = null;
>
> public static void main(String[] args)
> {
> DataProviderChart dataProviderChart = new DataProviderChart();
> CreateReport3 de = new CreateReport3();
> de.buildReport(dataProviderChart);
> }
>
> void buildReport(IChart dataProvider)
> {
> configurePlatform();
> buildDataSource();
> buildDataSet(dataProvider);
> buildBasicReport();
> buildPieChartReport();
> stopSavePlatform();
> convertReport(output_format, dataProvider);
> }
>
> void configurePlatform()
> {
> try
> {
> System.out.println("starting configurePlatform() method");
>
> DesignConfig config = new DesignConfig();
> config.setProperty("BIRT_HOME", engine_path);
> Platform.startup(config);
> IDesignEngineFactory factory = (IDesignEngineFactory)
> Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_ DESIGN_ENGINE_FACTORY);
> engine = factory.createDesignEngine(config);
> SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
> designHandle = session.createDesign();
> designFactory = designHandle.getElementFactory();
> }catch(Exception e)
> {
> e.printStackTrace();
> }
> System.out.println("Finished configurePlatform() method");
> System.out.println();
> }
>
> void buildDataSource()
> {
> try
> {
> System.out.println("starting buildDataSource() method");
> ScriptDataSourceHandle dsHandle =
> designFactory.newScriptDataSource("Data Source");
>
> designHandle.getDataSources().add(dsHandle);
> }catch(Exception e)
> {
> e.printStackTrace();
> }
>
> System.out.println("Finished buildDataSource() Method");
> System.out.println("");
> }
>
> void buildDataSet(IChart dataProvider)
> {
> try
> {
> System.out.println("starting buildDataSet() method");
>
> ScriptDataSetHandle dsHandle = designFactory.newScriptDataSet("ds");
> dsHandle.setDataSource("Data Source");
>
> dsHandle.setOpen("data = dataProvider.getyValues(); \n" +
> "data2 = dataProvider.getxValues(); \n " +
> "totalrows = data.size(); \n" +
> "currentrow = 1;\n");
>
> dsHandle.setFetch("if(currentrow >= totalrows) \n" +
> "{return(false);} \n" +
> "var favrow = data.get(currentrow); \n" +
> "row[\"abc0\"] = favrow; \n"+
> "var favrow2 = data2.get(currentrow); \n" +
> "row[\"cba0\"] = favrow2 \n;"+
> "currentrow = currentrow + 1; \n" +
> "return(true); \n");
>
> dsHandle.setClose("data = null; \n data2 = null; \n");
>
> PropertyHandle computedSet =
> dsHandle.getPropertyHandle(ScriptDataSetHandle.RESULT_SET_PR OP);
> ResultSetColumn resultColumn =
> StructureFactory.createResultSetColumn();
>
> resultColumn = StructureFactory.createResultSetColumn();
> resultColumn.setPosition(1);
> resultColumn.setColumnName("abc0");
> resultColumn.setDataType(COLUMN_DATA_TYPE_FLOAT);
> computedSet.addItem(resultColumn);
>
> resultColumn = StructureFactory.createResultSetColumn();
> resultColumn.setPosition(2);
> resultColumn.setColumnName("cba0");
> resultColumn.setDataType(COLUMN_DATA_TYPE_STRING);
> computedSet.addItem(resultColumn);
>
> designHandle.getDataSets().add(dsHandle);
>
> System.out.println("Finished buildDataSet() method");
> System.out.println("");
> }catch(Exception e)
> {
> e.printStackTrace();
> }
> }
>
> void stopSavePlatform()
> {
> try
> {
> System.out.println("starting stopSavePlatform() method");
>
> /*save file*/
> designHandle.saveAs(output_path + "/" + filename + ".rptdesign");
> designHandle.close();
>
> Platform.shutdown();
> }catch(Exception e)
> {
> e.printStackTrace();
> }
> System.out.println("Finished stopSavePlatform() method");
> System.out.println("");
> }
>
> void buildBasicReport()
> {
> try
> {
> System.out.println("starting buildBasicReport method");
> DesignElementHandle element = designFactory.newSimpleMasterPage("Page
> Master");
> designHandle.getMasterPages().add(element);
>
> /*table with 2 columns, 1 row*/
> GridHandle grid = designFactory.newGridItem(null, 2, 1);
> designHandle.getBody().add(grid);
>
> //Kopf soll
|
|
| | | |
Goto Forum:
Current Time: Fri Mar 21 14:26:19 EDT 2025
Powered by FUDForum. Page generated in 0.08401 seconds
|