KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > format > FormatCharts


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.format;
13
14 import org.eclipse.birt.chart.model.Chart;
15 import org.eclipse.birt.chart.model.ChartWithAxes;
16 import org.eclipse.birt.chart.model.ChartWithoutAxes;
17 import org.eclipse.birt.chart.model.attribute.Anchor;
18 import org.eclipse.birt.chart.model.attribute.AxisType;
19 import org.eclipse.birt.chart.model.attribute.DataPoint;
20 import org.eclipse.birt.chart.model.attribute.DataPointComponent;
21 import org.eclipse.birt.chart.model.attribute.DataPointComponentType;
22 import org.eclipse.birt.chart.model.attribute.IntersectionType;
23 import org.eclipse.birt.chart.model.attribute.LegendItemType;
24 import org.eclipse.birt.chart.model.attribute.LineStyle;
25 import org.eclipse.birt.chart.model.attribute.Marker;
26 import org.eclipse.birt.chart.model.attribute.MarkerType;
27 import org.eclipse.birt.chart.model.attribute.Orientation;
28 import org.eclipse.birt.chart.model.attribute.Position;
29 import org.eclipse.birt.chart.model.attribute.TickStyle;
30 import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
31 import org.eclipse.birt.chart.model.attribute.impl.DataPointComponentImpl;
32 import org.eclipse.birt.chart.model.attribute.impl.GradientImpl;
33 import org.eclipse.birt.chart.model.attribute.impl.JavaDateFormatSpecifierImpl;
34 import org.eclipse.birt.chart.model.attribute.impl.JavaNumberFormatSpecifierImpl;
35 import org.eclipse.birt.chart.model.component.Axis;
36 import org.eclipse.birt.chart.model.component.Series;
37 import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
38 import org.eclipse.birt.chart.model.data.DateTimeDataSet;
39 import org.eclipse.birt.chart.model.data.NumberDataSet;
40 import org.eclipse.birt.chart.model.data.SeriesDefinition;
41 import org.eclipse.birt.chart.model.data.TextDataSet;
42 import org.eclipse.birt.chart.model.data.impl.DateTimeDataSetImpl;
43 import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
44 import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
45 import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
46 import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
47 import org.eclipse.birt.chart.model.impl.ChartWithoutAxesImpl;
48 import org.eclipse.birt.chart.model.layout.Legend;
49 import org.eclipse.birt.chart.model.layout.Plot;
50 import org.eclipse.birt.chart.model.layout.TitleBlock;
51 import org.eclipse.birt.chart.model.type.BarSeries;
52 import org.eclipse.birt.chart.model.type.PieSeries;
53 import org.eclipse.birt.chart.model.type.ScatterSeries;
54 import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
55 import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
56 import org.eclipse.birt.chart.model.type.impl.ScatterSeriesImpl;
57 import org.eclipse.birt.chart.util.CDateTime;
58
59 import com.ibm.icu.util.Calendar;
60
61 public class FormatCharts
62 {
63     protected static final Chart createAxisFormatChart( )
64     {
65         ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
66
67         // Plot
68
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
69         Plot p = cwaBar.getPlot( );
70         p.getClientArea( )
71                 .setBackground( GradientImpl.create( ColorDefinitionImpl.create( 225,
72                         225,
73                         255 ),
74                         ColorDefinitionImpl.create( 255, 255, 225 ),
75                         -35,
76                         false ) );
77         p.getOutline( ).setVisible( true );
78
79         // Title
80
cwaBar.getTitle( )
81                 .getLabel( )
82                 .getCaption( )
83                 .setValue( "Bar Chart with Formatted Axes" );//$NON-NLS-1$
84

85         // Legend
86
Legend lg = cwaBar.getLegend( );
87         lg.getText( ).getFont( ).setSize( 16 );
88         lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
89
90         // X-Axis
91
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
92         xAxisPrimary.setCategoryAxis( true );
93         xAxisPrimary.setType( AxisType.DATE_TIME_LITERAL );
94         xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
95         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
96         xAxisPrimary.getTitle( ).getCaption( ).setValue( "Regional Markets" ); //$NON-NLS-1$
97
xAxisPrimary.setTitlePosition( Position.BELOW_LITERAL );
98         xAxisPrimary.setLabelPosition( Position.BELOW_LITERAL );
99         xAxisPrimary.setFormatSpecifier( JavaDateFormatSpecifierImpl.create( "MM/dd/yyyy" ) );//$NON-NLS-1$
100

101         // Y-Axis
102
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
103         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
104         yAxisPrimary.getTitle( ).getCaption( ).setValue( "Net Profit" );//$NON-NLS-1$
105
yAxisPrimary.setFormatSpecifier( JavaNumberFormatSpecifierImpl.create( "$###,###" ) );//$NON-NLS-1$
106

107         // Data Set
108
DateTimeDataSet categoryValues = DateTimeDataSetImpl.create( new Calendar[]{
109                 new CDateTime( 2001, 5, 1 ),
110                 new CDateTime( 2001, 4, 11 ),
111                 new CDateTime( 2001, 8, 23 )
112         } );
113         NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
114                 16170, 24210, -4300
115         } );
116
117         // X-Series
118
Series seCategory = SeriesImpl.create( );
119         seCategory.setDataSet( categoryValues );
120
121         SeriesDefinition sdX = SeriesDefinitionImpl.create( );
122         sdX.getSeriesPalette( ).update( -2 );
123         xAxisPrimary.getSeriesDefinitions( ).add( sdX );
124         sdX.getSeries( ).add( seCategory );
125
126         // Y-Series
127
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
128         bs.setSeriesIdentifier( "Sales" );//$NON-NLS-1$
129
bs.setDataSet( orthoValues );
130         bs.setRiserOutline( null );
131         bs.getLabel( ).setVisible( true );
132         bs.setLabelPosition( Position.INSIDE_LITERAL );
133
134         SeriesDefinition sdY = SeriesDefinitionImpl.create( );
135         yAxisPrimary.getSeriesDefinitions( ).add( sdY );
136         sdY.getSeries( ).add( bs );
137
138         return cwaBar;
139     }
140
141     protected static final Chart createColoredByCategoryChart( )
142     {
143         ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
144
145         // Plot
146
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
147         cwaBar.getBlock( ).getOutline( ).setVisible( true );
148         Plot p = cwaBar.getPlot( );
149         p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
150                 255,
151                 225 ) );
152         p.getOutline( ).setVisible( false );
153         cwaBar.getTitle( )
154                 .getLabel( )
155                 .getCaption( )
156                 .setValue( "Bar Chart Colored by Category" );//$NON-NLS-1$
157

