01: package dinamica;
02:
03: /**
04: * Generic Transaction used for server-side Chart Actions.
05: * This Transaction class will read some specific elements from
06: * config.xml in order to set the values of the chart configuration
07: * recordset used by the ChartOutput class. This Transaction will save
08: * you the effort of writing a class for the sole purpose of configuring
09: * a chart, instead you will use config.xml to provide chart properties.
10: * <br><br>
11: * (c) 2004-2008 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: /* (non-Javadoc)
19: * @see dinamica.GenericTransaction#service(dinamica.Recordset)
20: */
21: public int service(Recordset inputParams) throws Throwable {
22:
23: //reuse superclass code
24: super .service(inputParams);
25:
26: //get chart config recordset
27: Recordset rs = getChartInfoRecordset();
28:
29: fillChartConfig(rs);
30:
31: /* publish recordset to be consumed by output module */
32: publish("chartinfo", rs);
33:
34: //return OK
35: return 0;
36:
37: }
38:
39: /**
40: * Lee la configuracion basica del plugin de charts, este metodo
41: * puede ser llamado por subclases para que lea la configuracion y luego
42: * las subclases leen parametros adicionales que ellas mismas definieron
43: * al hacer un override del metodo getChartInfoRecordset().<br>
44: * <br>PATCH 2008-03-06 mejorar la extensibilidad del framework para soportar
45: * nuevos parametros de configuracion de charts no previstos por el framework.
46: * @param rs Recordset retornado por el metodo getChartInfoRecordset() de la clase GenericTransaction
47: * @throws Throwable
48: */
49: public void fillChartConfig(Recordset rs) throws Throwable {
50:
51: //read chart properties from config.xml
52: String session = getConfig().getConfigValue("//chart/session");
53: String imageid = getConfig().getConfigValue("//chart/image-id");
54: String plugin = getConfig().getConfigValue("//chart/plugin");
55: Integer width = new Integer(getConfig().getConfigValue(
56: "//chart/width"));
57: Integer height = new Integer(getConfig().getConfigValue(
58: "//chart/height"));
59: String title = getConfig().getConfigValue("//chart/title");
60: String titlex = getConfig().getConfigValue("//chart/title-x");
61: String titley = getConfig().getConfigValue("//chart/title-y");
62: String series = getConfig().getConfigValue(
63: "//chart/title-series");
64: String recordset = getConfig().getConfigValue(
65: "//chart/recordset");
66: String fieldx = getConfig().getConfigValue("//chart/field-x");
67: String fieldy = getConfig().getConfigValue("//chart/field-y");
68: String color = getConfig()
69: .getConfigValue("//chart/color", null);
70:
71: //set chart properties using a recordset
72: rs.addNew();
73: rs.setValue("title", title);
74: rs.setValue("title-x", titlex); //irrelevant for pie charts
75: rs.setValue("title-y", titley); //irrelevant for pie charts
76: rs.setValue("column-x", fieldx);
77: rs.setValue("column-y", fieldy); //if multiseries then type multiple column names separated by ";"
78: rs.setValue("title-series", series); //no series - otherwise set label names separated by ";"
79: rs.setValue("width", width); //in pixels
80: rs.setValue("height", height); //in pixels
81: rs.setValue("data", recordset); //recordset that must be stored in session attribute
82:
83: /* select the type of chart you want to use */
84: rs.setValue("chart-plugin", plugin);
85:
86: //added on april-6-2004 - persist image bytes in session attribute
87: //to be reused by PDF generators
88: rs.setValue("session", session);
89: rs.setValue("image-id", imageid);
90:
91: //added on july-19-2005 - default color for charts
92: //with 1 series only (applies to bar, line and area only)
93: rs.setValue("color", color);
94:
95: }
96:
97: }
|