Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ExcelChart.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General Public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016 
00017         You should have received a copy of the GNU General Public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import javax.xml.transform.*;
00023 import javax.xml.transform.stream.*;
00024 import java.sql.*;
00025 import java.io.*;
00026 import java.util.*;
00027 import javax.servlet.http.*;
00028 import javax.servlet.jsp.*;
00029 
00060 public class ExcelChart {
00061 
00062         public static final int Combo = -1  ;  
00063         public static final int ColumnClustered = 0  ;  
00064         public static final int ColumnStacked = 1  ;  
00065         public static final int ColumnStacked100 = 2  ;  
00066         public static final int BarClustered = 3  ;  
00067         public static final int BarStacked = 4  ;  
00068         public static final int BarStacked100 = 5  ;  
00069         public static final int Line = 6  ;  
00070         public static final int LineMarkers = 7  ;  
00071         public static final int LineStacked = 8  ;  
00072         public static final int LineStackedMarkers = 9  ;  
00073         public static final int LineStacked100 = 10  ;  
00074         public static final int LineStacked100Markers = 11  ;  
00075         public static final int SmoothLine = 12  ;  
00076         public static final int SmoothLineMarkers = 13  ;  
00077         public static final int SmoothLineStacked = 14  ;  
00078         public static final int SmoothLineStackedMarkers = 15  ;  
00079         public static final int SmoothLineStacked100 = 16  ;  
00080         public static final int SmoothLineStacked100Markers = 17  ;  
00081         public static final int Pie = 18  ;  
00082         public static final int PieExploded = 19  ;  
00083         public static final int PieStacked = 20  ;  
00084         public static final int ScatterMarkers = 21  ;  
00085         public static final int ScatterSmoothLineMarkers = 22  ;  
00086         public static final int ScatterSmoothLine = 23  ;  
00087         public static final int ScatterLineMarkers = 24  ;  
00088         public static final int ScatterLine = 25  ;  
00089         public static final int ScatterLineFilled = 26  ;  
00090         public static final int Bubble = 27  ;  
00091         public static final int BubbleLine = 28  ;  
00092         public static final int Area = 29  ;  
00093         public static final int AreaStacked = 30  ;  
00094         public static final int AreaStacked100 = 31  ;  
00095         public static final int Doughnut = 32  ;  
00096         public static final int DoughnutExploded = 33  ;  
00097         public static final int RadarLine = 34  ;  
00098         public static final int RadarLineMarkers = 35  ;  
00099         public static final int RadarLineFilled = 36  ;  
00100         public static final int RadarSmoothLine = 37  ;  
00101         public static final int RadarSmoothLineMarkers = 38  ;  
00102         public static final int StockHLC = 39  ;  
00103         public static final int StockOHLC = 40  ;  
00104         public static final int PolarMarkers = 41  ;  
00105         public static final int PolarLine = 42  ;  
00106         public static final int PolarLineMarkers = 43  ;  
00107         public static final int PolarSmoothLine = 44  ;  
00108         public static final int PolarSmoothLineMarkers = 45  ;  
00109 
00110         private StringWriter sw = new StringWriter();
00111         private PrintWriter out = new PrintWriter(sw);
00112         private String name = null;
00113         private List items = new ArrayList();
00114         private int instance = 0;
00115         public String width = "99%";
00116         public String height = "500px";
00117   
00121         public ExcelChart (String name) throws java.io.IOException {
00122                 this(name,0);
00123         }
00124 
00128         public ExcelChart (String name, int instance) throws java.io.IOException {
00129                 this.name = name; 
00130                 this.instance = instance;
00131         }
00135         public void render (OutputStream out) throws Exception {
00136                 PrintWriter ow = new PrintWriter(new OutputStreamWriter(out));
00137                 ow.print("<object ");
00138                 ow.print(" id=\""+name+"\" "); 
00139                 ow.print(" classid=\"CLSID:0002E500-0000-0000-C000-000000000046\"");   
00140                 ow.print(" style=\"width: "+width+"; height: "+height+";\">");
00141                 ow.println("</object>");
00142                 ow.println("");
00143                 ow.println(sw.getBuffer().toString());
00144                 ow.println("");
00145                 ow.println("<script language=\"vbs\">");
00146                 for (Iterator i = items.iterator(); i.hasNext(); ) {
00147                         ow.println("  " + i.next() + "()");
00148                 }
00149                 ow.println("</script>");
00150                 ow.println("");
00151                 ow.flush();
00152         }
00153 
00157         public void draw(String chartName, String dataSource, ArrayList series, int chartType) throws java.io.IOException { 
00158                 items.add(chartName) ; 
00159 
00160                 out.println("<script language=\"VBScript\">"); 
00161                 out.println("Sub "+chartName+"()");  
00162                 if (instance == 0 ) { out.println(name + ".Clear "); }
00163                 out.println(name + ".Charts.Add ");
00164                 out.println("Set c = " + name + ".Constants ");
00165                 if (instance == 0 ) { out.println(name + ".DataSource = " + dataSource); }
00166                 out.println(name+".Charts("+instance+").Type = " + chartType ); 
00167 
00168                 int k = 0 ; 
00169                 for (Iterator i = series.iterator(); i.hasNext();) {
00170                         out.println( name +  ".Charts("+instance+").SeriesCollection.Add" ); 
00171                         List o = (ArrayList) i.next() ; 
00172                         out.println(name + ".Charts("+instance+").SeriesCollection("+k+").SetData c.chDimSeriesNames, 0, \"" + o.get(0)+"\"" ); 
00173                         out.println(name + ".Charts("+instance+").SeriesCollection("+k+").SetData c.chDimCategories, 0, \""+ o.get(1)+ "\"" ); 
00174                         out.println(name + ".Charts("+instance+").SeriesCollection("+k+").SetData c.chDimValues, 0, \"" + o.get(2)+"\"" );
00175                         k++; 
00176                 }
00177                 out.println(name + ".Charts("+instance+").HasLegend = True "); 
00178                 out.println("End Sub \n </script>"); 
00179         }
00180 
00181 }

Generated on Mon Jul 14 17:19:20 2003 for SOSC by doxygen1.2.15