Source Code Cross Referenced for StackedBarChart.java in  » Chart » jCharts » org » krysalis » jcharts » axisChart » 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.axisChart 
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.axisChart;
034:
035:        import org.krysalis.jcharts.chartData.ChartDataException;
036:        import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet;
037:        import org.krysalis.jcharts.imageMap.RectMapArea;
038:        import org.krysalis.jcharts.properties.DataAxisProperties;
039:        import org.krysalis.jcharts.properties.StackedBarChartProperties;
040:
041:        import java.awt.*;
042:        import java.awt.geom.Rectangle2D;
043:
044:        /*************************************************************************************
045:         *
046:         * @author Nathaniel Auvil
047:         * @version $Id: StackedBarChart.java,v 1.1 2003/05/17 16:56:57 nathaniel_auvil Exp $
048:         ************************************************************************************/
049:        abstract class StackedBarChart {
050:
051:            /********************************************************************************************
052:             * Draws the chart
053:             *
054:             * @param axisChart
055:             *********************************************************************************************/
056:            static void render(AxisChart axisChart,
057:                    IAxisChartDataSet iAxisChartDataSet)
058:                    throws ChartDataException {
059:                Graphics2D g2d = axisChart.getGraphics2D();
060:                StackedBarChartProperties stackedBarChartProperties = (StackedBarChartProperties) iAxisChartDataSet
061:                        .getChartTypeProperties();
062:
063:                float barWidth;
064:
065:                //---y axis position on screen to start drawing.
066:                float startingX;
067:                float startingY;
068:                float width;
069:                float height;
070:
071:                DataAxisProperties dataAxisProperties;
072:
073:                if (axisChart.getAxisProperties().isPlotHorizontal()) {
074:                    dataAxisProperties = (DataAxisProperties) axisChart
075:                            .getAxisProperties().getXAxisProperties();
076:                    barWidth = axisChart.getYAxis().getScalePixelWidth()
077:                            * stackedBarChartProperties.getPercentage();
078:
079:                    startingX = axisChart.getXAxis().getZeroLineCoordinate();
080:                    startingY = axisChart.getYAxis().getLastTickY()
081:                            - (barWidth / 2);
082:                    width = 0;
083:                    height = barWidth;
084:                    Rectangle2D.Float rectangle = new Rectangle2D.Float(
085:                            startingX, startingY, width, height);
086:
087:                    StackedBarChart.horizontalPlot(axisChart,
088:                            iAxisChartDataSet, stackedBarChartProperties,
089:                            dataAxisProperties, g2d, rectangle, startingX);
090:                } else {
091:                    dataAxisProperties = (DataAxisProperties) axisChart
092:                            .getAxisProperties().getYAxisProperties();
093:                    barWidth = axisChart.getXAxis().getScalePixelWidth()
094:                            * stackedBarChartProperties.getPercentage();
095:
096:                    startingX = axisChart.getXAxis().getTickStart()
097:                            - (barWidth / 2);
098:                    startingY = axisChart.getYAxis().getZeroLineCoordinate();
099:                    width = barWidth;
100:                    height = 0;
101:                    Rectangle2D.Float rectangle = new Rectangle2D.Float(
102:                            startingX, startingY, width, height);
103:
104:                    StackedBarChart.verticalPlot(axisChart, iAxisChartDataSet,
105:                            stackedBarChartProperties, dataAxisProperties, g2d,
106:                            rectangle, startingY);
107:                }
108:            }
109:
110:            /**************************************************************************************
111:             *
112:             * @param axisChart
113:             * @param iAxisChartDataSet
114:             * @param stackedBarChartProperties
115:             * @param dataAxisProperties
116:             * @param g2d
117:             * @param rectangle
118:             * @param startingX
119:             **************************************************************************************/
120:            private static void horizontalPlot(AxisChart axisChart,
121:                    IAxisChartDataSet iAxisChartDataSet,
122:                    StackedBarChartProperties stackedBarChartProperties,
123:                    DataAxisProperties dataAxisProperties, Graphics2D g2d,
124:                    Rectangle2D.Float rectangle, float startingX)
125:                    throws ChartDataException {
126:                int imageMapLabelIndex = axisChart.getYAxis()
127:                        .getNumberOfScaleItems() - 1;
128:
129:                //LOOP
130:                //---initial postion of each line.
131:                for (int i = 0; i < iAxisChartDataSet.getNumberOfDataItems(); i++) {
132:                    //---draw each bar in stack
133:                    for (int j = 0; j < iAxisChartDataSet.getNumberOfDataSets(); j++) {
134:                        //---if segment has a zero value, draw nothing.
135:                        if (iAxisChartDataSet.getValue(j, i) == 0) {
136:                            continue;
137:                        } else if (iAxisChartDataSet.getValue(j, i) < 0) {
138:                            //todo i think we could support this, but it can wait
139:                            throw new ChartDataException(
140:                                    "Negative values in Stacked Bar charts are not supported yet... Coming soon...");
141:                            /*
142:                             rectangle.x = axisChart.getXAxis().computeAxisCoordinate( axisChart.getXAxis().getOrigin(),
143:                             iAxisChartDataSet.getValue( 0, i ),
144:                             dataAxisProperties.getScaleCalculator().getMinValue() );
145:                             rectangle.width = startingX - rectangle.x;
146:                             */
147:                        } else {
148:
149:                            rectangle.width = BarChart
150:                                    .computeScaleHeightOfValue(
151:                                            iAxisChartDataSet.getValue(j, i),
152:                                            axisChart.getXAxis()
153:                                                    .getOneUnitPixelSize());
154:
155:                            //rectangle.x = startingX;
156:                            //rectangle.width = BarChart.computeScaleHeightOfValue( iAxisChartDataSet.getValue( j, i ), axisChart.getXAxis().getOneUnitPixelSize() );
157:                        }
158:
159:                        g2d.setPaint(iAxisChartDataSet.getPaint(j));
160:                        g2d.fill(rectangle);
161:
162:                        if (stackedBarChartProperties.getShowOutlinesFlag()) {
163:                            stackedBarChartProperties.getBarOutlineStroke()
164:                                    .draw(g2d, rectangle);
165:                        }
166:
167:                        //---if we are generating an ImageMap, store the image coordinates
168:                        if (axisChart.getGenerateImageMapFlag()) {
169:                            String label = null;
170:                            if (axisChart.getYAxis().getAxisLabelsGroup() != null) {
171:                                label = axisChart.getYAxis()
172:                                        .getAxisLabelsGroup().getTextTag(
173:                                                imageMapLabelIndex).getText();
174:                            }
175:                            axisChart.getImageMap().addImageMapArea(
176:                                    new RectMapArea(rectangle,
177:                                            iAxisChartDataSet.getValue(j, i),
178:                                            label, iAxisChartDataSet
179:                                                    .getLegendLabel(j)));
180:                        }
181:
182:                        rectangle.x += rectangle.width;
183:                    }
184:
185:                    imageMapLabelIndex--;
186:
187:                    rectangle.y += axisChart.getYAxis().getScalePixelWidth();
188:                    rectangle.x = startingX;
189:                }
190:            }
191:
192:            /**************************************************************************************
193:             *
194:             * @param axisChart
195:             * @param iAxisChartDataSet
196:             * @param stackedBarChartProperties
197:             * @param dataAxisProperties
198:             * @param g2d
199:             * @param rectangle
200:             * @param startingY
201:             **************************************************************************************/
202:            private static void verticalPlot(AxisChart axisChart,
203:                    IAxisChartDataSet iAxisChartDataSet,
204:                    StackedBarChartProperties stackedBarChartProperties,
205:                    DataAxisProperties dataAxisProperties, Graphics2D g2d,
206:                    Rectangle2D.Float rectangle, float startingY) {
207:                //IDataSeries iDataSeries= (IDataSeries) axisChart.getIAxisDataSeries();
208:
209:                //LOOP
210:                //---initial postion of each line.
211:                for (int i = 0; i < iAxisChartDataSet.getNumberOfDataItems(); i++) {
212:                    //---draw each bar in stack
213:                    for (int j = 0; j < iAxisChartDataSet.getNumberOfDataSets(); j++) {
214:                        //---if segment has a zero value, draw nothing.
215:                        if (iAxisChartDataSet.getValue(j, i) == 0) {
216:                            continue;
217:                        }
218:
219:                        rectangle.height = BarChart.computeScaleHeightOfValue(
220:                                iAxisChartDataSet.getValue(j, i), axisChart
221:                                        .getYAxis().getOneUnitPixelSize());
222:                        rectangle.y -= rectangle.height;
223:
224:                        g2d.setPaint(iAxisChartDataSet.getPaint(j));
225:                        g2d.fill(rectangle);
226:
227:                        if (stackedBarChartProperties.getShowOutlinesFlag()) {
228:                            stackedBarChartProperties.getBarOutlineStroke()
229:                                    .draw(g2d, rectangle);
230:                        }
231:
232:                        //---if we are generating an ImageMap, store the image coordinates
233:                        if (axisChart.getGenerateImageMapFlag()) {
234:                            String label = null;
235:                            if (axisChart.getXAxis().getAxisLabelsGroup() != null) {
236:                                label = axisChart.getXAxis()
237:                                        .getAxisLabelsGroup().getTextTag(i)
238:                                        .getText();
239:                            }
240:                            axisChart.getImageMap().addImageMapArea(
241:                                    new RectMapArea(rectangle,
242:                                            iAxisChartDataSet.getValue(j, i),
243:                                            label, iAxisChartDataSet
244:                                                    .getLegendLabel(j)));
245:                        }
246:
247:                    }
248:
249:                    rectangle.x += axisChart.getXAxis().getScalePixelWidth();
250:                    rectangle.y = startingY;
251:                }
252:            }
253:
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.