1 11 12 package org.eclipse.birt.chart.examples.api.interactivity; 13 14 import java.util.ArrayList ; 15 import java.util.Vector ; 16 import org.eclipse.birt.chart.model.Chart; 17 import org.eclipse.birt.chart.model.ChartWithAxes; 18 import org.eclipse.birt.chart.model.ChartWithoutAxes; 19 import org.eclipse.birt.chart.model.attribute.ActionType; 20 import org.eclipse.birt.chart.model.attribute.Anchor; 21 import org.eclipse.birt.chart.model.attribute.AxisType; 22 import org.eclipse.birt.chart.model.attribute.DataPoint; 23 import org.eclipse.birt.chart.model.attribute.DataPointComponentType; 24 import org.eclipse.birt.chart.model.attribute.IntersectionType; 25 import org.eclipse.birt.chart.model.attribute.LegendBehaviorType; 26 import org.eclipse.birt.chart.model.attribute.LegendItemType; 27 import org.eclipse.birt.chart.model.attribute.LineAttributes; 28 import org.eclipse.birt.chart.model.attribute.LineStyle; 29 import org.eclipse.birt.chart.model.attribute.Marker; 30 import org.eclipse.birt.chart.model.attribute.MarkerType; 31 import org.eclipse.birt.chart.model.attribute.Position; 32 import org.eclipse.birt.chart.model.attribute.TickStyle; 33 import org.eclipse.birt.chart.model.attribute.TriggerCondition; 34 import org.eclipse.birt.chart.model.attribute.impl.CallBackValueImpl; 35 import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl; 36 import org.eclipse.birt.chart.model.attribute.impl.DataPointComponentImpl; 37 import org.eclipse.birt.chart.model.attribute.impl.JavaNumberFormatSpecifierImpl; 38 import org.eclipse.birt.chart.model.attribute.impl.SeriesValueImpl; 39 import org.eclipse.birt.chart.model.attribute.impl.TooltipValueImpl; 40 import org.eclipse.birt.chart.model.attribute.impl.URLValueImpl; 41 import org.eclipse.birt.chart.model.component.Axis; 42 import org.eclipse.birt.chart.model.component.Series; 43 import org.eclipse.birt.chart.model.component.impl.SeriesImpl; 44 import org.eclipse.birt.chart.model.data.NumberDataSet; 45 import org.eclipse.birt.chart.model.data.SeriesDefinition; 46 import org.eclipse.birt.chart.model.data.TextDataSet; 47 import org.eclipse.birt.chart.model.data.Trigger; 48 import org.eclipse.birt.chart.model.data.impl.ActionImpl; 49 import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl; 50 import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl; 51 import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl; 52 import org.eclipse.birt.chart.model.data.impl.TriggerImpl; 53 import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl; 54 import org.eclipse.birt.chart.model.impl.ChartWithoutAxesImpl; 55 import org.eclipse.birt.chart.model.layout.Legend; 56 import org.eclipse.birt.chart.model.layout.Plot; 57 import org.eclipse.birt.chart.model.type.BarSeries; 58 import org.eclipse.birt.chart.model.type.LineSeries; 59 import org.eclipse.birt.chart.model.type.PieSeries; 60 import org.eclipse.birt.chart.model.type.ScatterSeries; 61 import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl; 62 import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl; 63 import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl; 64 import org.eclipse.birt.chart.model.type.impl.ScatterSeriesImpl; 65 66 public class InteractivityCharts 67 { 68 protected static final Chart createHSChart( ) 69 { 70 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 71 cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) ); 72 cwaBar.getInteractivity( ) 73 .setLegendBehavior( LegendBehaviorType.HIGHLIGHT_SERIE_LITERAL ); 74 Plot p = cwaBar.getPlot( ); 75 p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255, 76 255, 77 225 ) ); 78 cwaBar.getTitle( ) 79 .getLabel( ) 80 .getCaption( ) 81 .setValue( "Click \"Items\" to Highlight Seires" ); cwaBar.setUnitSpacing( 20 ); 83 84 Legend lg = cwaBar.getLegend( ); 85 LineAttributes lia = lg.getOutline( ); 86 lg.getText( ).getFont( ).setSize( 16 ); 87 lia.setStyle( LineStyle.SOLID_LITERAL ); 88 lg.getInsets( ).set( 10, 5, 0, 0 ); 89 lg.getOutline( ).setVisible( false ); 90 lg.setAnchor( Anchor.NORTH_LITERAL ); 91 lg.setItemType( LegendItemType.CATEGORIES_LITERAL ); 92 93 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 95 96 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 97 xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL ); 98 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 99 xAxisPrimary.getTitle( ).setVisible( true ); 100 101 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 103 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 104 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 105 yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 ); 106 107 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 109 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 111 25, 35, 15 112 } ); 113 114 Series seCategory = SeriesImpl.create( ); 116 seCategory.setDataSet( categoryValues ); 117 118 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 119 sdX.getSeriesPalette( ).update( 0 ); 120 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 121 sdX.getSeries( ).add( seCategory ); 122 123 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 125 bs.setDataSet( orthoValues ); 126 bs.setRiserOutline( null ); 127 bs.setSeriesIdentifier( "Highlight" ); bs.getLabel( ).setVisible( true ); 129 bs.setLabelPosition( Position.INSIDE_LITERAL ); 130 bs.getTriggers( ) 131 .add( TriggerImpl.create( TriggerCondition.ONCLICK_LITERAL, 132 ActionImpl.create( ActionType.HIGHLIGHT_LITERAL, 133 SeriesValueImpl.create( String.valueOf( bs.getSeriesIdentifier( ) ) ) ) ) ); 134 135 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 136 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 137 sdY.getSeries( ).add( bs ); 138 139 return cwaBar; 140 } 141 142 protected static final Chart createSTChart( ) 143 { 144 ChartWithAxes cwaScatter = ChartWithAxesImpl.create( ); 145 146 cwaScatter.getTitle( ) 148 .getLabel( ) 149 .getCaption( ) 150 .setValue( "Mouse over the Data Points to Show Tooltips" ); cwaScatter.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) ); 152 153 cwaScatter.getPlot( ).getClientArea( ).getOutline( ).setVisible( false ); 155 cwaScatter.getPlot( ) 156 .getClientArea( ) 157 .setBackground( ColorDefinitionImpl.create( 255, 255, 225 ) ); 158 159 Axis xAxisPrimary = ( (ChartWithAxesImpl) cwaScatter ).getPrimaryBaseAxes( )[0]; 161 xAxisPrimary.getTitle( ).setVisible( false ); 162 163 xAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 164 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 165 xAxisPrimary.getLabel( ) 166 .getCaption( ) 167 .setColor( ColorDefinitionImpl.GREEN( ).darker( ) ); 168 169 xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL ); 170 xAxisPrimary.getMajorGrid( ) 171 .getLineAttributes( ) 172 .setStyle( LineStyle.DOTTED_LITERAL ); 173 xAxisPrimary.getMajorGrid( ) 174 .getLineAttributes( ) 175 .setColor( ColorDefinitionImpl.GREY( ) ); 176 xAxisPrimary.getMajorGrid( ).getLineAttributes( ).setVisible( true ); 177 178 Axis yAxisPrimary = ( (ChartWithAxesImpl) cwaScatter ).getPrimaryOrthogonalAxis( xAxisPrimary ); 180 yAxisPrimary.getLabel( ).getCaption( ).setValue( "Price Axis" ); yAxisPrimary.getLabel( ) 182 .getCaption( ) 183 .setColor( ColorDefinitionImpl.BLUE( ) ); 184 185 yAxisPrimary.getTitle( ).setVisible( false ); 186 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 187 yAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 188 189 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 190 yAxisPrimary.getMajorGrid( ) 191 .getLineAttributes( ) 192 .setStyle( LineStyle.DOTTED_LITERAL ); 193 yAxisPrimary.getMajorGrid( ) 194 .getLineAttributes( ) 195 .setColor( ColorDefinitionImpl.GREY( ) ); 196 yAxisPrimary.getMajorGrid( ).getLineAttributes( ).setVisible( true ); 197 198 NumberDataSet dsNumericValues1 = NumberDataSetImpl.create( new double[]{ 200 -46.55, 25.32, 84.46, 125.95, 38.65, -54.32, 30 201 } ); 202 NumberDataSet dsNumericValues2 = NumberDataSetImpl.create( new double[]{ 203 125.99, 352.95, -201.95, 299.95, -95.95, 65.95, 58.95 204 } ); 205 206 Series seBase = SeriesImpl.create( ); 208 seBase.setDataSet( dsNumericValues1 ); 209 210 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 211 sdX.getQuery( ).setDefinition( "" ); xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 213 sdX.getSeries( ).add( seBase ); 214 215 ScatterSeries ss = (ScatterSeries) ScatterSeriesImpl.create( ); 217 ss.setSeriesIdentifier( "Unit Price" ); for ( int i = 0; i < ss.getMarkers( ).size( ); i++ ) 219 { 220 ( (Marker) ss.getMarkers( ).get( i ) ).setType( MarkerType.CIRCLE_LITERAL ); 221 } 222 223 DataPoint dp = ss.getDataPoint( ); 224 dp.getComponents( ).clear( ); 225 dp.setPrefix( "(" ); dp.setSuffix( ")" ); dp.getComponents( ) 228 .add( DataPointComponentImpl.create( DataPointComponentType.BASE_VALUE_LITERAL, 229 JavaNumberFormatSpecifierImpl.create( "0.00" ) ) ); dp.getComponents( ) 231 .add( DataPointComponentImpl.create( DataPointComponentType.ORTHOGONAL_VALUE_LITERAL, 232 JavaNumberFormatSpecifierImpl.create( "0.00" ) ) ); 234 ss.getLabel( ).getCaption( ).setColor( ColorDefinitionImpl.RED( ) ); 235 ss.getLabel( ).setBackground( ColorDefinitionImpl.CYAN( ) ); 236 ss.getLabel( ).setVisible( true ); 237 ss.setDataSet( dsNumericValues2 ); 238 ss.getTriggers( ) 239 .add( TriggerImpl.create( TriggerCondition.ONMOUSEOVER_LITERAL, 240 ActionImpl.create( ActionType.SHOW_TOOLTIP_LITERAL, 241 TooltipValueImpl.create( 500, null ) ) ) ); 242 243 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 244 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 245 sdY.getSeriesPalette( ).update( ColorDefinitionImpl.BLACK( ) ); 246 sdY.getSeries( ).add( ss ); 247 248 return cwaScatter; 249 } 250 251 protected static final Chart createTVChart( ) 252 { 253 ChartWithAxes cwaLine = ChartWithAxesImpl.create( ); 254 cwaLine.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) ); 255 Plot p = cwaLine.getPlot( ); 256 p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255, 257 255, 258 225 ) ); 259 cwaLine.getTitle( ) 260 .getLabel( ) 261 .getCaption( ) 262 .setValue( "Click \"Line Series\" to Toggle Visibility" ); cwaLine.setUnitSpacing( 20 ); 264 265 Legend lg = cwaLine.getLegend( ); 266 LineAttributes lia = lg.getOutline( ); 267 lg.getText( ).getFont( ).setSize( 16 ); 268 lia.setStyle( LineStyle.SOLID_LITERAL ); 269 lg.getInsets( ).set( 10, 5, 0, 0 ); 270 lg.getOutline( ).setVisible( false ); 271 lg.setAnchor( Anchor.NORTH_LITERAL ); 272 lg.getTriggers( ) 273 .add( TriggerImpl.create( TriggerCondition.ONMOUSEDOWN_LITERAL, 274 ActionImpl.create( ActionType.TOGGLE_VISIBILITY_LITERAL, 275 SeriesValueImpl.create( "not-used" ) ) ) ); 277 Axis xAxisPrimary = cwaLine.getPrimaryBaseAxes( )[0]; 278 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 279 xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL ); 280 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 281 xAxisPrimary.getTitle( ).setVisible( false ); 282 283 xAxisPrimary.setStaggered( true ); 284 285 Axis yAxisPrimary = cwaLine.getPrimaryOrthogonalAxis( xAxisPrimary ); 286 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 287 yAxisPrimary.getTitle( ).setVisible( false ); 288 289 Vector vs = new Vector ( ); 290 vs.add( "one" ); vs.add( "two" ); vs.add( "three" ); 294 ArrayList vn1 = new ArrayList ( ); 295 vn1.add( new Double ( 25 ) ); 296 vn1.add( new Double ( 35 ) ); 297 vn1.add( new Double ( -45 ) ); 298 299 TextDataSet categoryValues = TextDataSetImpl.create( vs ); 300 NumberDataSet orthoValues1 = NumberDataSetImpl.create( vn1 ); 301 302 Series seCategory = SeriesImpl.create( ); 304 seCategory.setDataSet( categoryValues ); 305 306 LineSeries ls = (LineSeries) LineSeriesImpl.create( ); 308 ls.setSeriesIdentifier( "Line Series" ); ls.setDataSet( orthoValues1 ); 310 ls.getLineAttributes( ).setColor( ColorDefinitionImpl.CREAM( ) ); 311 ls.getLabel( ).setVisible( true ); 312 313 for ( int i = 0; i < ls.getMarkers( ).size( ); i++ ) 314 { 315 ((Marker)ls.getMarkers( ).get( i )).setType( MarkerType.FOUR_DIAMONDS_LITERAL ); 316 ((Marker)ls.getMarkers( ).get( i )).setSize( 8 ); 317 } 318 319 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 320 sdX.getSeriesPalette( ).update( 0 ); xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 322 323 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 324 sdY.getSeriesPalette( ).update( 1 ); yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 326 327 sdX.getSeries( ).add( seCategory ); 328 sdY.getSeries( ).add( ls ); 329 330 return cwaLine; 331 } 332 333 protected static final Chart createURChart( ) 334 { 335 ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( ); 336 337 cwoaPie.setSeriesThickness( 25 ); 339 cwoaPie.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) ); 340 Plot p = cwoaPie.getPlot( ); 341 p.getClientArea( ).setBackground( null ); 342 p.getClientArea( ).getOutline( ).setVisible( true ); 343 p.getOutline( ).setVisible( true ); 344 345 Legend lg = cwoaPie.getLegend( ); 347 lg.getText( ).getFont( ).setSize( 16 ); 348 lg.setBackground( null ); 349 lg.getOutline( ).setVisible( true ); 350 351 cwoaPie.getTitle( ).getLabel( ).getCaption( ).setValue( "Click Pie slice to Redirect URL" ); cwoaPie.getTitle( ).getOutline( ).setVisible( true ); 354 355 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 357 "New York", "Boston", "Chicago", "San Francisco", "Dallas" } ); 359 NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{ 360 54.65, 21, 75.95, 91.28, 37.43 361 } ); 362 363 Series seCategory = (Series) SeriesImpl.create( ); 365 seCategory.setDataSet( categoryValues ); 366 367 SeriesDefinition sd = SeriesDefinitionImpl.create( ); 368 cwoaPie.getSeriesDefinitions( ).add( sd ); 369 sd.getSeriesPalette( ).update( 0 ); 370 sd.getSeries( ).add( seCategory ); 371 372 PieSeries sePie = (PieSeries) PieSeriesImpl.create( ); 374 sePie.setDataSet( seriesOneValues ); 375 sePie.setSeriesIdentifier( "Cities" ); 377 Trigger triger = TriggerImpl.create( TriggerCondition.ONMOUSEDOWN_LITERAL, 378 ActionImpl.create( ActionType.URL_REDIRECT_LITERAL, 379 URLValueImpl.create( "http://www.actuate.com", null, null, null, null ) ) ); 381 sePie.getTriggers( ).add( triger ); 382 383 SeriesDefinition sdCity = SeriesDefinitionImpl.create( ); 384 sdCity.getQuery( ).setDefinition( "Census.City" ); sd.getSeriesDefinitions( ).add( sdCity ); 386 sdCity.getSeries( ).add( sePie ); 387 388 return cwoaPie; 389 } 390 391 protected static final Chart createCBChart( ) 392 { 393 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 394 cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) ); 395 cwaBar.getTitle( ) 396 .getLabel( ) 397 .getCaption( ) 398 .setValue( "Click \"Items\" to Call Back" ); cwaBar.setUnitSpacing( 20 ); 400 401 Legend lg = cwaBar.getLegend( ); 402 LineAttributes lia = lg.getOutline( ); 403 lg.getText( ).getFont( ).setSize( 16 ); 404 lia.setStyle( LineStyle.SOLID_LITERAL ); 405 lg.getInsets( ).set( 10, 5, 0, 0 ); 406 lg.getOutline( ).setVisible( false ); 407 lg.setAnchor( Anchor.NORTH_LITERAL ); 408 lg.setItemType( LegendItemType.CATEGORIES_LITERAL ); 409 410 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 412 413 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 414 xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL ); 415 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 416 xAxisPrimary.getTitle( ).setVisible( true ); 417 418 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 420 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 421 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 422 yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 ); 423 424 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 426 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 428 25, 35, 15 429 } ); 430 431 Series seCategory = SeriesImpl.create( ); 433 seCategory.setDataSet( categoryValues ); 434 435 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 436 sdX.getSeriesPalette( ).update( 0 ); 437 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 438 sdX.getSeries( ).add( seCategory ); 439 440 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 442 bs.setDataSet( orthoValues ); 443 bs.setRiserOutline( null ); 444 bs.setSeriesIdentifier( "Callback" ); bs.getLabel( ).setVisible( true ); 446 bs.setLabelPosition( Position.INSIDE_LITERAL ); 447 bs.getTriggers( ) 448 .add( TriggerImpl.create( TriggerCondition.ONCLICK_LITERAL, 449 ActionImpl.create( ActionType.CALL_BACK_LITERAL, 450 CallBackValueImpl.create( String.valueOf( bs.getSeriesIdentifier( ) ) ) ) ) ); 451 452 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 453 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 454 sdY.getSeries( ).add( bs ); 455 456 return cwaBar; 457 } 458 } 459 | Popular Tags |