1 11 package org.eclipse.birt.chart.examples.api.preference; 12 13 14 import org.eclipse.birt.chart.model.Chart; 15 import org.eclipse.birt.chart.model.ChartWithAxes; 16 import org.eclipse.birt.chart.model.attribute.AxisType; 17 import org.eclipse.birt.chart.model.attribute.LegendItemType; 18 import org.eclipse.birt.chart.model.attribute.Position; 19 import org.eclipse.birt.chart.model.attribute.TickStyle; 20 import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl; 21 import org.eclipse.birt.chart.model.component.Axis; 22 import org.eclipse.birt.chart.model.component.Series; 23 import org.eclipse.birt.chart.model.component.impl.SeriesImpl; 24 import org.eclipse.birt.chart.model.data.NumberDataSet; 25 import org.eclipse.birt.chart.model.data.SeriesDefinition; 26 import org.eclipse.birt.chart.model.data.TextDataSet; 27 import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl; 28 import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl; 29 import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl; 30 import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl; 31 import org.eclipse.birt.chart.model.layout.Legend; 32 import org.eclipse.birt.chart.model.layout.Plot; 33 import org.eclipse.birt.chart.model.type.BarSeries; 34 import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl; 35 36 public class ChartModels 37 { 38 39 45 protected static Chart createBarChart( ) 46 { 47 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 48 49 cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) ); 51 cwaBar.getBlock( ).getOutline( ).setVisible( true ); 52 Plot p = cwaBar.getPlot( ); 53 p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255, 54 255, 55 225 ) ); 56 p.getOutline( ).setVisible( false ); 57 58 cwaBar.getTitle( ).getLabel( ).getCaption( ).setValue( "Bar Chart" ); 61 Legend lg = cwaBar.getLegend( ); 63 lg.setItemType( LegendItemType.CATEGORIES_LITERAL ); 64 65 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 67 68 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 69 xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL ); 70 xAxisPrimary.getTitle( ).setVisible( true ); 71 72 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 74 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 75 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 76 yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 ); 77 78 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 80 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 82 25, 35, 15 83 } ); 84 85 Series seCategory = SeriesImpl.create( ); 87 seCategory.setDataSet( categoryValues ); 88 89 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 90 sdX.getSeriesPalette( ).update( 0 ); 91 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 92 sdX.getSeries( ).add( seCategory ); 93 94 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 96 bs.setDataSet( orthoValues ); 97 bs.setRiserOutline( null ); 98 bs.getLabel( ).setVisible( true ); 99 bs.setLabelPosition( Position.INSIDE_LITERAL ); 100 101 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 102 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 103 sdY.getSeries( ).add( bs ); 104 105 return cwaBar; 106 } 107 } 108 | Popular Tags |