KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > data > GroupOnXSeries


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

11
12 package org.eclipse.birt.chart.examples.api.data;
13
14 import java.io.IOException JavaDoc;
15
16 import org.eclipse.birt.chart.model.Chart;
17 import org.eclipse.birt.chart.model.ChartWithAxes;
18 import org.eclipse.birt.chart.model.attribute.DataType;
19 import org.eclipse.birt.chart.model.attribute.SortOption;
20 import org.eclipse.birt.chart.model.component.Axis;
21 import org.eclipse.birt.chart.model.data.SeriesDefinition;
22 import org.eclipse.birt.report.model.api.DesignEngine;
23 import org.eclipse.birt.report.model.api.DesignFileException;
24 import org.eclipse.birt.report.model.api.ExtendedItemHandle;
25 import org.eclipse.birt.report.model.api.ReportDesignHandle;
26 import org.eclipse.birt.report.model.api.SessionHandle;
27 import org.eclipse.birt.report.model.api.extension.ExtendedElementException;
28
29 import com.ibm.icu.util.ULocale;
30
31 /**
32  * Presents a bar chart with grouping on X series, which could be acheived in
33  * the report designer as follows: Chart Builder -> Data -> X Series -> Set Dat
34  * Sorting / Tick Grouping Enabled
35  */

36 public class GroupOnXSeries
37 {
38
39     /**
40      * execute application
41      *
42      * @param args
43      */

44     public static void main( String JavaDoc[] args )
45     {
46         new GroupOnXSeries( ).groupSeries( );
47
48     }
49
50     /**
51      * Get the chart instance from the design file and group X series of the
52      * chart.
53      *
54      * @return An instance of the simulated runtime chart model (containing
55      * filled datasets)
56      */

57     void groupSeries( )
58     {
59         SessionHandle sessionHandle = new DesignEngine( null ).newSessionHandle( (ULocale) null );
60         ReportDesignHandle designHandle = null;
61
62         String JavaDoc path = "src/org/eclipse/birt/chart/examples/api/data/";//$NON-NLS-1$
63

64         try
65         {
66             designHandle = sessionHandle.openDesign( path
67                     + "NonGroupOnXSeries.rptdesign" );//$NON-NLS-1$
68
}
69         catch ( DesignFileException e )
70         {
71             // TODO Auto-generated catch block
72
e.printStackTrace( );
73         }
74
75         ExtendedItemHandle eih = (ExtendedItemHandle) designHandle.getBody( )
76                 .getContents( ).get( 0 );
77
78         Chart cm = null;
79         try
80         {
81             cm = (Chart) eih.getReportItem( ).getProperty( "chart.instance" ); //$NON-NLS-1$
82
}
83         catch ( ExtendedElementException e )
84         {
85             // TODO Auto-generated catch block
86
e.printStackTrace( );
87         }
88         
89         cm.getTitle( ).getLabel( ).getCaption( ).setValue( "Group On X Series" );//$NON-NLS-1$
90

91         SeriesDefinition sdX = (SeriesDefinition) ( (Axis) ( (ChartWithAxes) cm )
92                 .getAxes( ).get( 0 ) ).getSeriesDefinitions( ).get( 0 );
93
94         sdX.setSorting( SortOption.ASCENDING_LITERAL );
95         sdX.getGrouping( ).setEnabled( true );
96         sdX.getGrouping( ).setAggregateExpression( "Sum" );//$NON-NLS-1$
97
sdX.getGrouping( ).setGroupType( DataType.NUMERIC_LITERAL );
98         sdX.getGrouping( ).setGroupingInterval( 1 );
99
100         try
101         {
102             designHandle.saveAs( path + "GroupOnXSeries.rptdesign" );//$NON-NLS-1$
103
}
104         catch ( IOException JavaDoc e )
105         {
106             e.printStackTrace( );
107         }
108
109     }
110
111 }
112
Popular Tags