Source Code Cross Referenced for AxisChartsGuide.java in  » Chart » jCharts » org » krysalis » jcharts » demo » userGuide » 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 » jCharts » org.krysalis.jcharts.demo.userGuide 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***********************************************************************************************
002:         * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003:         *
004:         * Redistribution and use of this software and associated documentation ("Software"), with or
005:         * without modification, are permitted provided that the following conditions are met:
006:         *
007:         * 1. Redistributions of source code must retain copyright statements and notices.
008:         * 	Redistributions must also contain a copy of this document.
009:         *
010:         * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011:         * 	conditions and the following disclaimer in the documentation and/or other materials
012:         * 	provided with the distribution.
013:         *
014:         * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015:         * 	products derived from this Software without prior written permission of Nathaniel G.
016:         * 	Auvil.  For written permission, please contact nathaniel_auvil@users.sourceforge.net
017:         *
018:         * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019:         * 	in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020:         * 	registered trademark of Nathaniel G. Auvil.
021:         *
022:         * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023:         *
024:         * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025:         * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
027:         * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030:         * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032:         * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033:         ************************************************************************************************/package org.krysalis.jcharts.demo.userGuide;
034:
035:        import org.krysalis.jcharts.chartData.DataSeries;
036:        import org.krysalis.jcharts.chartData.ChartDataException;
037:        import org.krysalis.jcharts.chartData.AxisChartDataSet;
038:        import org.krysalis.jcharts.axisChart.AxisChart;
039:        import org.krysalis.jcharts.properties.AxisProperties;
040:        import org.krysalis.jcharts.properties.AreaChartProperties;
041:        import org.krysalis.jcharts.properties.ChartProperties;
042:        import org.krysalis.jcharts.properties.LegendProperties;
043:        import org.krysalis.jcharts.properties.PropertyException;
044:        import org.krysalis.jcharts.properties.BarChartProperties;
045:        import org.krysalis.jcharts.properties.DataAxisProperties;
046:        import org.krysalis.jcharts.properties.AxisTypeProperties;
047:        import org.krysalis.jcharts.properties.ChartTypeProperties;
048:        import org.krysalis.jcharts.properties.util.ChartStroke;
049:        import org.krysalis.jcharts.properties.util.ChartFont;
050:        import org.krysalis.jcharts.types.ChartType;
051:        import org.krysalis.jcharts.test.TestDataGenerator;
052:
053:        import java.awt.*;
054:
055:        /*************************************************************************************
056:         *
057:         * @author Nathaniel Auvil
058:         * @version $Id: AxisChartsGuide.java,v 1.3 2003/07/05 13:24:35 nathaniel_auvil Exp $
059:         ************************************************************************************/
060:        public class AxisChartsGuide extends UserGuideBase {
061:            public static final int width = 500;
062:            public static final int height = 320;
063:
064:            /*****************************************************************************************
065:             *
066:             *
067:             ******************************************************************************************/
068:            private AxisChart getChart(AxisProperties axisProperties)
069:                    throws ChartDataException {
070:                String[] xAxisLabels = { "1998", "1999", "2000", "2001",
071:                        "2002", "2003", "2004" };
072:                String xAxisTitle = "Years";
073:                String yAxisTitle = "Problems";
074:                String title = "Micro$oft at Work";
075:                DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
076:                        yAxisTitle, title);
077:
078:                dataSeries.addIAxisPlotDataSet(AxisChartsGuide
079:                        .createAxisChartDataSet(ChartType.AREA,
080:                                new AreaChartProperties(), 200, 5000));
081:
082:                ChartProperties chartProperties = new ChartProperties();
083:                LegendProperties legendProperties = new LegendProperties();
084:
085:                AxisChart axisChart = new AxisChart(dataSeries,
086:                        chartProperties, axisProperties, legendProperties,
087:                        AxisChartsGuide.width, AxisChartsGuide.height);
088:
089:                return axisChart;
090:            }
091:
092:            /*****************************************************************************************
093:             * Tests a 'real' data set and usage.
094:             *
095:             * @throws ChartDataException
096:             ******************************************************************************************/
097:            public void run() throws ChartDataException, PropertyException {
098:                this .horizontalPlots();
099:
100:                this .rounding();
101:                this .userDefinedScale();
102:
103:                this .numberOfItemsOnYAxis();
104:                this .gridLines();
105:
106:                this .dollarSigns();
107:                this .commas();
108:
109:                this .axisBackgroundPaint();
110:                this .axisTitles();
111:
112:                this .zeroLine();
113:                this .scaleFont();
114:
115:                this .tickMarks();
116:
117:                this .verticalXAxisLabels();
118:            }
119:
120:            /*****************************************************************************************/
121:            private void horizontalPlots() throws ChartDataException {
122:                AxisProperties axisProperties = new AxisProperties(true);
123:
124:                double[][] data = { { 3444d, 1506.3d, 2777d, 2550.345d,
125:                        659.667d, 950.6644d, 4500.3453d, 1200.67583d } };
126:                String[] xAxisLabels = { "January", "Febuary", "March",
127:                        "April", "May", "June", "July", "August" };
128:                String[] legendLabels = { "New Bugs in Windows Per Month" };
129:                Paint[] paints = { Color.blue };
130:                String xAxisTitle = "Months";
131:                String yAxisTitle = "Bugs";
132:                String title = "Micro$oft At Work";
133:
134:                DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
135:                        yAxisTitle, title);
136:                AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
137:                        legendLabels, paints, ChartType.BAR,
138:                        new BarChartProperties());
139:
140:                dataSeries.addIAxisPlotDataSet(axisChartDataSet);
141:
142:                AxisChart axisChart = new AxisChart(dataSeries,
143:                        new ChartProperties(), axisProperties,
144:                        new LegendProperties(), width, height);
145:                super .exportImage(axisChart, "horizontalPlots");
146:            }
147:
148:            /*****************************************************************************************/
149:            private void rounding() throws ChartDataException {
150:                AxisProperties axisProperties = new AxisProperties();
151:
152:                DataAxisProperties dataAxisProperties = (DataAxisProperties) axisProperties
153:                        .getYAxisProperties();
154:                dataAxisProperties.setRoundToNearest(-2);
155:
156:                super 
157:                        .exportImage(this .getChart(axisProperties),
158:                                "axisRounding");
159:            }
160:
161:            /*****************************************************************************************/
162:            private void userDefinedScale() throws ChartDataException,
163:                    PropertyException {
164:                AxisProperties axisProperties = new AxisProperties();
165:
166:                DataAxisProperties dataAxisProperties = (DataAxisProperties) axisProperties
167:                        .getYAxisProperties();
168:                dataAxisProperties.setUserDefinedScale(-2000, 850);
169:                dataAxisProperties.setRoundToNearest(0);
170:
171:                super .exportImage(this .getChart(axisProperties),
172:                        "userDefinedScale");
173:            }
174:
175:            //todo what about ScaleCalculator implementations?
176:
177:            /*****************************************************************************************/
178:            private void numberOfItemsOnYAxis() throws ChartDataException {
179:                AxisProperties axisProperties = new AxisProperties();
180:                DataAxisProperties dataAxisProperties = (DataAxisProperties) axisProperties
181:                        .getYAxisProperties();
182:                dataAxisProperties.setNumItems(8);
183:
184:                super .exportImage(this .getChart(axisProperties),
185:                        "numberOfItemsOnYAxis");
186:            }
187:
188:            /*****************************************************************************************/
189:            private void gridLines() throws ChartDataException {
190:                AxisProperties axisProperties = new AxisProperties();
191:
192:                ChartStroke xAxisGridLines = new ChartStroke(new BasicStroke(
193:                        1.0f), Color.red);
194:                axisProperties.getXAxisProperties().setGridLineChartStroke(
195:                        xAxisGridLines);
196:                axisProperties.getXAxisProperties().setShowGridLines(
197:                        AxisTypeProperties.GRID_LINES_ONLY_WITH_LABELS);
198:
199:                axisProperties.getYAxisProperties().setShowGridLines(
200:                        AxisTypeProperties.GRID_LINES_NONE);
201:
202:                double[][] data = { { 3444d, 1506.3d, 2777d, 2550.345d,
203:                        659.667d, 950.6644d, 4500.3453d, 1200.67583d,
204:                        3000.4354d, 1268.0001d, 2444.432d, 5003d } };
205:                String[] xAxisLabels = { "January", "Febuary", "March",
206:                        "April", "May", "June", "July", "August", "September",
207:                        "October", "November", "December" };
208:                String[] legendLabels = { "New Bugs in Windows Per Month" };
209:                Paint[] paints = { Color.blue };
210:                String xAxisTitle = "Months";
211:                String yAxisTitle = "Bugs";
212:                String title = "Micro$oft At Work";
213:
214:                DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
215:                        yAxisTitle, title);
216:                AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
217:                        legendLabels, paints, ChartType.AREA,
218:                        new AreaChartProperties());
219:
220:                dataSeries.addIAxisPlotDataSet(axisChartDataSet);
221:
222:                AxisChart axisChart = new AxisChart(dataSeries,
223:                        new ChartProperties(), axisProperties,
224:                        new LegendProperties(), width, height);
225:                super .exportImage(axisChart, "gridLines");
226:            }
227:
228:            /*****************************************************************************************/
229:            private void dollarSigns() throws ChartDataException {
230:                AxisProperties axisProperties = new AxisProperties();
231:                DataAxisProperties dataAxisProperties = (DataAxisProperties) axisProperties
232:                        .getYAxisProperties();
233:                dataAxisProperties.setUseDollarSigns(true);
234:                super .exportImage(this .getChart(axisProperties), "dollarSigns");
235:            }
236:
237:            /*****************************************************************************************/
238:            private void commas() throws ChartDataException {
239:                AxisProperties axisProperties = new AxisProperties();
240:                DataAxisProperties dataAxisProperties = (DataAxisProperties) axisProperties
241:                        .getYAxisProperties();
242:                dataAxisProperties.setUseCommas(false);
243:                super .exportImage(this .getChart(axisProperties), "commas");
244:            }
245:
246:            /*****************************************************************************************/
247:            private void axisBackgroundPaint() throws ChartDataException {
248:                AxisProperties axisProperties = new AxisProperties();
249:                axisProperties.setBackgroundPaint(Color.yellow);
250:                super .exportImage(this .getChart(axisProperties),
251:                        "axisBackground");
252:            }
253:
254:            /*****************************************************************************************/
255:            private void axisTitles() throws ChartDataException {
256:                double[][] data = { { 3444d, 1506.3d, 2777d, 2550.345d,
257:                        659.667d, 950.6644d, 4500.3453d, 1200.67583d,
258:                        3000.4354d, 1268.0001d, 2444.432d, 5003d } };
259:                String[] xAxisLabels = { "January", "Febuary", "March",
260:                        "April", "May", "June", "July", "August", "September",
261:                        "October", "November", "December" };
262:                String[] legendLabels = { "New Bugs in Windows Per Month" };
263:                Paint[] paints = { Color.blue };
264:                String xAxisTitle = "Months";
265:                String yAxisTitle = "Bugs";
266:                String title = "Micro$oft At Work";
267:                AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
268:                        legendLabels, paints, ChartType.AREA,
269:                        new AreaChartProperties());
270:
271:                DataSeries dataSeries = new DataSeries(xAxisLabels, null,
272:                        yAxisTitle, title);
273:                dataSeries.addIAxisPlotDataSet(axisChartDataSet);
274:
275:                AxisChart axisChart = new AxisChart(dataSeries,
276:                        new ChartProperties(), new AxisProperties(),
277:                        new LegendProperties(), width, height);
278:                super .exportImage(axisChart, "axisTitles");
279:
280:                AxisProperties axisProperties = new AxisProperties();
281:                ChartFont yAxisFont = new ChartFont(new Font("Arial Narrow",
282:                        Font.BOLD, 14), Color.blue);
283:                axisProperties.getYAxisProperties().setAxisTitleChartFont(
284:                        yAxisFont);
285:
286:                axisChart = new AxisChart(dataSeries, new ChartProperties(),
287:                        axisProperties, new LegendProperties(), width, height);
288:                super .exportImage(axisChart, "axisTitleFont");
289:            }
290:
291:            /*****************************************************************************************/
292:            private void zeroLine() throws ChartDataException,
293:                    PropertyException {
294:                AxisProperties axisProperties = new AxisProperties();
295:
296:                DataAxisProperties dataAxisProperties = (DataAxisProperties) axisProperties
297:                        .getYAxisProperties();
298:                dataAxisProperties.setUserDefinedScale(-2000, 1200);
299:                dataAxisProperties.setShowZeroLine(false);
300:                super .exportImage(this .getChart(axisProperties), "noZeroLine");
301:
302:                dataAxisProperties.setShowZeroLine(true);
303:
304:                BasicStroke stroke = new BasicStroke(1f, BasicStroke.CAP_ROUND,
305:                        BasicStroke.JOIN_ROUND, 5f, new float[] { 5f, 5f, 10f,
306:                                5f }, 4f);
307:                ChartStroke zeroLineChartStroke = new ChartStroke(stroke,
308:                        Color.red);
309:                dataAxisProperties.setZeroLineChartStroke(zeroLineChartStroke);
310:                super .exportImage(this .getChart(axisProperties),
311:                        "zeroLinePaintStroke");
312:            }
313:
314:            /*****************************************************************************************/
315:            private void scaleFont() throws ChartDataException {
316:                AxisProperties axisProperties = new AxisProperties();
317:                ChartFont xScaleChartFont = new ChartFont(new Font(
318:                        "Georgia Negreta cursiva", Font.PLAIN, 13), Color.blue);
319:                axisProperties.getXAxisProperties().setScaleChartFont(
320:                        xScaleChartFont);
321:                super .exportImage(this .getChart(axisProperties), "scaleFont");
322:            }
323:
324:            /*****************************************************************************************/
325:            private void verticalXAxisLabels() throws ChartDataException {
326:                AxisProperties axisProperties = new AxisProperties();
327:                axisProperties.setXAxisLabelsAreVertical(true);
328:                super .exportImage(this .getChart(axisProperties),
329:                        "verticalXAxisLabels");
330:            }
331:
332:            /*****************************************************************************************/
333:            private void tickMarks() throws ChartDataException {
334:                AxisProperties axisProperties = new AxisProperties();
335:                axisProperties.getXAxisProperties().setShowTicks(
336:                        AxisTypeProperties.TICKS_ONLY_WITH_LABELS);
337:                super .exportImage(this .getChart(axisProperties),
338:                        "ticksWithLabels");
339:
340:                axisProperties = new AxisProperties();
341:                axisProperties.getXAxisProperties().setShowTicks(
342:                        AxisTypeProperties.TICKS_NONE);
343:                super .exportImage(this .getChart(axisProperties), "noTicks");
344:
345:                axisProperties = new AxisProperties();
346:                ChartStroke xTicks = new ChartStroke(new BasicStroke(1.0f),
347:                        Color.blue);
348:                axisProperties.getXAxisProperties().setTickChartStroke(xTicks);
349:
350:                ChartStroke yTicks = new ChartStroke(new BasicStroke(1.0f),
351:                        Color.green);
352:                axisProperties.getYAxisProperties().setTickChartStroke(yTicks);
353:
354:                super .exportImage(this .getChart(axisProperties), "tickColors");
355:
356:                axisProperties = new AxisProperties();
357:                ChartStroke xTickStroke = new ChartStroke(
358:                        new BasicStroke(2.0f), Color.blue);
359:                axisProperties.getXAxisProperties().setTickChartStroke(
360:                        xTickStroke);
361:                super .exportImage(this .getChart(axisProperties), "tickStroke");
362:            }
363:
364:            /*****************************************************************************************************
365:             *
366:             *
367:             *****************************************************************************************************/
368:            public static final DataSeries createDataSeries() {
369:                String[] xAxisLabels = { "1998", "1999", "2000", "2001",
370:                        "2002", "2003", "2004" };
371:                String xAxisTitle = "Years";
372:                String yAxisTitle = "Problems";
373:                String title = null;
374:
375:                return new DataSeries(xAxisLabels, xAxisTitle, yAxisTitle,
376:                        "Micro$oft At Work");
377:            }
378:
379:            /*****************************************************************************************
380:             *
381:             *
382:             * @param minValue
383:             * @param maxValue
384:             * @return AxisChartDataSet
385:             ******************************************************************************************/
386:            public static final AxisChartDataSet createAxisChartDataSet(
387:                    ChartType chartType,
388:                    ChartTypeProperties chartTypeProperties,
389:                    int numberOfDataSets, String[] legendLabels, int minValue,
390:                    int maxValue) throws ChartDataException {
391:                double[][] data = TestDataGenerator.getRandomNumbers(
392:                        numberOfDataSets, 7, minValue, maxValue);
393:                Paint[] paints = TestDataGenerator
394:                        .getRandomPaints(numberOfDataSets);
395:
396:                return new AxisChartDataSet(data, legendLabels, paints,
397:                        chartType, chartTypeProperties);
398:            }
399:
400:            /*****************************************************************************************
401:             *
402:             *
403:             * @param minValue
404:             * @param maxValue
405:             * @return AxisChartDataSet
406:             ******************************************************************************************/
407:            public static final AxisChartDataSet createAxisChartDataSet(
408:                    ChartType chartType,
409:                    ChartTypeProperties chartTypeProperties, int minValue,
410:                    int maxValue) throws ChartDataException {
411:                double[][] data = TestDataGenerator.getRandomNumbers(1, 7,
412:                        minValue, maxValue);
413:                String[] legendLabels = { "Bugs" };
414:                Paint[] paints = TestDataGenerator.getRandomPaints(1);
415:
416:                return new AxisChartDataSet(data, legendLabels, paints,
417:                        chartType, chartTypeProperties);
418:            }
419:
420:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.