Source Code Cross Referenced for TestChart.java in  » Chart » charting-0.94 » de » progra » charting » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » charting 0.94 » de.progra.charting.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:            JOpenChart Java Charting Library and Toolkit
003:            Copyright (C) 2001  Sebastian Müller
004:            http://jopenchart.sourceforge.net
005:
006:            This library is free software; you can redistribute it and/or
007:            modify it under the terms of the GNU Lesser General Public
008:            License as published by the Free Software Foundation; either
009:            version 2.1 of the License, or (at your option) any later version.
010:
011:            This library is distributed in the hope that it will be useful,
012:            but WITHOUT ANY WARRANTY; without even the implied warranty of
013:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:            Lesser General Public License for more details.
015:
016:            You should have received a copy of the GNU Lesser General Public
017:            License along with this library; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:
020:            TestChart.java
021:            Created on 19. Oktober 2001, 16:34
022:         */
023:
024:        package de.progra.charting.test;
025:
026:        import de.progra.charting.*;
027:        import de.progra.charting.model.*;
028:        import de.progra.charting.render.*;
029:        import java.awt.*;
030:        import java.awt.geom.*;
031:        import java.io.*;
032:        import java.text.*;
033:        import java.awt.geom.AffineTransform;
034:
035:        /**
036:         * This class is used to test the Charting package.
037:         * @author  mueller
038:         * @version 1.0
039:         */
040:        public class TestChart {
041:
042:            /** Creates new TestChart */
043:            public TestChart() {
044:            }
045:
046:            /** Used to create multiple charts for testing purposes in $USERHOME.
047:             * @param args empty
048:             */
049:            public static void main(String[] args) {
050:                makeSimpleLineTest();
051:                makeRadarTest();
052:                makeDiffSizedBarChartTest();
053:                makeBarChartFormatTest();
054:                makeAxisTitleTest();
055:
056:                makeNevilleTest();
057:
058:                makeSimplePieTest();
059:                makeLineChartTest();
060:                makePlotTest();
061:                makePlot2Test();
062:                makeBarTest();
063:                makeStackedBarTest();
064:
065:                makeManualBarTest();
066:                makeSimpleNegativeLineTest();
067:
068:                System.exit(0);
069:            }
070:
071:            public static void makeAxisTitleTest() {
072:                System.out
073:                        .println("** Creating Bar Chart Plot with Axis Titles.");
074:                int[][] model = { { 23, 43, 12 }, { 54, -15, 34 },
075:                        { 99, 32, 45 } };
076:
077:                String[] columns = { "1997", "1998", "1999" };
078:
079:                String[] rows = { "foobar.com", "@foo Ltd.", "bar.online" };
080:
081:                String title = "Average Growth 1997 - 1999";
082:
083:                int width = 640;
084:                int height = 480;
085:
086:                ObjectChartDataModel data = new ObjectChartDataModel(model,
087:                        columns, rows);
088:                DefaultChart c = new DefaultChart(data, title,
089:                        DefaultChart.LINEAR_X_LINEAR_Y, "Year", "Growth");
090:                c.addChartRenderer(new BarChartRenderer(c.getCoordSystem(),
091:                        data), 1);
092:                c.setBounds(new Rectangle(0, 0, width, height));
093:                try {
094:                    ChartEncoder.createPNG(new FileOutputStream(System
095:                            .getProperty("user.home")
096:                            + "/axistest.png"), c);
097:                } catch (EncodingException e) {
098:                    System.out
099:                            .println("** Error creating the axistest.png file, showing the bar chart.");
100:                    e.getCause().printStackTrace();
101:                    return;
102:                } catch (Exception e) {
103:                    System.out
104:                            .println("** Error creating the axistest.png file, showing the bar chart.");
105:                    e.printStackTrace();
106:                    return;
107:                }
108:                System.out.println("successfull.");
109:            }
110:
111:            public static void makeRadarTest() {
112:                System.out.println("** Creating Radar Chart Plot.");
113:                int[][] model = { { 23, 43, 12, 19, 12 },
114:                        { 54, 20, 34, 40, 67 }, { 15, 30, 8, 17, 23 },
115:                        { 85, 15, 10, 26, 54 } };
116:
117:                String[] columns = { "1997", "1998", "1999", "2000", "2001" };
118:
119:                String[] rows = { "foobar.com", "@foo Ltd.", "bar.online",
120:                        "foo.co.uk" };
121:
122:                String title = "Average Growth 1997 - 2001";
123:
124:                int width = 640;
125:                int height = 480;
126:
127:                ObjectChartDataModel data = new ObjectChartDataModel(model,
128:                        columns, rows);
129:                DefaultChart c = new DefaultChart(data, title);
130:                c.addChartRenderer(new RadarChartRenderer(data), 1);
131:                c.setBounds(new Rectangle(0, 0, width, height));
132:
133:                try {
134:                    ChartEncoder.createPNG(new FileOutputStream(System
135:                            .getProperty("user.home")
136:                            + "/radartest.png"), c);
137:                } catch (EncodingException e) {
138:                    System.out
139:                            .println("** Error creating the radartest.png file, showing the radar chart.");
140:                    e.getCause().printStackTrace();
141:                    return;
142:                } catch (Exception e) {
143:                    System.out
144:                            .println("** Error creating the radartest.png file, showing the radar chart.");
145:                    e.printStackTrace();
146:                    return;
147:                }
148:                System.out.println("successfull.");
149:            }
150:
151:            public static void makeBarChartFormatTest() {
152:                System.out.println("** Creating Bar Chart Plot.");
153:                int[][] model = { { 23, 43, 12 }, { 54, -15, 34 },
154:                        { 99, 32, 45 } };
155:
156:                String[] columns = { "1997", "1998", "1999" };
157:
158:                String[] rows = { "foobar.com", "@foo Ltd.", "bar.online" };
159:
160:                String title = "Average Growth 1997 - 1999";
161:
162:                int width = 640;
163:                int height = 480;
164:
165:                ObjectChartDataModel data = new ObjectChartDataModel(model,
166:                        columns, rows);
167:                DefaultChart c = new DefaultChart(data, title,
168:                        DefaultChart.LINEAR_X_LINEAR_Y, "Year", "Growth");
169:                /*CoordSystem cs, ChartDataModel model, RowColorModel rcm, 
170:                    DecimalFormat topFormat, Font topFont, float boxWidth
171:                 */
172:                c.setCoordSystem(new CoordSystem(data, new DecimalFormat(),
173:                        false, true, false));
174:                c.addChartRenderer(new BarChartRenderer(c.getCoordSystem(),
175:                        data, new DecimalFormat(), new Font("sans",
176:                                Font.ITALIC, 9), 1.0f), 1);
177:                c.setBounds(new Rectangle(0, 0, width, height));
178:                try {
179:                    ChartEncoder.createPNG(new FileOutputStream(System
180:                            .getProperty("user.home")
181:                            + "/barchart2test.png"), c);
182:                } catch (EncodingException e) {
183:                    System.out
184:                            .println("** Error creating the barchart2test.png file, showing the bar chart.");
185:                    e.getCause().printStackTrace();
186:                    return;
187:                } catch (Exception e) {
188:                    System.out
189:                            .println("** Error creating the barchart2test.png file, showing the bar chart.");
190:                    e.printStackTrace();
191:                    return;
192:                }
193:                System.out.println("successfull.");
194:            }
195:
196:            public static void makeSimpleLineTest() {
197:                System.out.println("** Creating Simple Line Test.");
198:                int[][] model = { { -200000, 0, 100, 200000 } };
199:
200:                double[] columns = { -100, 0.0, 1.0, 2000.0 };
201:
202:                String[] rows = { "f(x) = x^3" };
203:
204:                String title = "Neville Interpolation";
205:
206:                int width = 640;
207:                int height = 480;
208:
209:                DefaultChartDataModel data = new DefaultChartDataModel(model,
210:                        columns, rows);
211:                /*
212:                data.setManualScale(true);
213:                data.setMaximumValue(new Integer(200000));
214:                data.setMinimumValue(new Integer(-10));
215:                data.setMaximumColumnValue(500.0);
216:                data.setMinimumColumnValue(-10.0);
217:                 */
218:                DefaultChart c = new DefaultChart(data, title,
219:                        DefaultChart.LINEAR_X_LINEAR_Y);
220:                c.addChartRenderer(new PlotChartRenderer(c.getCoordSystem(),
221:                        data), 1);
222:
223:                c.setBounds(new Rectangle(0, 0, width, height));
224:
225:                try {
226:                    ChartEncoder.createEncodedImage(new FileOutputStream(System
227:                            .getProperty("user.home")
228:                            + "/linetest.png"), c, "png");
229:                } catch (EncodingException e) {
230:                    System.out
231:                            .println("** Error creating the linetest.png file, showing the simple line chart.");
232:                    e.getCause().printStackTrace();
233:                    return;
234:                } catch (Exception e) {
235:                    System.out
236:                            .println("** Error creating the linetest.png file, showing the simple line chart.");
237:                    e.printStackTrace();
238:                    return;
239:                }
240:                System.out.println("successfull.");
241:            }
242:
243:            public static void makeNevilleTest() {
244:                System.out.println("** Creating Neville Interpolation Test.");
245:                int[][] model = { { -8, 0, 1, 8 } };
246:
247:                double[] columns = { -2.0, 0.0, 1.0, 2.0 };
248:
249:                String[] rows = { "f(x) = x^3" };
250:
251:                String title = "Neville Interpolation";
252:
253:                int width = 640;
254:                int height = 480;
255:
256:                DefaultChartDataModel data = new DefaultChartDataModel(model,
257:                        columns, rows);
258:                data.setAutoScale(true);
259:                DefaultChart c = new DefaultChart(data, title,
260:                        DefaultChart.LINEAR_X_LINEAR_Y);
261:                c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(),
262:                        data), 1);
263:
264:                c.addChartRenderer(new PlotChartRenderer(c.getCoordSystem(),
265:                        data), 2);
266:
267:                c.addChartRenderer(new InterpolationChartRenderer(c
268:                        .getCoordSystem(), data), 3);
269:                c.setBounds(new Rectangle(0, 0, width, height));
270:
271:                try {
272:                    ChartEncoder.createEncodedImage(new FileOutputStream(System
273:                            .getProperty("user.home")
274:                            + "/nevilletest.png"), c, "png");
275:                } catch (EncodingException e) {
276:                    System.out
277:                            .println("** Error creating the nevilletest.png file, showing the Neville Interpolation.");
278:                    e.getCause().printStackTrace();
279:                    return;
280:                } catch (Exception e) {
281:                    System.out
282:                            .println("** Error creating the nevilletest.png file, showing the Neville Interpolation.");
283:                    e.printStackTrace();
284:                    return;
285:                }
286:                System.out.println("successfull.");
287:            }
288:
289:            public static void makeSimplePieTest() {
290:                System.out.println("** Creating Pie Chart Test.");
291:                int[][] model = { { 23, 43, 12 }, { 54, -15, 34 },
292:                        { 99, 32, 45 } };
293:
294:                String[] columns = { "1997", "1998", "1999" };
295:
296:                String[] rows = { "foobar.com", "@foo Ltd.", "bar.online" };
297:
298:                String title = "Average Growth 1997 - 1999";
299:
300:                int width = 640;
301:                int height = 480;
302:
303:                ObjectChartDataModel data = new ObjectChartDataModel(model,
304:                        columns, rows);
305:                DefaultChart c = new DefaultChart(data, title);
306:                c.addChartRenderer(new PieChartRenderer(data), 1);
307:                c.setBounds(new Rectangle(0, 0, width, height));
308:                try {
309:                    ChartEncoder.createPNG(new FileOutputStream(System
310:                            .getProperty("user.home")
311:                            + "/simplepie.png"), c);
312:                } catch (EncodingException e) {
313:                    System.out
314:                            .println("** Error creating the simple.png file, showing the pie chart.");
315:                    e.getCause().printStackTrace();
316:                    return;
317:                } catch (Exception e) {
318:                    System.out
319:                            .println("** Error creating the simplepie.png file, showing the pie chart.");
320:                    e.printStackTrace();
321:                }
322:                System.out.println("successfull.");
323:            }
324:
325:            public static void makeLineChartTest() {
326:                System.out.println("** Creating Line Chart Test.");
327:
328:                int[] quadr = { 0, 1, 4, 9, 16, 25, 36 };
329:                int[] exp = { 1, 2, 4, 8, 16, 32, 64 };
330:                double[] columns = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
331:
332:                DefaultDataSet[] ds = new DefaultDataSet[3];
333:                ds[0] = new DefaultDataSet(ChartUtilities
334:                        .transformArray(new int[] { 0, 6 }), ChartUtilities
335:                        .transformArray(new double[] { 0.0, 6.0 }),
336:                        CoordSystem.FIRST_YAXIS, "Linear Growth");
337:                ds[1] = new DefaultDataSet(
338:                        ChartUtilities.transformArray(quadr), ChartUtilities
339:                                .transformArray(columns),
340:                        CoordSystem.FIRST_YAXIS, "Quadratic Growth");
341:
342:                ds[2] = new DefaultDataSet(ChartUtilities.transformArray(exp),
343:                        ChartUtilities.transformArray(columns),
344:                        CoordSystem.FIRST_YAXIS, "Exponential Growth");
345:
346:                String title = "Growth Factor Comparison";
347:
348:                int width = 640;
349:                int height = 480;
350:
351:                DefaultChartDataModel data = new DefaultChartDataModel(ds);
352:
353:                // Look at the next 3 lines:
354:                data.setAutoScale(true);
355:                DefaultChart c = new DefaultChart(data, title,
356:                        DefaultChart.LINEAR_X_LINEAR_Y);
357:                c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(),
358:                        data), 1);
359:
360:                c.setBounds(new Rectangle(0, 0, width, height));
361:
362:                try {
363:                    ChartEncoder.createPNG(new FileOutputStream(System
364:                            .getProperty("user.home")
365:                            + "/simpleline.png"), c);
366:                } catch (EncodingException e) {
367:                    System.out
368:                            .println("** Error creating the simpleline.png file, showing the line chart.");
369:                    e.getCause().printStackTrace();
370:                    return;
371:                } catch (Exception e) {
372:                    System.out
373:                            .println("** Error creating the simpleline.png file, showing the line chart.");
374:                    e.printStackTrace();
375:                    return;
376:                }
377:                System.out.println("successfull.");
378:            }
379:
380:            public static void makeDiffSizedBarChartTest() {
381:                System.out
382:                        .println("** Creating Bar Chart Test with different sized DataSets.");
383:
384:                int[] quadr = { 0, 1, 4, 9, 16, 25, 36 };
385:                int[] exp = { 1, 2, 4, 8, 16, 32, 64 };
386:                String[] columns = { "0", "1", "2", "3", "4", "5", "6" };
387:
388:                DefaultDataSet[] ds = new DefaultDataSet[3];
389:                ds[0] = new DefaultDataSet(ChartUtilities
390:                        .transformArray(new int[] { 0, 6 }), new String[] {
391:                        "0", "6" }, CoordSystem.FIRST_YAXIS, "Linear Growth");
392:                ds[1] = new DefaultDataSet(
393:                        ChartUtilities.transformArray(quadr), columns,
394:                        CoordSystem.FIRST_YAXIS, "Quadratic Growth");
395:
396:                ds[2] = new DefaultDataSet(ChartUtilities.transformArray(exp),
397:                        columns, CoordSystem.FIRST_YAXIS, "Exponential Growth");
398:
399:                String title = "Growth Factor Comparison";
400:
401:                int width = 640;
402:                int height = 480;
403:
404:                ObjectChartDataModel data = new ObjectChartDataModel(ds,
405:                        columns);
406:
407:                // Look at the next 3 lines:
408:                //data.setAutoScale(true);
409:                DefaultChart c = new DefaultChart(data, title,
410:                        DefaultChart.LINEAR_X_LINEAR_Y, "x", "y");
411:                c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(),
412:                        data), 1);
413:
414:                c.setBounds(new Rectangle(0, 0, width, height));
415:
416:                try {
417:                    ChartEncoder.createPNG(new FileOutputStream(System
418:                            .getProperty("user.home")
419:                            + "/objectbarchart.png"), c);
420:                } catch (EncodingException e) {
421:                    System.out
422:                            .println("** Error creating the objectbarchart.png file, showing the line chart.");
423:                    e.getCause().printStackTrace();
424:                    return;
425:                } catch (Exception e) {
426:                    System.out
427:                            .println("** Error creating the objectbarchart.png file, showing the line chart.");
428:                    e.printStackTrace();
429:                    return;
430:                }
431:                System.out.println("successfull.");
432:            }
433:
434:            public static void makePlotTest() {
435:                System.out.println("** Creating Function Plot.");
436:                String title = "Plotting x^3";
437:
438:                int width = 640;
439:                int height = 480;
440:
441:                DefaultChartDataModel data = FunctionPlotter
442:                        .createChartDataModelInstance(-10, 10, 2000, "1/x");
443:                data.setAutoScale(true);
444:                DefaultChart c = new DefaultChart(data, title,
445:                        DefaultChart.LINEAR_X_LINEAR_Y);
446:                c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(),
447:                        data), 1);
448:
449:                c.setBounds(new Rectangle(0, 0, width, height));
450:                try {
451:                    ChartEncoder.createPNG(new FileOutputStream(System
452:                            .getProperty("user.home")
453:                            + "/plottest.png"), c);
454:                } catch (EncodingException e) {
455:                    System.out
456:                            .println("** Error creating the plottest.png file, showing the function plot.");
457:                    e.getCause().printStackTrace();
458:                    return;
459:                } catch (Exception e) {
460:                    System.out
461:                            .println("** Error creating the plottest.png file, showing the function plot.");
462:                    e.printStackTrace();
463:                    return;
464:                }
465:                System.out.println("successfull.");
466:            }
467:
468:            public static void makePlot2Test() {
469:                System.out.println("** Creating Plot Chart Test.");
470:
471:                double[] quadr = { 0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0 };
472:                double[] exp = { 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0 };
473:                double[] log = { 0.0, Math.log(1.0), Math.log(2.0),
474:                        Math.log(3.0), Math.log(4.0), Math.log(5.0),
475:                        Math.log(6.0) };
476:                double[] sqrt = { 0.0, Math.sqrt(1.0), Math.sqrt(2.0),
477:                        Math.sqrt(3.0), Math.sqrt(4.0), Math.sqrt(5.0),
478:                        Math.sqrt(6.0) };
479:                double[] columns = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
480:
481:                DefaultDataSet[] ds = new DefaultDataSet[5];
482:                ds[0] = new DefaultDataSet(ChartUtilities
483:                        .transformArray(new double[] { 0.0, 6.0 }),
484:                        ChartUtilities
485:                                .transformArray(new double[] { 0.0, 6.0 }),
486:                        CoordSystem.FIRST_YAXIS, "Linear Growth");
487:                ds[1] = new DefaultDataSet(
488:                        ChartUtilities.transformArray(quadr), ChartUtilities
489:                                .transformArray(columns),
490:                        CoordSystem.FIRST_YAXIS, "Quadratic Growth");
491:
492:                ds[2] = new DefaultDataSet(ChartUtilities.transformArray(exp),
493:                        ChartUtilities.transformArray(columns),
494:                        CoordSystem.FIRST_YAXIS, "Exponential Growth");
495:
496:                ds[3] = new DefaultDataSet(ChartUtilities.transformArray(log),
497:                        ChartUtilities.transformArray(columns),
498:                        CoordSystem.FIRST_YAXIS, "Logarithmic Growth");
499:
500:                ds[4] = new DefaultDataSet(ChartUtilities.transformArray(sqrt),
501:                        ChartUtilities.transformArray(columns),
502:                        CoordSystem.FIRST_YAXIS, "Square Root Growth");
503:
504:                String title = "Growth Factor Comparison";
505:
506:                int width = 640;
507:                int height = 480;
508:
509:                DefaultChartDataModel data = new DefaultChartDataModel(ds);
510:
511:                // Look at the next 3 lines:
512:                data.setAutoScale(true);
513:                DefaultChart c = new DefaultChart(data, title,
514:                        DefaultChart.LINEAR_X_LINEAR_Y);
515:                c.addChartRenderer(new PlotChartRenderer(c.getCoordSystem(),
516:                        data), 1);
517:
518:                c.setBounds(new Rectangle(0, 0, width, height));
519:
520:                try {
521:                    ChartEncoder.createPNG(new FileOutputStream(System
522:                            .getProperty("user.home")
523:                            + "/secondplot.png"), c);
524:                } catch (EncodingException e) {
525:                    System.out
526:                            .println("** Error creating the secondplot.png file, showing the plot chart.");
527:                    e.getCause().printStackTrace();
528:                    return;
529:                } catch (Exception e) {
530:                    System.out
531:                            .println("** Error creating the secondplot.png file, showing the second plot chart.");
532:                    e.printStackTrace();
533:                    return;
534:                }
535:                System.out.println("successfull.");
536:            }
537:
538:            public static void makeBarTest() {
539:                System.out.println("** Creating Bar Chart Plot.");
540:                int[][] model = { { 23, 43, 12 }, { 54, -15, 34 },
541:                        { 99, 32, 45 } };
542:
543:                String[] columns = { "1997", "1998", "1999" };
544:
545:                String[] rows = { "foobar.com", "@foo Ltd.", "bar.online" };
546:
547:                String title = "Average Growth 1997 - 1999";
548:
549:                int width = 640;
550:                int height = 480;
551:
552:                ObjectChartDataModel data = new ObjectChartDataModel(model,
553:                        columns, rows);
554:                DefaultChart c = new DefaultChart(data, title,
555:                        DefaultChart.LINEAR_X_LINEAR_Y);
556:                c.addChartRenderer(new BarChartRenderer(c.getCoordSystem(),
557:                        data), 1);
558:                c.setBounds(new Rectangle(0, 0, width, height));
559:                try {
560:                    ChartEncoder.createPNG(new FileOutputStream(System
561:                            .getProperty("user.home")
562:                            + "/simplebar.png"), c);
563:                } catch (EncodingException e) {
564:                    System.out
565:                            .println("** Error creating the simplebar.png file, showing the bar chart.");
566:                    e.getCause().printStackTrace();
567:                    return;
568:                } catch (Exception e) {
569:                    System.out
570:                            .println("** Error creating the simplebar.png file, showing the bar chart.");
571:                    e.printStackTrace();
572:                    return;
573:                }
574:                System.out.println("successfull.");
575:            }
576:
577:            public static void makeStackedBarTest() {
578:                System.out.println("** Creating Stacked Bar Chart Plot.");
579:                int[][] model = { { 23, 43, 12, 5, 20 },
580:                        { 54, -15, 34, 40, 45 }, { 99, -10, 45, -10, -25 } };
581:
582:                String[] columns = { "1997", "1998", "1999", "2000", "2001" };
583:
584:                String[] rows = { "foobar.com", "@foo Ltd.", "bar.online" };
585:
586:                String title = "Profit Shares 1997 - 2001";
587:
588:                int width = 640;
589:                int height = 480;
590:
591:                ObjectChartDataModel data = new ObjectChartDataModel(model,
592:                        columns, rows);
593:
594:                data.setChartDataModelConstraints(CoordSystem.FIRST_YAXIS,
595:                        new StackedChartDataModelConstraints(data,
596:                                CoordSystem.FIRST_YAXIS, false));
597:
598:                data.setChartDataModelConstraints(CoordSystem.SECOND_YAXIS,
599:                        new StackedChartDataModelConstraints(data,
600:                                CoordSystem.SECOND_YAXIS, false));
601:
602:                DefaultChart c = new DefaultChart(data, title,
603:                        DefaultChart.LINEAR_X_LINEAR_Y);
604:                c.addChartRenderer(new StackedBarChartRenderer(c
605:                        .getCoordSystem(), data), 1);
606:                c.setBounds(new Rectangle(0, 0, width, height));
607:                try {
608:                    ChartEncoder.createPNG(new FileOutputStream(System
609:                            .getProperty("user.home")
610:                            + "/stackedbar.png"), c);
611:                } catch (EncodingException e) {
612:                    System.out
613:                            .println("** Error creating the stackedbar.png file, showing the stacked bar chart.");
614:                    e.getCause().printStackTrace();
615:                    return;
616:                } catch (Exception e) {
617:                    System.out
618:                            .println("** Error creating the stackedbar.png file, showing the stacked bar chart.");
619:                    e.printStackTrace();
620:                    return;
621:                }
622:                System.out.println("successfull.");
623:            }
624:
625:            public static void makeManualBarTest() {
626:                System.out
627:                        .println("** Creating Bar Chart Plot with manual scaling.");
628:                int[][] model = { { 23, 43, 12 }, { 54, 10, 34 },
629:                        { 99, 32, 45 } };
630:
631:                String[] columns = { "1997", "1998", "1999" };
632:
633:                String[] rows = { "foobar.com", "@foo Ltd.", "bar.online" };
634:
635:                String title = "Average Growth 1997 - 1999";
636:
637:                int width = 640;
638:                int height = 480;
639:
640:                ObjectChartDataModel data = new ObjectChartDataModel(model,
641:                        columns, rows);
642:
643:                data.setManualScale(true);
644:                data.setMaximumValue(new Integer(100));
645:                data.setMinimumValue(new Integer(0));
646:
647:                DefaultChart c = new DefaultChart(data, title,
648:                        DefaultChart.LINEAR_X_LINEAR_Y);
649:                c.addChartRenderer(new BarChartRenderer(c.getCoordSystem(),
650:                        data), 1);
651:                c.setBounds(new Rectangle(0, 0, width, height));
652:                try {
653:                    ChartEncoder.createPNG(new FileOutputStream(System
654:                            .getProperty("user.home")
655:                            + "/manualbar.png"), c);
656:                } catch (EncodingException e) {
657:                    System.out
658:                            .println("** Error creating the manualbar.png file, showing the manually scaled bar chart.");
659:                    e.getCause().printStackTrace();
660:                    return;
661:                } catch (Exception e) {
662:                    System.out
663:                            .println("** Error creating the manualbar.png file, showing the manually scaled bar chart.");
664:                    e.printStackTrace();
665:                    return;
666:                }
667:                System.out.println("successfull.");
668:            }
669:
670:            public static void makeSimpleNegativeLineTest() {
671:                System.out.println("** Creating Simple Negative Line Test.");
672:                int[][] model = { { -200, -160, -80, 0 } };
673:
674:                double[] columns = { -100, -80, -40, 0 };
675:
676:                String[] rows = { "Negative sector" };
677:
678:                String title = "Just a Test";
679:
680:                int width = 640;
681:                int height = 480;
682:
683:                DefaultChartDataModel data = new DefaultChartDataModel(model,
684:                        columns, rows);
685:                //data.setAutoScale(true);
686:                DefaultChart c = new DefaultChart(data, title,
687:                        DefaultChart.LINEAR_X_LINEAR_Y);
688:                c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(),
689:                        data), 1);
690:
691:                c.setBounds(new Rectangle(0, 0, width, height));
692:
693:                try {
694:                    ChartEncoder.createEncodedImage(new FileOutputStream(System
695:                            .getProperty("user.home")
696:                            + "/neglinetest.png"), c, "png");
697:                } catch (EncodingException e) {
698:                    System.out
699:                            .println("** Error creating the neglinetest.png file, showing the simple negative line test.");
700:                    e.getCause().printStackTrace();
701:                    return;
702:                } catch (Exception e) {
703:                    System.out
704:                            .println("** Error creating the neglinetest.png file, showing the simple negative line test.");
705:                    e.printStackTrace();
706:                    return;
707:                }
708:                System.out.println("successfull.");
709:            }
710:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.