KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > report > api > SalesReport


1 /*******************************************************************************
2  * Copyright (c) 2004 Actuate Corporation. All rights reserved. This program and
3  * the accompanying materials are made available under the terms of the Eclipse
4  * Public License v1.0 which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors: Actuate Corporation - initial API and implementation
8  ******************************************************************************/

9
10 package org.eclipse.birt.chart.examples.report.api;
11
12 import java.io.BufferedInputStream JavaDoc;
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16
17 import org.eclipse.birt.chart.model.ChartWithoutAxes;
18 import org.eclipse.birt.chart.model.attribute.DataPointComponent;
19 import org.eclipse.birt.chart.model.attribute.DataPointComponentType;
20 import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
21 import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
22 import org.eclipse.birt.chart.model.attribute.impl.DataPointComponentImpl;
23 import org.eclipse.birt.chart.model.attribute.impl.GradientImpl;
24 import org.eclipse.birt.chart.model.attribute.impl.JavaNumberFormatSpecifierImpl;
25 import org.eclipse.birt.chart.model.component.Series;
26 import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
27 import org.eclipse.birt.chart.model.data.BaseSampleData;
28 import org.eclipse.birt.chart.model.data.DataFactory;
29 import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
30 import org.eclipse.birt.chart.model.data.Query;
31 import org.eclipse.birt.chart.model.data.SampleData;
32 import org.eclipse.birt.chart.model.data.SeriesDefinition;
33 import org.eclipse.birt.chart.model.data.impl.QueryImpl;
34 import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
35 import org.eclipse.birt.chart.model.impl.ChartWithoutAxesImpl;
36 import org.eclipse.birt.chart.model.type.PieSeries;
37 import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
38 import org.eclipse.birt.report.model.api.CellHandle;
39 import org.eclipse.birt.report.model.api.DataItemHandle;
40 import org.eclipse.birt.report.model.api.DesignElementHandle;
41 import org.eclipse.birt.report.model.api.DesignEngine;
42 import org.eclipse.birt.report.model.api.ElementFactory;
43 import org.eclipse.birt.report.model.api.ExtendedItemHandle;
44 import org.eclipse.birt.report.model.api.GridHandle;
45 import org.eclipse.birt.report.model.api.ImageHandle;
46 import org.eclipse.birt.report.model.api.LabelHandle;
47 import org.eclipse.birt.report.model.api.PropertyHandle;
48 import org.eclipse.birt.report.model.api.ReportDesignHandle;
49 import org.eclipse.birt.report.model.api.RowHandle;
50 import org.eclipse.birt.report.model.api.ScriptDataSetHandle;
51 import org.eclipse.birt.report.model.api.ScriptDataSourceHandle;
52 import org.eclipse.birt.report.model.api.SessionHandle;
53 import org.eclipse.birt.report.model.api.StructureFactory;
54 import org.eclipse.birt.report.model.api.StyleHandle;
55 import org.eclipse.birt.report.model.api.TableGroupHandle;
56 import org.eclipse.birt.report.model.api.TableHandle;
57 import org.eclipse.birt.report.model.api.activity.SemanticException;
58 import org.eclipse.birt.report.model.api.command.ContentException;
59 import org.eclipse.birt.report.model.api.command.NameException;
60 import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
61 import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
62 import org.eclipse.birt.report.model.api.elements.structures.EmbeddedImage;
63 import org.eclipse.birt.report.model.api.elements.structures.SortKey;
64 import org.eclipse.birt.report.model.api.extension.ExtendedElementException;
65 import org.eclipse.birt.report.model.api.metadata.IMetaDataDictionary;
66
67 import com.ibm.icu.util.ULocale;
68
69 public class SalesReport
70 {
71
72     ReportDesignHandle reportDesignHandle = null;
73
74     ElementFactory elementFactory = null;
75
76     IMetaDataDictionary dict = null;
77
78     ComputedColumn cs1, cs2, cs3 = null;
79
80     public static void main( String JavaDoc[] args ) throws SemanticException,
81             IOException JavaDoc
82     {
83         new SalesReport( ).createReport( );
84     }
85
86     void createReport( ) throws SemanticException, IOException JavaDoc
87     {
88         // A session handle for all open reports
89
SessionHandle session = new DesignEngine( null ).newSessionHandle( (ULocale) null );
90
91         // Create a new report
92
reportDesignHandle = session.createDesign( );
93
94         // Element factory is used to create instances of BIRT elements.
95
elementFactory = reportDesignHandle.getElementFactory( );
96
97         dict = new DesignEngine( null ).getMetaData( );
98
99         createMasterPages( );
100         createDataSources( );
101         createDataSets( );
102         createStyles( );
103         createBody( );
104
105         String JavaDoc outputPath = "output";//$NON-NLS-1$
106
File JavaDoc outputFolder = new File JavaDoc( outputPath );
107         if ( !outputFolder.exists( ) && !outputFolder.mkdir( ) )
108         {
109             throw new IOException JavaDoc( "Can not create the output folder" );//$NON-NLS-1$
110
}
111         reportDesignHandle.saveAs( outputPath + "/" + "SalesReport.rptdesign" );//$NON-NLS-1$//$NON-NLS-2$
112
}
113
114     private void createDataSources( ) throws SemanticException
115     {
116         ScriptDataSourceHandle dataSourceHandle = elementFactory.newScriptDataSource( "Data Source" );//$NON-NLS-1$
117
reportDesignHandle.getDataSources( ).add( dataSourceHandle );
118     }
119
120     private void createDataSets( ) throws SemanticException
121     {
122         // Data Set
123
ScriptDataSetHandle dataSetHandle = elementFactory.newScriptDataSet( "Data Set" );//$NON-NLS-1$
124
dataSetHandle.setDataSource( "Data Source" );//$NON-NLS-1$
125

126         // Set open( ) in code
127
dataSetHandle.setOpen( "i=0;"//$NON-NLS-1$
128
+ "sourcedata = new Array( new Array(3), new Array(3), new Array(3), "//$NON-NLS-1$
129
+ "new Array(3), new Array(3), new Array(3));"//$NON-NLS-1$
130
+ "sourcedata[0][0] = 10; "//$NON-NLS-1$
131
+ "sourcedata[0][1] = \"Chris Kwai\";"//$NON-NLS-1$
132
+ "sourcedata[0][2] = 2413;"//$NON-NLS-1$
133

134                 + "sourcedata[1][0] = 10; "//$NON-NLS-1$
135
+ "sourcedata[1][1] = \"Ice Bella\";"//$NON-NLS-1$
136
+ "sourcedata[1][2] = 2304;"//$NON-NLS-1$
137

138                 + "sourcedata[2][0] = 10; "//$NON-NLS-1$
139
+ "sourcedata[2][1] = \"Nola Dicci\";"//$NON-NLS-1$
140
+ "sourcedata[2][2] = 1998;"//$NON-NLS-1$
141

142                 + "sourcedata[3][0] = 11; "//$NON-NLS-1$
143
+ "sourcedata[3][1] = \"Chris Kwai\";"//$NON-NLS-1$
144
+ "sourcedata[3][2] = 2087;"//$NON-NLS-1$
145

146                 + "sourcedata[4][0] = 11; "//$NON-NLS-1$
147
+ "sourcedata[4][1] = \"Ice Bella\";"//$NON-NLS-1$
148
+ "sourcedata[4][2] = 2502;"//$NON-NLS-1$
149

150                 + "sourcedata[5][0] = 11; "//$NON-NLS-1$
151
+ "sourcedata[5][1] = \"Nola Dicci\";"//$NON-NLS-1$
152
+ "sourcedata[5][2] = 2011;" );//$NON-NLS-1$
153

154         // Set fetch( ) in code
155
dataSetHandle.setFetch( "if ( i < 6 ){"//$NON-NLS-1$
156
+ "row[\"Month\"] = sourcedata[i][0];"//$NON-NLS-1$
157
+ "row[\"Product\"] = sourcedata[i][1];"//$NON-NLS-1$
158
+ "row[\"Amount\"] = sourcedata[i][2];"//$NON-NLS-1$
159
+ "i++;"//$NON-NLS-1$
160
+ "return true;}" + "else return false;" );//$NON-NLS-1$//$NON-NLS-2$
161

162         // Set computed columns
163
cs1 = StructureFactory.createComputedColumn( );
164         cs1.setName( "Month" );//$NON-NLS-1$
165
cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$
166
cs1.setDataType( "integer" );//$NON-NLS-1$
167

168         cs2 = StructureFactory.createComputedColumn( );
169         cs2.setName( "Product" );//$NON-NLS-1$
170
cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$
171
cs2.setDataType( "string" );//$NON-NLS-1$
172

173         cs3 = StructureFactory.createComputedColumn( );
174         cs3.setName( "Amount" );//$NON-NLS-1$
175
cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
176
cs3.setDataType( "integer" );//$NON-NLS-1$
177

178         PropertyHandle computedSet = dataSetHandle.getPropertyHandle( ScriptDataSetHandle.COMPUTED_COLUMNS_PROP );
179         computedSet.addItem( cs1 );
180         computedSet.addItem( cs2 );
181         computedSet.addItem( cs3 );
182
183         reportDesignHandle.getDataSets( ).add( dataSetHandle );
184     }
185
186     private void createMasterPages( ) throws ContentException, NameException
187     {
188         DesignElementHandle simpleMasterPage = elementFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
189
reportDesignHandle.getMasterPages( ).add( simpleMasterPage );
190     }
191
192     private void createStyles( ) throws SemanticException
193     {
194         StyleHandle labelStyle = elementFactory.newStyle( "Label" );//$NON-NLS-1$
195
labelStyle.setProperty( StyleHandle.FONT_WEIGHT_PROP,
196                 DesignChoiceConstants.FONT_WEIGHT_BOLD );
197         labelStyle.setProperty( StyleHandle.FONT_FAMILY_PROP, "Arial Black" );//$NON-NLS-1$
198
labelStyle.setProperty( StyleHandle.COLOR_PROP, "#008000" );//$NON-NLS-1$
199

200         StyleHandle dataStyle = elementFactory.newStyle( "Data" );//$NON-NLS-1$
201
dataStyle.setProperty( StyleHandle.FONT_WEIGHT_PROP,
202                 DesignChoiceConstants.FONT_WEIGHT_BOLD );
203         dataStyle.setProperty( StyleHandle.FONT_FAMILY_PROP, "Century" );//$NON-NLS-1$
204
dataStyle.setProperty( StyleHandle.COLOR_PROP, "#009B9B" );//$NON-NLS-1$
205

206         reportDesignHandle.getStyles( ).add( labelStyle );
207         reportDesignHandle.getStyles( ).add( dataStyle );
208     }
209
210     private byte[] load( String JavaDoc fileName ) throws IOException JavaDoc
211     {
212         InputStream JavaDoc is = null;
213
214         is = new BufferedInputStream JavaDoc( this.getClass( )
215                 .getResourceAsStream( fileName ) );
216         byte data[] = null;
217         if ( is != null )
218         {
219             try
220             {
221                 data = new byte[is.available( )];
222                 is.read( data );
223             }
224             catch ( IOException JavaDoc e1 )
225             {
226                 throw e1;
227             }
228         }
229         return data;
230     }
231
232     private void createBody( ) throws SemanticException
233     {
234
235         // Grid 1
236
GridHandle grid1 = elementFactory.newGridItem( "grid1", 3, 1 );//$NON-NLS-1$
237
grid1.setWidth( "100%" );//$NON-NLS-1$
238
reportDesignHandle.getBody( ).add( grid1 );
239
240         // First Grid Row
241
RowHandle row = (RowHandle) grid1.getRows( ).get( 0 );
242
243         // Cell (1st Row)
244
CellHandle cell = (CellHandle) row.getCells( ).get( 0 );
245         cell.setProperty( StyleHandle.TEXT_ALIGN_PROP,
246                 DesignChoiceConstants.TEXT_ALIGN_CENTER );
247         try
248         {
249             EmbeddedImage image1 = StructureFactory.createEmbeddedImage( );
250             image1.setType( DesignChoiceConstants.IMAGE_TYPE_IMAGE_JPEG );
251             image1.setData( load( "logo1.jpg" ) );//$NON-NLS-1$
252
image1.setName( "logo1" );//$NON-NLS-1$
253
reportDesignHandle.addImage( image1 );
254             ImageHandle imageHandle = elementFactory.newImage( "handle" );//$NON-NLS-1$
255
imageHandle.setSource( DesignChoiceConstants.IMAGE_REF_TYPE_EMBED );
256             imageHandle.setImageName( "logo1" );//$NON-NLS-1$
257
cell.getContent( ).add( imageHandle );
258         }
259         catch ( IOException JavaDoc e )
260         {
261             e.printStackTrace( );
262         }
263
264         cell = (CellHandle) row.getCells( ).get( 1 );
265         cell.setProperty( StyleHandle.TEXT_ALIGN_PROP,
266                 DesignChoiceConstants.TEXT_ALIGN_CENTER );
267         try
268         {
269             EmbeddedImage image2 = StructureFactory.createEmbeddedImage( );
270             image2.setType( DesignChoiceConstants.IMAGE_TYPE_IMAGE_JPEG );
271             image2.setData( load( "logo2.jpg" ) );//$NON-NLS-1$
272
image2.setName( "logo2" );//$NON-NLS-1$
273
reportDesignHandle.addImage( image2 );
274             ImageHandle imageHandle2 = elementFactory.newImage( "imageHandle2" );//$NON-NLS-1$
275
imageHandle2.setSource( DesignChoiceConstants.IMAGE_REF_TYPE_EMBED );
276             imageHandle2.setImageName( "logo2" );//$NON-NLS-1$
277
cell.getContent( ).add( imageHandle2 );
278         }
279         catch ( IOException JavaDoc e )
280         {
281             e.printStackTrace( );
282         }
283
284         cell = (CellHandle) row.getCells( ).get( 2 );
285         cell.setProperty( StyleHandle.TEXT_ALIGN_PROP,
286                 DesignChoiceConstants.TEXT_ALIGN_CENTER );
287         try
288         {
289             EmbeddedImage image3 = StructureFactory.createEmbeddedImage( );
290             image3.setType( DesignChoiceConstants.IMAGE_TYPE_IMAGE_JPEG );
291             image3.setData( load( "logo3.jpg" ) );//$NON-NLS-1$
292
image3.setName( "logo3" );//$NON-NLS-1$
293
reportDesignHandle.addImage( image3 );
294             ImageHandle imageHandle3 = elementFactory.newImage( "imageHandle3" );//$NON-NLS-1$
295
imageHandle3.setSource( DesignChoiceConstants.IMAGE_REF_TYPE_EMBED );
296             imageHandle3.setImageName( "logo3" );//$NON-NLS-1$
297
cell.getContent( ).add( imageHandle3 );
298         }
299         catch ( IOException JavaDoc e )
300         {
301             e.printStackTrace( );
302         }
303
304         // Grid 2
305
GridHandle grid2 = elementFactory.newGridItem( "grid2", 2, 1 );//$NON-NLS-1$
306
grid2.setWidth( "100%" );//$NON-NLS-1$
307
reportDesignHandle.getBody( ).add( grid2 );
308
309         // First Grid Row
310
row = (RowHandle) grid2.getRows( ).get( 0 );
311
312         // Cell (1st Row)
313
cell = (CellHandle) row.getCells( ).get( 0 );
314         cell.setProperty( StyleHandle.TEXT_ALIGN_PROP,
315                 DesignChoiceConstants.TEXT_ALIGN_RIGHT );
316         cell.setProperty( StyleHandle.VERTICAL_ALIGN_PROP,
317                 DesignChoiceConstants.VERTICAL_ALIGN_MIDDLE );
318
319         TableHandle table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
320         table.setProperty( StyleHandle.TEXT_ALIGN_PROP,
321                 DesignChoiceConstants.TEXT_ALIGN_CENTER );
322         table.setWidth( "80%" );//$NON-NLS-1$
323
table.setProperty( TableHandle.DATA_SET_PROP, "Data Set" );//$NON-NLS-1$
324

325         PropertyHandle computedSet = table.getColumnBindings( );
326         cs1.setExpression( "dataSetRow[\"Month\"]" );//$NON-NLS-1$
327
computedSet.addItem( cs1 );
328         cs2.setExpression( "dataSetRow[\"Product\"]" );//$NON-NLS-1$
329
computedSet.addItem( cs2 );
330         cs3.setExpression( "dataSetRow[\"Amount\"]" );//$NON-NLS-1$
331
computedSet.addItem( cs3 );
332
333         // Table sorter
334
SortKey key = StructureFactory.createSortKey( );
335         key.setKey( "row[\"Month\"]" );//$NON-NLS-1$
336
key.setDirection( "asc" );//$NON-NLS-1$
337
PropertyHandle sort = table.getPropertyHandle( TableHandle.SORT_PROP );
338         sort.addItem( key );
339
340         // Header
341
RowHandle header = (RowHandle) table.getHeader( ).get( 0 );
342
343         CellHandle tcell = (CellHandle) header.getCells( ).get( 0 );
344         LabelHandle label = elementFactory.newLabel( null );
345         label.setText( "Product" );//$NON-NLS-1$
346
label.setStyleName( "Label" );//$NON-NLS-1$
347
tcell.getContent( ).add( label );
348
349         tcell = (CellHandle) header.getCells( ).get( 1 );
350         label = elementFactory.newLabel( null );
351         label.setText( "Month" );//$NON-NLS-1$
352
label.setStyleName( "Label" );//$NON-NLS-1$
353
tcell.getContent( ).add( label );
354
355         tcell = (CellHandle) header.getCells( ).get( 2 );
356         label = elementFactory.newLabel( null );
357         label.setText( "Amount" );//$NON-NLS-1$
358
label.setStyleName( "Label" );//$NON-NLS-1$
359
tcell.getContent( ).add( label );
360
361         // Table Group
362
TableGroupHandle group = elementFactory.newTableGroup( );
363         group.setKeyExpr( "row[\"Product\"]" );//$NON-NLS-1$
364
table.getGroups( ).add( group );
365
366         RowHandle groupHeader = elementFactory.newTableRow( 3 );
367         tcell = (CellHandle) groupHeader.getCells( ).get( 0 );
368         tcell.setDrop( DesignChoiceConstants.DROP_TYPE_DETAIL );
369         DataItemHandle data = elementFactory.newDataItem( null );
370         data.setStyleName( "Data" );//$NON-NLS-1$
371
data.setResultSetColumn( cs2.getName( ) );
372         tcell.getContent( ).add( data );
373         group.getHeader( ).add( groupHeader );
374
375         RowHandle groupFooter = elementFactory.newTableRow( 3 );
376         tcell = (CellHandle) groupFooter.getCells( ).get( 0 );
377         tcell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#FF8000" );//$NON-NLS-1$
378
tcell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP,
379                 DesignChoiceConstants.LINE_STYLE_SOLID );
380         tcell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP,
381                 DesignChoiceConstants.LINE_WIDTH_THIN );
382         tcell = (CellHandle) groupFooter.getCells( ).get( 1 );
383         tcell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#FF8000" );//$NON-NLS-1$
384
tcell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP,
385                 DesignChoiceConstants.LINE_STYLE_SOLID );
386         tcell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP,
387                 DesignChoiceConstants.LINE_WIDTH_THIN );
388         tcell = (CellHandle) groupFooter.getCells( ).get( 2 );
389         tcell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#FF8000" );//$NON-NLS-1$
390
tcell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP,
391                 DesignChoiceConstants.LINE_STYLE_SOLID );
392         tcell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP,
393                 DesignChoiceConstants.LINE_WIDTH_THIN );
394         group.getFooter( ).add( groupFooter );
395
396         // Detail
397
RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
398         tcell = (CellHandle) detail.getCells( ).get( 1 );
399         data = elementFactory.newDataItem( null );
400         data.setStyleName( "Data" );//$NON-NLS-1$
401
data.setResultSetColumn( cs1.getName( ) );
402         tcell.getContent( ).add( data );
403
404         tcell = (CellHandle) detail.getCells( ).get( 2 );
405         data = elementFactory.newDataItem( null );
406         data.setStyleName( "Data" );//$NON-NLS-1$
407
data.setResultSetColumn( cs3.getName( ) );
408         tcell.getContent( ).add( data );
409
410         cell.getContent( ).add( table );
411
412         cell = (CellHandle) row.getCells( ).get( 1 );
413         cell.setProperty( StyleHandle.TEXT_ALIGN_PROP,
414                 DesignChoiceConstants.TEXT_ALIGN_CENTER );
415         cell.getContent( ).add( createPieChart( ) );
416     }
417
418     private ExtendedItemHandle createPieChart( )
419     {
420         ExtendedItemHandle eih = elementFactory.newExtendedItem( null, "Chart" );//$NON-NLS-1$
421

422         try
423         {
424             eih.setHeight( "288pt" );//$NON-NLS-1$
425
eih.setWidth( "252pt" );//$NON-NLS-1$
426
eih.setProperty( ExtendedItemHandle.DATA_SET_PROP, "Data Set" );//$NON-NLS-1$
427
PropertyHandle computedSet = eih.getColumnBindings( );
428             cs1.setExpression( "dataSetRow[\"Month\"]" );//$NON-NLS-1$
429
computedSet.addItem( cs1 );
430             cs2.setExpression( "dataSetRow[\"Product\"]" );//$NON-NLS-1$
431
computedSet.addItem( cs2 );
432             cs3.setExpression( "dataSetRow[\"Amount\"]" );//$NON-NLS-1$
433
computedSet.addItem( cs3 );
434         }
435         catch ( SemanticException e )
436         {
437             e.printStackTrace( );
438         }
439
440         ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( );
441         cwoaPie.setType( "Pie Chart" );//$NON-NLS-1$
442
cwoaPie.setSubType( "Standard Pie Chart" );//$NON-NLS-1$
443
cwoaPie.getTitle( ).setVisible( false );
444         cwoaPie.getBlock( ).setBounds( BoundsImpl.create( 0, 0, 252, 288 ) );
445         cwoaPie.getBlock( ).getOutline( ).setVisible( true );
446         cwoaPie.getBlock( )
447                 .setBackground( GradientImpl.create( ColorDefinitionImpl.create( 204,
448                         254,
449                         204 ),
450                         ColorDefinitionImpl.create( 254, 226, 240 ),
451                         -35,
452                         false ) );
453         cwoaPie.getPlot( )
454                 .getClientArea( )
455                 .setBackground( ColorDefinitionImpl.TRANSPARENT( ) );
456         cwoaPie.getLegend( ).setBackground( ColorDefinitionImpl.TRANSPARENT( ) );
457         cwoaPie.getLegend( )
458                 .getClientArea( )
459                 .setBackground( ColorDefinitionImpl.TRANSPARENT( ) );
460
461         SampleData sd = DataFactory.eINSTANCE.createSampleData( );
462         BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
463         sdBase.setDataSetRepresentation( "Category-A, Category-B" );//$NON-NLS-1$
464
sd.getBaseSampleData( ).add( sdBase );
465
466         OrthogonalSampleData sdOrthogonal = DataFactory.eINSTANCE.createOrthogonalSampleData( );
467         sdOrthogonal.setDataSetRepresentation( "4,12" );//$NON-NLS-1$
468
sdOrthogonal.setSeriesDefinitionIndex( 0 );
469         sd.getOrthogonalSampleData( ).add( sdOrthogonal );
470
471         cwoaPie.setSampleData( sd );
472
473         Series seCategory = SeriesImpl.create( );
474         Query query = QueryImpl.create( "row[\"Product\"]" );//$NON-NLS-1$
475
seCategory.getDataDefinition( ).add( query );
476
477         SeriesDefinition series = SeriesDefinitionImpl.create( );
478         series.getSeries( ).add( seCategory );
479         cwoaPie.getSeriesDefinitions( ).add( series );
480
481         PieSeries ps = (PieSeries) PieSeriesImpl.create( );
482         Query query2 = QueryImpl.create( "row[\"Amount\"]" );//$NON-NLS-1$
483
ps.getDataDefinition( ).add( query2 );
484
485         SeriesDefinition seGroup = SeriesDefinitionImpl.create( );
486         Query query1 = QueryImpl.create( "row[\"Month\"]" );//$NON-NLS-1$
487
seGroup.setQuery( query1 );
488         series.getSeriesPalette( ).update( -2 );
489         series.getSeriesDefinitions( ).add( seGroup );
490         seGroup.getSeries( ).add( ps );
491
492         DataPointComponent dpc = DataPointComponentImpl.create( DataPointComponentType.ORTHOGONAL_VALUE_LITERAL,
493                 JavaNumberFormatSpecifierImpl.create( "###,###" ) );//$NON-NLS-1$
494
ps.getDataPoint( ).getComponents( ).clear( );
495         ps.getDataPoint( ).getComponents( ).add( dpc );
496         ps.getLabel( ).setVisible( true );
497
498         try
499         {
500             //Add chart instance to IReportItem
501
eih.getReportItem( ).setProperty( "chart.instance", cwoaPie );//$NON-NLS-1$
502
}
503         catch ( ExtendedElementException e )
504         {
505             e.printStackTrace( );
506         }
507
508         return eih;
509     }
510 }
Popular Tags