1 11 12 package org.eclipse.birt.chart.examples.api.data; 13 14 import java.io.IOException ; 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 38 public class GroupOnYAxis 39 { 40 41 46 public static void main( String [] args ) 47 { 48 new GroupOnYAxis( ).groupKey( ); 49 50 } 51 52 58 void groupKey( ) 59 { 60 SessionHandle sessionHandle = new DesignEngine( null ).newSessionHandle( (ULocale) null ); 61 ReportDesignHandle designHandle = null; 62 63 String path = "src/org/eclipse/birt/chart/examples/api/data/"; 65 try 66 { 67 designHandle = sessionHandle.openDesign( path 68 + "NonGroupOnYAxis.rptdesign" ); } 70 catch ( DesignFileException e ) 71 { 72 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" ); } 84 catch ( ExtendedElementException e ) 85 { 86 e.printStackTrace( ); 88 } 89 cm.getTitle( ).getLabel( ).getCaption( ).setValue( "Group On Y Axis" ); 91 Axis axisBase = (Axis) ( (ChartWithAxes) cm ).getAxes( ).get( 0 ); Axis axisOrth = (Axis) axisBase.getAssociatedAxes( ).get( 0 ); SeriesDefinition sdY = (SeriesDefinition) axisOrth 94 .getSeriesDefinitions( ).get( 0 ); 96 SeriesDefinition sdGroup = SeriesDefinitionImpl.create( ); 97 Query query = QueryImpl.create( "row[\"Month\"]" ); sdGroup.setQuery( query ); 99 100 axisOrth.getSeriesDefinitions( ).clear( ); axisOrth.getSeriesDefinitions( ).add( 0, sdGroup ); 103 sdGroup.getSeries( ).add( sdY.getSeries( ).get( 0 ) ); 104 105 try 106 { 107 designHandle.saveAs( path + "GroupOnYAxis.rptdesign" ); } 109 catch ( IOException e ) 110 { 111 e.printStackTrace( ); 112 } 113 114 } 115 116 } 117 | Popular Tags |