KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > GenericChart


1 package dinamica;
2
3 /**
4  * Generic Transaction used for server-side Chart Actions.
5  * This Transaction class will read some specific elements from
6  * config.xml in order to set the values of the chart configuration
7  * recordset used by the ChartOutput class. This Transaction will save
8  * you the effort of writing a class for the sole purpose of configuring
9  * a chart, instead you will use config.xml to provide chart properties.
10  * <br><br>
11  * (c) 2004 Martin Cordova<br>
12  * This code is released under the LGPL license<br>
13  * Dinamica Framework - http://www.martincordova.com
14  * @author Martin Cordova (dinamica@martincordova.com)
15  * */

16 public class GenericChart extends GenericTransaction
17 {
18
19     /* (non-Javadoc)
20      * @see dinamica.GenericTransaction#service(dinamica.Recordset)
21      */

22     public int service(Recordset inputParams) throws Throwable JavaDoc
23     {
24         
25         //reuse superclass code
26
super.service(inputParams);
27         
28         //get chart config recordset
29
Recordset rs = getChartInfoRecordset();
30         
31         //read chart properties from config.xml
32
String JavaDoc session = getConfig().getConfigValue("//chart/session");
33         String JavaDoc imageid = getConfig().getConfigValue("//chart/image-id");
34         String JavaDoc plugin = getConfig().getConfigValue("//chart/plugin");
35         Integer JavaDoc width = new Integer JavaDoc(getConfig().getConfigValue("//chart/width"));
36         Integer JavaDoc height = new Integer JavaDoc(getConfig().getConfigValue("//chart/height"));
37         String JavaDoc title = getConfig().getConfigValue("//chart/title");
38         String JavaDoc titlex = getConfig().getConfigValue("//chart/title-x");
39         String JavaDoc titley = getConfig().getConfigValue("//chart/title-y");
40         String JavaDoc series = getConfig().getConfigValue("//chart/title-series");
41         String JavaDoc recordset = getConfig().getConfigValue("//chart/recordset");
42         String JavaDoc fieldx = getConfig().getConfigValue("//chart/field-x");
43         String JavaDoc fieldy = getConfig().getConfigValue("//chart/field-y");
44         String JavaDoc color = getConfig().getConfigValue("//chart/color", null);
45         
46         //set chart properties inr ecordset
47
rs.addNew();
48         rs.setValue("title", title);
49         rs.setValue("title-x", titlex); //irrelevant for pie charts
50
rs.setValue("title-y", titley); //irrelevant for pie charts
51
rs.setValue("column-x", fieldx);
52         rs.setValue("column-y", fieldy); //if multiseries then type multiple column names separated by ";"
53
rs.setValue("title-series", series); //no series - otherwise set label names separated by ";"
54
rs.setValue("width", width); //in pixels
55
rs.setValue("height", height); //in pixels
56
rs.setValue("data", recordset); //recordset that must be stored in session attribute
57

58         /* select the type of chart you want to use */
59         rs.setValue("chart-plugin", plugin);
60         
61         //added on april-6-2004 - persist image bytes in session attribute
62
//to be reused by PDF generators
63
rs.setValue("session", session);
64         rs.setValue("image-id", imageid);
65
66         //added on july-19-2005 - default color for charts
67
//with 1 series only (applies to bar, line and area only)
68
rs.setValue("color", color);
69
70         /* publish recordset to be consumed by output module */
71         publish("chartinfo", rs);
72         
73         //return OK
74
return 0;
75         
76     }
77
78 }
79
Popular Tags