KickJava   Java API By Example, From Geeks To Geeks.

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


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.component.Axis;
19 import org.eclipse.birt.chart.model.data.Query;
20 import org.eclipse.birt.chart.model.data.SeriesDefinition;
21 import org.eclipse.birt.chart.model.data.impl.QueryImpl;
22 import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
23 import org.eclipse.birt.report.model.api.DesignEngine;
24 import org.eclipse.birt.report.model.api.DesignFileException;
25 import org.eclipse.birt.report.model.api.ExtendedItemHandle;
26 import org.eclipse.birt.report.model.api.ReportDesignHandle;
27 import org.eclipse.birt.report.model.api.SessionHandle;
28 import org.eclipse.birt.report.model.api.extension.ExtendedElementException;
29
30 import com.ibm.icu.util.ULocale;
31
32 /**
33  * Presents a bar chart with mulitple Y series, which could be acheived in the
34  * report designer as follows: Chart Builder -> Data -> Y Axis -> Set: Series
35  * Grouping Key
36  *
37  */

38 public class GroupOnYAxis
39 {
40
41     /**
42      * execute application
43      *
44      * @param args
45      */

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

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

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

91         Axis axisBase = (Axis) ( (ChartWithAxes) cm ).getAxes( ).get( 0 ); // X-Axis
92
Axis axisOrth = (Axis) axisBase.getAssociatedAxes( ).get( 0 ); // Y-Axis
93
SeriesDefinition sdY = (SeriesDefinition) axisOrth
94                 .getSeriesDefinitions( ).get( 0 ); // Y-Series
95

96         SeriesDefinition sdGroup = SeriesDefinitionImpl.create( );
97         Query query = QueryImpl.create( "row[\"Month\"]" );//$NON-NLS-1$
98
sdGroup.setQuery( query );
99
100         axisOrth.getSeriesDefinitions( ).clear( ); // Clear the original
101
// Y-Series (sdY)
102
axisOrth.getSeriesDefinitions( ).add( 0, sdGroup );
103         sdGroup.getSeries( ).add( sdY.getSeries( ).get( 0 ) );
104
105         try
106         {
107             designHandle.saveAs( path + "GroupOnYAxis.rptdesign" );//$NON-NLS-1$
108
}
109         catch ( IOException JavaDoc e )
110         {
111             e.printStackTrace( );
112         }
113
114     }
115
116 }
117
Popular Tags