KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > script > ScriptCharts


1 /*******************************************************************************
2  * Copyright (c) 2004 Actuate Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Actuate Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.birt.chart.examples.api.script;
13
14 import java.util.Locale JavaDoc;
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)" //$NON-NLS-1$
51
+ "{importPackage(Packages.org.eclipse.birt.chart.model.attribute); " //$NON-NLS-1$
52
+ "if (axis.getType() == AxisType.TEXT_LITERAL)" //$NON-NLS-1$
53
+ "label.getCaption( ).getColor( ).set( 140, 198, 62 );" //$NON-NLS-1$
54
+ "else label.getCaption().getColor( ).set( 208, 32, 0);}" //$NON-NLS-1$
55

56                 + "function beforeDrawAxisTitle(axis, title, scriptContext)" //$NON-NLS-1$
57
+ "{importPackage(Packages.org.eclipse.birt.chart.model.attribute);" //$NON-NLS-1$
58
+ "{ if (axis.getType() == AxisType.LINEAR_LITERAL)" //$NON-NLS-1$
59
+ "title.getCaption( ).setValue( \"Y-Axis Title By JavaScript\");}" //$NON-NLS-1$
60
+ "title.getCaption( ).getColor( ).set( 32, 168, 255 );}" //$NON-NLS-1$
61
);
62
63         // X-Axis
64
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         // Y-Axis
70
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         // Data Set
76
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
77                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
78
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
79                 8, 18, -15
80         } );
81
82         // X-Series
83
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         // Y-Series
91
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)" //$NON-NLS-1$
106
+ "{val = dataPoints.getOrthogonalValue( );" //$NON-NLS-1$
107
+ "clr = label.getCaption( ).getColor( );" //$NON-NLS-1$
108
+ "if ( val < -10 ) clr.set( 32, 168, 255 );" //$NON-NLS-1$
109
+ "else if ( ( val >= -10 ) & ( val <=10 ) ) clr.set( 168, 0, 208 );" //$NON-NLS-1$
110
+ "else if ( val > 10 ) clr.set( 0, 208, 32 );}"//$NON-NLS-1$
111
);
112
113         // X-Axis
114
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
115         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
116         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
117
118         // Y-Axis
119
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
120         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
121         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
122
123         // Data Set
124
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
125                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
126
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
127                 8, 18, -15
128         } );
129
130         // X-Series
131
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         // Y-Series
139
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)" //$NON-NLS-1$
155
+ "{ importPackage(Packages.java.util);" //$NON-NLS-1$
156
+ "if (scriptContext.getLocale().equals(Locale.US))" //$NON-NLS-1$
157
+ "{line.getLabel().getCaption( ).getColor().set( 165, 184, 55 );" //$NON-NLS-1$
158
+ "line.getLineAttributes().getColor().set( 165, 184, 55 );}}" //$NON-NLS-1$
159

160                 + "function beforeDrawMarkerRange(axis, range, scriptContext)" //$NON-NLS-1$
161
+ "{range.getLabel().getCaption().getColor().set( 225, 104, 105 );}" //$NON-NLS-1$
162
);
163
164         // X-Axis
165
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
166         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
167         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
168
169         // Y-Axis
170
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         // Data Set
185
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
186                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
187
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
188                 8, 18, -15
189         } );
190
191         // X-Series
192
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         // Y-Series
200
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)" //$NON-NLS-1$
215
+ "{importPackage(Packages.org.eclipse.birt.chart.model.component.impl);" //$NON-NLS-1$
216
+ "series.setCurveFitting(CurveFittingImpl.create());" //$NON-NLS-1$
217
+ "series.getLabel().getCaption().getColor().set(12, 232, 182);}" //$NON-NLS-1$
218
);
219
220         // X-Axis
221
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
222         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
223         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
224
225         // Y-Axis
226
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
227         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
228         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
229
230         // Data Set
231
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
232                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
233
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
234                 8, 18, -15
235         } );
236
237         // X-Series
238
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         // Y-Series
246
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)" //$NON-NLS-1$
261
+ "{label.setVisible(true);" //$NON-NLS-1$
262
+ "label.getCaption().setValue(\"Cities\");" //$NON-NLS-1$
263
+ "label.getCaption().getColor().set(222, 32, 182);" //$NON-NLS-1$
264
+ "series.getLabel().getCaption().getColor().set(12, 232, 182);}" //$NON-NLS-1$
265
);
266
267         cwoaPie.setSeriesThickness( 10 );
268
269         // Data Set
270
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
271                 "New York", "Boston", "Chicago", "San Francisco", "Dallas"} );//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
272
NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{
273                 54.65, 21, 75.95, 91.28, 37.43
274         } );
275
276         // Base Series
277
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         // Orthogonal Series
286
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)" //$NON-NLS-1$
300
+ "{importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);" //$NON-NLS-1$
301
+ "if (block.isLegend())" //$NON-NLS-1$
302
+ "{block.getOutline().setVisible( true );" //$NON-NLS-1$
303
+ "block.getOutline().getColor().set(21,244,231);}" //$NON-NLS-1$
304

305                 + "else if (block.isPlot())" //$NON-NLS-1$
306
+ "{block.getOutline().setVisible( true );" //$NON-NLS-1$
307
+ "block.getOutline().getColor().set(244,21,231);}" //$NON-NLS-1$
308

309                 + "else if (block.isTitle())" //$NON-NLS-1$
310
+ "{block.getOutline().setVisible( true );" //$NON-NLS-1$
311
+ "block.setBackground(ColorDefinitionImpl.CREAM());" //$NON-NLS-1$
312
+ "block.getOutline().getColor().set(0,0,0);}}" //$NON-NLS-1$
313
);
314
315         Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
316         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
317         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
318
319         // Y-Axis
320
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
321         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
322         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
323
324         // Data Set
325
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
326                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
327
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
328                 8, 18, -15
329         } );
330
331         // X-Series
332
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         // Y-Series
340
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)" //$NON-NLS-1$
355
+ "{label.getCaption( ).getColor().set( 35, 184, 245 );"//$NON-NLS-1$
356
+ "label.getCaption().getFont().setBold(true);" //$NON-NLS-1$
357
+ "label.getCaption().getFont().setItalic(true);" //$NON-NLS-1$
358
+ "label.getOutline().setVisible(true);" //$NON-NLS-1$
359
+ "label.getOutline().getColor().set( 177, 12, 187);}" //$NON-NLS-1$
360
);
361         cwaBar.getLegend( ).setVisible( true );
362         cwaBar.getLegend( ).setItemType( LegendItemType.CATEGORIES_LITERAL );
363
364         // X-Axis
365
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
366         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
367         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
368
369         // Y-Axisj
370
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
371         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
372         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
373
374         // Data Set
375
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
376                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
377
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
378                 8, 18, -15
379         } );
380
381         // X-Series
382
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         // Y-Series
390
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" );//$NON-NLS-1$
405

406         // X-Axis
407
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         // Y-Axis
413
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         // Data Set
419
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
420                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
421
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
422                 8, 18, -15
423         } );
424
425         // X-Series
426
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         // Y-Series
434
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" );//$NON-NLS-1$
449

450         // X-Axis
451
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
452         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
453         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
454
455         // Y-Axis
456
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
457         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
458         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
459
460         // Data Set
461
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
462                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
463
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
464                 8, 18, -15
465         } );
466
467         // X-Series
468
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         // Y-Series
476
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" ); //$NON-NLS-1$
491

492         // X-Axis
493
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
494         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
495         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
496
497         // Y-Axis
498
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         // Data Set
513
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
514                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
515
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
516                 8, 18, -15
517         } );
518
519         // X-Series
520
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         // Y-Series
528
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" );//$NON-NLS-1$
543

544         // X-Axis
545
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
546         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
547         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
548
549         // Y-Axis
550
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
551         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
552         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
553
554         // Data Set
555
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
556                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
557
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
558                 8, 18, -15
559         } );
560
561         // X-Series
562
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         // Y-Series
570
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" );//$NON-NLS-1$
585

586         cwoaPie.setSeriesThickness( 10 );
587
588         // Data Set
589
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
590                 "New York", "Boston", "Chicago", "San Francisco", "Dallas"} );//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
591
NumberDataSet seriesOneValues = NumberDataSetImpl.create( new double[]{
592                 54.65, 21, 75.95, 91.28, 37.43
593         } );
594
595         // Base Series
596
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         // Orthogonal Series
605
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" );//$NON-NLS-1$
619

620         Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
621         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
622         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
623
624         // Y-Axis
625
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
626         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
627         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
628
629         // Data Set
630
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
631                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
632
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
633                 8, 18, -15
634         } );
635
636         // X-Series
637
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         // Y-Series
645
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" );//$NON-NLS-1$
660

661         cwaBar.getLegend( ).setVisible( true );
662         cwaBar.getLegend( ).setItemType( LegendItemType.CATEGORIES_LITERAL );
663
664         // X-Axis
665
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
666         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
667         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
668
669         // Y-Axisj
670
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
671         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
672         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
673
674         // Data Set
675
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
676                 "Item 1", "Item 2", "Item 3"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
677
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
678                 8, 18, -15
679         } );
680
681         // X-Series
682
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         // Y-Series
690
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