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.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 36 public class GroupOnXSeries 37 { 38 39 44 public static void main( String [] args ) 45 { 46 new GroupOnXSeries( ).groupSeries( ); 47 48 } 49 50 57 void groupSeries( ) 58 { 59 SessionHandle sessionHandle = new DesignEngine( null ).newSessionHandle( (ULocale) null ); 60 ReportDesignHandle designHandle = null; 61 62 String path = "src/org/eclipse/birt/chart/examples/api/data/"; 64 try 65 { 66 designHandle = sessionHandle.openDesign( path 67 + "NonGroupOnXSeries.rptdesign" ); } 69 catch ( DesignFileException e ) 70 { 71 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" ); } 83 catch ( ExtendedElementException e ) 84 { 85 e.printStackTrace( ); 87 } 88 89 cm.getTitle( ).getLabel( ).getCaption( ).setValue( "Group On X Series" ); 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" ); sdX.getGrouping( ).setGroupType( DataType.NUMERIC_LITERAL ); 98 sdX.getGrouping( ).setGroupingInterval( 1 ); 99 100 try 101 { 102 designHandle.saveAs( path + "GroupOnXSeries.rptdesign" ); } 104 catch ( IOException e ) 105 { 106 e.printStackTrace( ); 107 } 108 109 } 110 111 } 112 | Popular Tags |