1 11 12 package org.eclipse.birt.chart.examples.api.script; 13 14 import java.util.Locale ; 15 import org.eclipse.birt.chart.model.Chart; 16 import org.eclipse.birt.chart.model.ChartWithAxes; 17 import org.eclipse.birt.chart.model.ChartWithoutAxes; 18 import org.eclipse.birt.chart.model.attribute.AxisType; 19 import org.eclipse.birt.chart.model.attribute.IntersectionType; 20 import org.eclipse.birt.chart.model.attribute.LegendItemType; 21 import org.eclipse.birt.chart.model.attribute.TickStyle; 22 import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl; 23 import org.eclipse.birt.chart.model.component.Axis; 24 import org.eclipse.birt.chart.model.component.MarkerLine; 25 import org.eclipse.birt.chart.model.component.MarkerRange; 26 import org.eclipse.birt.chart.model.component.Series; 27 import org.eclipse.birt.chart.model.component.impl.MarkerLineImpl; 28 import org.eclipse.birt.chart.model.component.impl.MarkerRangeImpl; 29 import org.eclipse.birt.chart.model.component.impl.SeriesImpl; 30 import org.eclipse.birt.chart.model.data.NumberDataSet; 31 import org.eclipse.birt.chart.model.data.SeriesDefinition; 32 import org.eclipse.birt.chart.model.data.TextDataSet; 33 import org.eclipse.birt.chart.model.data.impl.NumberDataElementImpl; 34 import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl; 35 import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl; 36 import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl; 37 import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl; 38 import org.eclipse.birt.chart.model.impl.ChartWithoutAxesImpl; 39 import org.eclipse.birt.chart.model.type.BarSeries; 40 import org.eclipse.birt.chart.model.type.PieSeries; 41 import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl; 42 import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl; 43 44 public class ScriptCharts 45 { 46 47 protected static final Chart createChart_Axis( ) 48 { 49 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 50 cwaBar.setScript( "function beforeDrawAxisLabel(axis, label, scriptContext)" + "{importPackage(Packages.org.eclipse.birt.chart.model.attribute); " + "if (axis.getType() == AxisType.TEXT_LITERAL)" + "label.getCaption( ).getColor( ).set( 140, 198, 62 );" + "else label.getCaption().getColor( ).set( 208, 32, 0);}" 56 + "function beforeDrawAxisTitle(axis, title, scriptContext)" + "{importPackage(Packages.org.eclipse.birt.chart.model.attribute);" + "{ if (axis.getType() == AxisType.LINEAR_LITERAL)" + "title.getCaption( ).setValue( \"Y-Axis Title By JavaScript\");}" + "title.getCaption( ).getColor( ).set( 32, 168, 255 );}" ); 62 63 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 65 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 66 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 67 xAxisPrimary.getTitle( ).setVisible( true ); 68 69 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 71 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 72 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 73 yAxisPrimary.getTitle( ).setVisible( true ); 74 75 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 77 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 79 8, 18, -15 80 } ); 81 82 Series seCategory = SeriesImpl.create( ); 84 seCategory.setDataSet( categoryValues ); 85 86 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 87 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 88 sdX.getSeries( ).add( seCategory ); 89 90 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 92 bs.setDataSet( orthoValues ); 93 bs.getLabel( ).setVisible( true ); 94 95 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 96 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 97 sdY.getSeries( ).add( bs ); 98 99 return cwaBar; 100 } 101 102 protected static final Chart createChart_DataPoints( ) 103 { 104 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 105 cwaBar.setScript( "function beforeDrawDataPointLabel(dataPoints, label, scriptContext)" + "{val = dataPoints.getOrthogonalValue( );" + "clr = label.getCaption( ).getColor( );" + "if ( val < -10 ) clr.set( 32, 168, 255 );" + "else if ( ( val >= -10 ) & ( val <=10 ) ) clr.set( 168, 0, 208 );" + "else if ( val > 10 ) clr.set( 0, 208, 32 );}" ); 112 113 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 115 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 116 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 117 118 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 120 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 121 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 122 123 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 125 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 127 8, 18, -15 128 } ); 129 130 Series seCategory = SeriesImpl.create( ); 132 seCategory.setDataSet( categoryValues ); 133 134 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 135 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 136 sdX.getSeries( ).add( seCategory ); 137 138 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 140 bs.setDataSet( orthoValues ); 141 bs.getLabel( ).setVisible( true ); 142 143 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 144 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 145 sdY.getSeries( ).add( bs ); 146 147 return cwaBar; 148 } 149 150 protected static final Chart createChart_Marker( ) 151 { 152 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 153 Locale.setDefault( Locale.US ); 154 cwaBar.setScript( "function beforeDrawMarkerLine(axis, line, scriptContext)" + "{ importPackage(Packages.java.util);" + "if (scriptContext.getLocale().equals(Locale.US))" + "{line.getLabel().getCaption( ).getColor().set( 165, 184, 55 );" + "line.getLineAttributes().getColor().set( 165, 184, 55 );}}" 160 + "function beforeDrawMarkerRange(axis, range, scriptContext)" + "{range.getLabel().getCaption().getColor().set( 225, 104, 105 );}" ); 163 164 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 166 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 167 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 168 169 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 171 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 172 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 173 174 MarkerLine ml = MarkerLineImpl.create( yAxisPrimary, 175 NumberDataElementImpl.create( 2 ) ); 176 yAxisPrimary.getMarkerLines( ).add( ml ); 177 178 MarkerRange mr = MarkerRangeImpl.create( yAxisPrimary, 179 NumberDataElementImpl.create( 8 ), 180 NumberDataElementImpl.create( 12 ), 181 ColorDefinitionImpl.PINK( ) ); 182 yAxisPrimary.getMarkerRanges( ).add( mr ); 183 184 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 186 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 188 8, 18, -15 189 } ); 190 191 Series seCategory = SeriesImpl.create( ); 193 seCategory.setDataSet( categoryValues ); 194 195 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 196 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 197 sdX.getSeries( ).add( seCategory ); 198 199 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 201 bs.setDataSet( orthoValues ); 202 bs.getLabel( ).setVisible( true ); 203 204 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 205 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 206 sdY.getSeries( ).add( bs ); 207 208 return cwaBar; 209 } 210 211 protected static final Chart createChart_Series( ) 212 { 213 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 214 cwaBar.setScript( "function beforeDrawSeries(series, renderer, scriptContext)" + "{importPackage(Packages.org.eclipse.birt.chart.model.component.impl);" + "series.setCurveFitting(CurveFittingImpl.create());" + "series.getLabel().getCaption().getColor().set(12, 232, 182);}" ); 219 220 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 222 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 223 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 224 225 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 227 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 228 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 229 230 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 232 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 234 8, 18, -15 235 } ); 236 237 Series seCategory = SeriesImpl.create( ); 239 seCategory.setDataSet( categoryValues ); 240 241 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 242 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 243 sdX.getSeries( ).add( seCategory ); 244 245 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 247 bs.setDataSet( orthoValues ); 248 bs.getLabel( ).setVisible( true ); 249 250 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 251 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 252 sdY.getSeries( ).add( bs ); 253 254 return cwaBar; 255 } 256 257 protected static final Chart createChart_SeriesTitle( ) 258 { 259 ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( ); 260 cwoaPie.setScript( "function beforeDrawSeriesTitle(series, label, scriptContext)" + "{label.setVisible(true);" + "label.getCaption().setValue(\"Cities\");" + "label.getCaption().getColor().set(222, 32, 182);" + "series.getLabel().getCaption().getColor().set(12, 232, 182);}" ); 266 267 cwoaPie.setSeriesThickness( 10 ); 268 269 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 271 "New York", "Boston", "Chicago", "San Francisco", "Dallas"} ); NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{ 273 54.65, 21, 75.95, 91.28, 37.43 274 } ); 275 276 Series seCategory = (Series) SeriesImpl.create( ); 278 seCategory.setDataSet( categoryValues ); 279 280 SeriesDefinition sd = SeriesDefinitionImpl.create( ); 281 cwoaPie.getSeriesDefinitions( ).add( sd ); 282 sd.getSeriesPalette( ).update( 0 ); 283 sd.getSeries( ).add( seCategory ); 284 285 PieSeries sePie = (PieSeries) PieSeriesImpl.create( ); 287 sePie.setDataSet( seriesOneValues ); 288 289 SeriesDefinition sdCity = SeriesDefinitionImpl.create( ); 290 sd.getSeriesDefinitions( ).add( sdCity ); 291 sdCity.getSeries( ).add( sePie ); 292 293 return cwoaPie; 294 } 295 296 protected static final Chart createChart_Block( ) 297 { 298 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 299 cwaBar.setScript( "function beforeDrawBlock(block, scriptContext)" + "{importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);" + "if (block.isLegend())" + "{block.getOutline().setVisible( true );" + "block.getOutline().getColor().set(21,244,231);}" 305 + "else if (block.isPlot())" + "{block.getOutline().setVisible( true );" + "block.getOutline().getColor().set(244,21,231);}" 309 + "else if (block.isTitle())" + "{block.getOutline().setVisible( true );" + "block.setBackground(ColorDefinitionImpl.CREAM());" + "block.getOutline().getColor().set(0,0,0);}}" ); 314 315 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 316 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 317 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 318 319 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 321 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 322 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 323 324 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 326 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 328 8, 18, -15 329 } ); 330 331 Series seCategory = SeriesImpl.create( ); 333 seCategory.setDataSet( categoryValues ); 334 335 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 336 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 337 sdX.getSeries( ).add( seCategory ); 338 339 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 341 bs.setDataSet( orthoValues ); 342 bs.getLabel( ).setVisible( true ); 343 344 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 345 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 346 sdY.getSeries( ).add( bs ); 347 348 return cwaBar; 349 } 350 351 protected static final Chart createChart_Legend( ) 352 { 353 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 354 cwaBar.setScript( "function beforeDrawLegendEntry(label, scriptContext)" + "{label.getCaption( ).getColor().set( 35, 184, 245 );" + "label.getCaption().getFont().setBold(true);" + "label.getCaption().getFont().setItalic(true);" + "label.getOutline().setVisible(true);" + "label.getOutline().getColor().set( 177, 12, 187);}" ); 361 cwaBar.getLegend( ).setVisible( true ); 362 cwaBar.getLegend( ).setItemType( LegendItemType.CATEGORIES_LITERAL ); 363 364 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 366 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 367 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 368 369 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 371 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 372 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 373 374 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 376 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 378 8, 18, -15 379 } ); 380 381 Series seCategory = SeriesImpl.create( ); 383 seCategory.setDataSet( categoryValues ); 384 385 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 386 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 387 sdX.getSeries( ).add( seCategory ); 388 389 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 391 bs.setDataSet( orthoValues ); 392 bs.getLabel( ).setVisible( true ); 393 394 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 395 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 396 sdY.getSeries( ).add( bs ); 397 398 return cwaBar; 399 } 400 401 protected static final Chart createJChart_Axis( ) 402 { 403 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 404 cwaBar.setScript( "org.eclipse.birt.chart.examples.api.script.java.AxisScript" ); 406 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 408 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 409 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 410 xAxisPrimary.getTitle( ).setVisible( true ); 411 412 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 414 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 415 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 416 yAxisPrimary.getTitle( ).setVisible( true ); 417 418 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 420 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 422 8, 18, -15 423 } ); 424 425 Series seCategory = SeriesImpl.create( ); 427 seCategory.setDataSet( categoryValues ); 428 429 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 430 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 431 sdX.getSeries( ).add( seCategory ); 432 433 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 435 bs.setDataSet( orthoValues ); 436 bs.getLabel( ).setVisible( true ); 437 438 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 439 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 440 sdY.getSeries( ).add( bs ); 441 442 return cwaBar; 443 } 444 445 protected static final Chart createJChart_DataPoints( ) 446 { 447 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 448 cwaBar.setScript( "org.eclipse.birt.chart.examples.api.script.java.DataPointsScript" ); 450 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 452 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 453 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 454 455 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 457 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 458 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 459 460 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 462 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 464 8, 18, -15 465 } ); 466 467 Series seCategory = SeriesImpl.create( ); 469 seCategory.setDataSet( categoryValues ); 470 471 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 472 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 473 sdX.getSeries( ).add( seCategory ); 474 475 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 477 bs.setDataSet( orthoValues ); 478 bs.getLabel( ).setVisible( true ); 479 480 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 481 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 482 sdY.getSeries( ).add( bs ); 483 484 return cwaBar; 485 } 486 487 protected static final Chart createJChart_Marker( ) 488 { 489 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 490 cwaBar.setScript( "org.eclipse.birt.chart.examples.api.script.java.MarkerScript" ); 492 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 494 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 495 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 496 497 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 499 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 500 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 501 502 MarkerLine ml = MarkerLineImpl.create( yAxisPrimary, 503 NumberDataElementImpl.create( 2 ) ); 504 yAxisPrimary.getMarkerLines( ).add( ml ); 505 506 MarkerRange mr = MarkerRangeImpl.create( yAxisPrimary, 507 NumberDataElementImpl.create( 8 ), 508 NumberDataElementImpl.create( 12 ), 509 ColorDefinitionImpl.PINK( ) ); 510 yAxisPrimary.getMarkerRanges( ).add( mr ); 511 512 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 514 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 516 8, 18, -15 517 } ); 518 519 Series seCategory = SeriesImpl.create( ); 521 seCategory.setDataSet( categoryValues ); 522 523 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 524 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 525 sdX.getSeries( ).add( seCategory ); 526 527 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 529 bs.setDataSet( orthoValues ); 530 bs.getLabel( ).setVisible( true ); 531 532 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 533 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 534 sdY.getSeries( ).add( bs ); 535 536 return cwaBar; 537 } 538 539 protected static final Chart createJChart_Series( ) 540 { 541 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 542 cwaBar.setScript( "org.eclipse.birt.chart.examples.api.script.java.SeriesScript" ); 544 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 546 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 547 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 548 549 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 551 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 552 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 553 554 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 556 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 558 8, 18, -15 559 } ); 560 561 Series seCategory = SeriesImpl.create( ); 563 seCategory.setDataSet( categoryValues ); 564 565 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 566 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 567 sdX.getSeries( ).add( seCategory ); 568 569 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 571 bs.setDataSet( orthoValues ); 572 bs.getLabel( ).setVisible( true ); 573 574 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 575 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 576 sdY.getSeries( ).add( bs ); 577 578 return cwaBar; 579 } 580 581 protected static final Chart createJChart_SeriesTitle( ) 582 { 583 ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( ); 584 cwoaPie.setScript( "org.eclipse.birt.chart.examples.api.script.java.SeriesTitleScript" ); 586 cwoaPie.setSeriesThickness( 10 ); 587 588 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 590 "New York", "Boston", "Chicago", "San Francisco", "Dallas"} ); NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{ 592 54.65, 21, 75.95, 91.28, 37.43 593 } ); 594 595 Series seCategory = (Series) SeriesImpl.create( ); 597 seCategory.setDataSet( categoryValues ); 598 599 SeriesDefinition sd = SeriesDefinitionImpl.create( ); 600 cwoaPie.getSeriesDefinitions( ).add( sd ); 601 sd.getSeriesPalette( ).update( 0 ); 602 sd.getSeries( ).add( seCategory ); 603 604 PieSeries sePie = (PieSeries) PieSeriesImpl.create( ); 606 sePie.setDataSet( seriesOneValues ); 607 608 SeriesDefinition sdCity = SeriesDefinitionImpl.create( ); 609 sd.getSeriesDefinitions( ).add( sdCity ); 610 sdCity.getSeries( ).add( sePie ); 611 612 return cwoaPie; 613 } 614 615 protected static final Chart createJChart_Block( ) 616 { 617 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 618 cwaBar.setScript( "org.eclipse.birt.chart.examples.api.script.java.BlockScript" ); 620 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 621 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 622 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 623 624 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 626 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 627 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 628 629 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 631 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 633 8, 18, -15 634 } ); 635 636 Series seCategory = SeriesImpl.create( ); 638 seCategory.setDataSet( categoryValues ); 639 640 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 641 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 642 sdX.getSeries( ).add( seCategory ); 643 644 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 646 bs.setDataSet( orthoValues ); 647 bs.getLabel( ).setVisible( true ); 648 649 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 650 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 651 sdY.getSeries( ).add( bs ); 652 653 return cwaBar; 654 } 655 656 protected static final Chart createJChart_Legend( ) 657 { 658 ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); 659 cwaBar.setScript( "org.eclipse.birt.chart.examples.api.script.java.LegendScript" ); 661 cwaBar.getLegend( ).setVisible( true ); 662 cwaBar.getLegend( ).setItemType( LegendItemType.CATEGORIES_LITERAL ); 663 664 Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; 666 xAxisPrimary.setType( AxisType.TEXT_LITERAL ); 667 xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL ); 668 669 Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); 671 yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); 672 yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); 673 674 TextDataSet categoryValues = TextDataSetImpl.create( new String []{ 676 "Item 1", "Item 2", "Item 3"} ); NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{ 678 8, 18, -15 679 } ); 680 681 Series seCategory = SeriesImpl.create( ); 683 seCategory.setDataSet( categoryValues ); 684 685 SeriesDefinition sdX = SeriesDefinitionImpl.create( ); 686 xAxisPrimary.getSeriesDefinitions( ).add( sdX ); 687 sdX.getSeries( ).add( seCategory ); 688 689 BarSeries bs = (BarSeries) BarSeriesImpl.create( ); 691 bs.setDataSet( orthoValues ); 692 bs.getLabel( ).setVisible( true ); 693 694 SeriesDefinition sdY = SeriesDefinitionImpl.create( ); 695 yAxisPrimary.getSeriesDefinitions( ).add( sdY ); 696 sdY.getSeries( ).add( bs ); 697 698 return cwaBar; 699 } 700 } 701 | Popular Tags |