158         // Legend
159
Legend lg = cwaBar.getLegend( );
160         lg.getText( ).getFont( ).setSize( 16 );
161         lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
162
163         // X-Axis
164
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
165         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
166         xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
167         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
168         xAxisPrimary.getTitle( ).getCaption( ).setValue( "Products" );//$NON-NLS-1$
169
xAxisPrimary.getTitle( ).setVisible( true );
170
171         // Y-Axis
172
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
173         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
174         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
175         yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );
176         yAxisPrimary.getTitle( ).getCaption( ).setValue( "Sales" );//$NON-NLS-1$
177

178         // Data Set
179
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
180                 "Item 1", "Item 2", "Item 3"} );//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
181
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
182                 14.3, 20.9, -7.6
183         } );
184
185         // X-Series
186
Series seCategory = SeriesImpl.create( );
187         seCategory.setDataSet( categoryValues );
188         SeriesDefinition sdX = SeriesDefinitionImpl.create( );
189         sdX.getSeriesPalette( ).update( 0 );
190         xAxisPrimary.getSeriesDefinitions( ).add( sdX );
191         sdX.getSeries( ).add( seCategory );
192
193         // Y-Series
194
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
195         bs.setDataSet( orthoValues );
196         bs.setRiserOutline( null );
197         bs.getLabel( ).setVisible( true );
198         bs.setLabelPosition( Position.INSIDE_LITERAL );
199         SeriesDefinition sdY = SeriesDefinitionImpl.create( );
200         sdY.getSeriesPalette( ).update( 1 );
201         yAxisPrimary.getSeriesDefinitions( ).add( sdY );
202         sdY.getSeries( ).add( bs );
203
204         return cwaBar;
205     }
206
207     protected static final Chart createLegendTitleChart( )
208     {
209         ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
210
211         // Plot
212
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
213         cwaBar.getBlock( ).getOutline( ).setVisible( true );
214         Plot p = cwaBar.getPlot( );
215         p.getOutline( ).setVisible( false );
216
217         // Title
218
TitleBlock tb = cwaBar.getTitle( );
219         tb.setBackground( GradientImpl.create( ColorDefinitionImpl.create( 200,
220                 200,
221                 244 ), ColorDefinitionImpl.create( 250, 122, 253 ), 0, false ) );
222
223         tb.getOutline( ).setStyle( LineStyle.DASHED_LITERAL );
224         tb.getOutline( ).setColor( ColorDefinitionImpl.create( 0, 100, 245 ) );
225         tb.getOutline( ).setThickness( 1 );
226         tb.getOutline( ).setVisible( true );
227
228         tb.getLabel( ).getCaption( ).setValue( "Formatted Legend and Title" ); //$NON-NLS-1$
229
tb.getLabel( ).getCaption( ).setColor( ColorDefinitionImpl.GREEN( ) );
230         tb.getLabel( ).setShadowColor( ColorDefinitionImpl.YELLOW( ) );
231         tb.getLabel( ).getOutline( ).setVisible( true );
232
233         // Legend
234
Legend lg = cwaBar.getLegend( );
235         lg.getText( ).getFont( ).setSize( 16 );
236         lg.getInsets( ).set( 10, 5, 0, 0 );
237
238         lg.getOutline( ).setStyle( LineStyle.DASH_DOTTED_LITERAL );
239         lg.getOutline( ).setColor( ColorDefinitionImpl.create( 214, 100, 12 ) );
240         lg.getOutline( ).setVisible( true );
241
242         lg.setBackground( GradientImpl.create( ColorDefinitionImpl.create( 225,
243                 225,
244                 255 ), ColorDefinitionImpl.create( 255, 255, 225 ), -35, false ) );
245         lg.setAnchor( Anchor.NORTH_LITERAL );
246         lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
247
248         lg.getClientArea( ).setBackground( ColorDefinitionImpl.ORANGE( ) );
249         lg.setPosition( Position.LEFT_LITERAL );
250         lg.setOrientation( Orientation.HORIZONTAL_LITERAL );
251
252         // X-Axis
253
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
254         xAxisPrimary.setType( AxisType.TEXT_LITERAL );
255         xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
256         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
257         xAxisPrimary.getTitle( ).getCaption( ).setValue( "Products" );//$NON-NLS-1$
258
xAxisPrimary.getTitle( ).setVisible( true );
259
260         // Y-Axis
261
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
262         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
263         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
264         yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );
265         yAxisPrimary.getTitle( ).getCaption( ).setValue( "Sales" );//$NON-NLS-1$
266

267         // Data Set
268
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
269                 "Item 1", "Item 2", "Item 3"} );//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
270
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
271                 14.3, 20.9, -7.6
272         } );
273
274         // X-Series
275
Series seCategory = SeriesImpl.create( );
276         seCategory.setDataSet( categoryValues );
277         SeriesDefinition sdX = SeriesDefinitionImpl.create( );
278         sdX.getSeriesPalette( ).update( -4 );
279         xAxisPrimary.getSeriesDefinitions( ).add( sdX );
280         sdX.getSeries( ).add( seCategory );
281
282         // Y-Series
283
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
284         bs.setDataSet( orthoValues );
285         bs.setRiserOutline( null );
286         bs.getLabel( ).setVisible( true );
287         bs.setLabelPosition( Position.INSIDE_LITERAL );
288         SeriesDefinition sdY = SeriesDefinitionImpl.create( );
289         sdY.getSeriesPalette( ).update( 1 );
290         yAxisPrimary.getSeriesDefinitions( ).add( sdY );
291         sdY.getSeries( ).add( bs );
292
293         return cwaBar;
294     }
295
296     protected static final Chart createPercentageValueChart( )
297     {
298         ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( );
299
300         // Plot
301
cwoaPie.setSeriesThickness( 25 );
302         cwoaPie.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
303         Plot p = cwoaPie.getPlot( );
304         p.getClientArea( ).setBackground( null );
305         p.getClientArea( ).getOutline( ).setVisible( true );
306         p.getOutline( ).setVisible( true );
307
308         // Legend
309
Legend lg = cwoaPie.getLegend( );
310         lg.getText( ).getFont( ).setSize( 16 );
311         lg.setBackground( null );
312         lg.getOutline( ).setVisible( true );
313
314         // Title
315
cwoaPie.getTitle( )
316                 .getLabel( )
317                 .getCaption( )
318                 .setValue( "Pie Chart with Percentage Values" );//$NON-NLS-1$
319
cwoaPie.getTitle( ).getOutline( ).setVisible( true );
320
321         // Data Set
322
TextDataSet categoryValues = TextDataSetImpl.create( new String JavaDoc[]{
323                 "New York", "Boston", "Chicago", "San Francisco", "Dallas"} );//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$
324

325         double data[] = {
326                 54.65, 21, 75.95, 91.28, 37.43
327         };
328
329         double value = 0;
330         for ( int i = 0; i < data.length; i++ )
331         {
332             value += data[i];
333         }
334
335         double values[] = new double[data.length];
336         for ( int i = 0; i < data.length; i++ )
337         {
338             values[i] += ( data[i] / value ) * 100;
339         }
340
341         NumberDataSet seriesValues = NumberDataSetImpl.create( values );
342
343         // Base Series
344
Series seCategory = (Series) SeriesImpl.create( );
345         seCategory.setDataSet( categoryValues );
346
347         SeriesDefinition sd = SeriesDefinitionImpl.create( );
348         cwoaPie.getSeriesDefinitions( ).add( sd );
349         sd.getSeriesPalette( ).update( 0 );
350         sd.getSeries( ).add( seCategory );
351
352         // Orthogonal Series
353
PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
354         sePie.setDataSet( seriesValues );
355         sePie.setSeriesIdentifier( "Cities" );//$NON-NLS-1$
356

357         SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
358         sdCity.getQuery( ).setDefinition( "Census.City" );//$NON-NLS-1$
359
sd.getSeriesDefinitions( ).add( sdCity );
360         sdCity.getSeries( ).add( sePie );
361
362         DataPointComponent dpc = DataPointComponentImpl.create( DataPointComponentType.ORTHOGONAL_VALUE_LITERAL,
363                 JavaNumberFormatSpecifierImpl.create( "0'%'" ) );//$NON-NLS-1$
364
sePie.getDataPoint( ).getComponents( ).clear( );
365         sePie.getDataPoint( ).getComponents( ).add( dpc );
366
367         return cwoaPie;
368     }
369
370     protected static final Chart createPlotFormatChart( )
371     {
372         ChartWithAxes cwaScatter = ChartWithAxesImpl.create( );
373
374         // Plot
375
Plot p = cwaScatter.getPlot( );
376
377         p.getOutline( ).setStyle( LineStyle.DASH_DOTTED_LITERAL );
378         p.getOutline( ).setColor( ColorDefinitionImpl.create( 214, 100, 12 ) );
379         p.getOutline( ).setVisible( true );
380
381         p.setBackground( ColorDefinitionImpl.CREAM( ) );
382         p.setAnchor( Anchor.NORTH_LITERAL );
383
384         p.getClientArea( )
385                 .setBackground( GradientImpl.create( ColorDefinitionImpl.create( 225,
386                         0,
387                         255 ),
388                         ColorDefinitionImpl.create( 255, 253, 200 ),
389                         -35,
390                         false ) );
391         p.getClientArea( ).getOutline( ).setVisible( true );
392
393         // Title
394
cwaScatter.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
395         cwaScatter.getTitle( )
396                 .getLabel( )
397                 .getCaption( )
398                 .setValue( "Numeric Scatter Chart" );//$NON-NLS-1$
399

400         // X-Axis
401
Axis xAxisPrimary = ( (ChartWithAxesImpl) cwaScatter ).getPrimaryBaseAxes( )[0];
402
403         xAxisPrimary.getTitle( ).getCaption( ).setValue( "X Axis" );//$NON-NLS-1$
404
xAxisPrimary.setType( AxisType.LINEAR_LITERAL );
405         xAxisPrimary.getLabel( )
406                 .getCaption( )
407                 .setColor( ColorDefinitionImpl.GREEN( ).darker( ) );
408         xAxisPrimary.getTitle( ).setVisible( false );
409
410         xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
411         xAxisPrimary.getMajorGrid( )
412                 .getLineAttributes( )
413                 .setStyle( LineStyle.DOTTED_LITERAL );
414         xAxisPrimary.getMajorGrid( )
415                 .getLineAttributes( )
416                 .setColor( ColorDefinitionImpl.GREY( ) );
417         xAxisPrimary.getMajorGrid( ).getLineAttributes( ).setVisible( true );
418
419         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
420
421         // Y-Axis
422
Axis yAxisPrimary = ( (ChartWithAxesImpl) cwaScatter ).getPrimaryOrthogonalAxis( xAxisPrimary );
423
424         yAxisPrimary.getLabel( ).getCaption( ).setValue( "Price Axis" );//$NON-NLS-1$
425
yAxisPrimary.getLabel( )
426                 .getCaption( )
427                 .setColor( ColorDefinitionImpl.BLUE( ) );
428         yAxisPrimary.getTitle( ).setVisible( true );
429         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
430
431         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
432         yAxisPrimary.getMajorGrid( )
433                 .getLineAttributes( )
434                 .setStyle( LineStyle.DOTTED_LITERAL );
435         yAxisPrimary.getMajorGrid( )
436                 .getLineAttributes( )
437                 .setColor( ColorDefinitionImpl.GREY( ) );
438         yAxisPrimary.getMajorGrid( ).getLineAttributes( ).setVisible( true );
439
440         yAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
441
442         // Data Set
443
NumberDataSet dsNumericValues1 = NumberDataSetImpl.create( new double[]{
444                 -46.55, 25.32, 84.46, 125.95, 38.65, -54.32, 30
445         } );
446         NumberDataSet dsNumericValues2 = NumberDataSetImpl.create( new double[]{
447                 125.99, 352.95, -201.95, 299.95, -95.95, 65.95, 58.95
448         } );
449
450         // X-Series
451
Series seBase = SeriesImpl.create( );
452         seBase.setDataSet( dsNumericValues1 );
453
454         SeriesDefinition sdX = SeriesDefinitionImpl.create( );
455         xAxisPrimary.getSeriesDefinitions( ).add( sdX );
456         sdX.getSeries( ).add( seBase );
457
458         // Y-Series
459
ScatterSeries ss = (ScatterSeries) ScatterSeriesImpl.create( );
460         ss.setSeriesIdentifier( "Unit Price" );//$NON-NLS-1$
461
for ( int i = 0; i < ss.getMarkers( ).size( ); i++ )
462         {
463             ( (Marker) ss.getMarkers( ).get( i ) ).setType( MarkerType.CIRCLE_LITERAL );
464         }
465         DataPoint dp = ss.getDataPoint( );
466         dp.getComponents( ).clear( );
467         dp.setPrefix( "(" );//$NON-NLS-1$
468
dp.setSuffix( ")" );//$NON-NLS-1$
469
dp.getComponents( )
470                 .add( DataPointComponentImpl.create( DataPointComponentType.BASE_VALUE_LITERAL,
471                         JavaNumberFormatSpecifierImpl.create( "0.00" ) ) );//$NON-NLS-1$
472
dp.getComponents( )
473                 .add( DataPointComponentImpl.create( DataPointComponentType.ORTHOGONAL_VALUE_LITERAL,
474                         JavaNumberFormatSpecifierImpl.create( "0.00" ) ) );//$NON-NLS-1$
475
ss.getLabel( ).getCaption( ).setColor( ColorDefinitionImpl.RED( ) );
476         ss.getLabel( ).setBackground( ColorDefinitionImpl.CYAN( ) );
477         ss.getLabel( ).setVisible( true );
478         ss.setDataSet( dsNumericValues2 );
479
480         SeriesDefinition sdY = SeriesDefinitionImpl.create( );
481         yAxisPrimary.getSeriesDefinitions( ).add( sdY );
482         sdY.getSeriesPalette( ).update( ColorDefinitionImpl.BLACK( ) );
483         sdY.getSeries( ).add( ss );
484
485         return cwaScatter;
486     }
487
488     protected static final Chart createSeriesFormatChart( )
489     {
490         ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
491
492         // Plot
493
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
494         Plot p = cwaBar.getPlot( );
495         p.getClientArea( )
496                 .setBackground( GradientImpl.create( ColorDefinitionImpl.create( 225,
497                         225,
498                         255 ),
499                         ColorDefinitionImpl.create( 255, 255, 225 ),
500                         -35,
501                         false ) );
502         p.getOutline( ).setVisible( true );
503
504         // Title
505
cwaBar.getTitle( )
506                 .getLabel( )
507                 .getCaption( )
508                 .setValue( "Bar Chart with Formatted Series" );//$NON-NLS-1$
509

510         // Legend
511
Legend lg = cwaBar.getLegend( );
512         lg.getText( ).getFont( ).setSize( 16 );
513         lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
514
515         // X-Axis
516
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
517         xAxisPrimary.setCategoryAxis( true );
518         xAxisPrimary.setType( AxisType.DATE_TIME_LITERAL );
519         xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
520         xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
521         xAxisPrimary.getTitle( ).getCaption( ).setValue( "Regional Markets" ); //$NON-NLS-1$
522
xAxisPrimary.setTitlePosition( Position.BELOW_LITERAL );
523         xAxisPrimary.setLabelPosition( Position.BELOW_LITERAL );
524
525         // Y-Axis
526
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
527         yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
528         yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
529         yAxisPrimary.getTitle( ).getCaption( ).setValue( "Net Profit" );//$NON-NLS-1$
530

531         // Data Set
532
DateTimeDataSet categoryValues = DateTimeDataSetImpl.create( new Calendar[]{
533                 new CDateTime( 2001, 5, 1 ),
534                 new CDateTime( 2001, 4, 11 ),
535                 new CDateTime( 2001, 8, 23 ),
536                 new CDateTime( 2001, 10, 15 )
537         } );
538         NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
539                 1620, 3630, 4600, -1800
540         } );
541
542         // X-Series
543
Series seCategory = SeriesImpl.create( );
544         seCategory.setDataSet( categoryValues );
545
546         SeriesDefinition sdX = SeriesDefinitionImpl.create( );
547         sdX.getSeriesPalette( ).update( -2 );
548         xAxisPrimary.getSeriesDefinitions( ).add( sdX );
549         sdX.getSeries( ).add( seCategory );
550         sdX.setFormatSpecifier( JavaDateFormatSpecifierImpl.create( "MM/dd/yyyy" ) );//$NON-NLS-1$
551

552         //Y-Series
553
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
554         bs.setSeriesIdentifier( "Sales" );//$NON-NLS-1$
555
bs.setDataSet( orthoValues );
556         bs.setRiserOutline( null );
557         bs.getLabel( ).setVisible( true );
558         bs.setLabelPosition( Position.INSIDE_LITERAL );
559
560         SeriesDefinition sdY = SeriesDefinitionImpl.create( );
561         yAxisPrimary.getSeriesDefinitions( ).add( sdY );
562         sdY.getSeries( ).add( bs );
563
564         DataPointComponent dpc = DataPointComponentImpl.create( DataPointComponentType.ORTHOGONAL_VALUE_LITERAL,
565                 JavaNumberFormatSpecifierImpl.create( "$###,###.00" ) );//$NON-NLS-1$
566
bs.getDataPoint( ).getComponents( ).clear( );
567         bs.getDataPoint( ).getComponents( ).add( dpc );
568
569         return cwaBar;
570     }
571 }
572
Popular Tags