FusionChartsRenderer.jsp
5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<%@page import="com.fusioncharts.helper.FCParameters" %>
<%
/*
* Version 2.0:
* Added JS v3.2 constructor call with object style parameters.
* Added strJSON, dataFormat, renderer and renderAt as parameters.
* Version: 1.1:
* Added support for all the parameters like wMode etc.
* Works with all jdk versions >=1.4.
* Creates the JavaScript + HTML code required to embed a chart.<br>
* Uses the javascript FusionCharts class to create the chart by supplying <br>
* the required parameters to it.<br>
* Note: Only one of the parameters dataURL or dataStr has to be non-empty for this<br>
* method to work. If both the parameters are provided then dataURL is used for further processing.<br>
*
* @param chartSWF -
* SWF File Name (and Path) of the chart which you intend
* to plot
* @param strURL -
* If you intend to use dataURL method for this chart,
* pass the URL as this parameter. Else, set it to "" (in
* case of dataStr method)
* @param strXML -
* If you intend to use dataStr method for this chart,
* pass the XML data as this parameter. Else, set it to ""
* (in case of dataURL method)
* @param strJSON -
* If you intend to use dataStr method for this chart,
* pass the JSON data as this parameter. Else, set it to ""
* (in case of dataURL/xml method)
* @param chartId -
* Id for the chart, using which it will be recognized in
* the HTML page. Each chart on the page needs to have a
* unique Id.
* @param chartWidth -
* Intended width for the chart (in pixels)
* @param chartHeight -
* Intended height for the chart (in pixels)
* @param debugMode -
* Whether to start the chart in debug mode
* @param registerWithJS -
* Whether to ask chart to register itself with
* JavaScript
* @param wMode -
* @param color -
* @param scaleMode -
* @param lang -
* @param detectFlashVersion -
* @param autoInstallRedirect -
*/
%>
<%
String chartSWF = request.getParameter("chartSWF");
String strURL = request.getParameter("strURL");
String strXML = request.getParameter("strXML");
String strJSON = request.getParameter("strJSON");
String chartId = request.getParameter("chartId");
String chartWidthStr = request.getParameter("chartWidth");
String chartHeightStr = request.getParameter("chartHeight");
String debugModeStr= request.getParameter("debugMode");
String registerWithJSStr= request.getParameter("registerWithJS");
String wMode = request.getParameter("wMode");
String color = request.getParameter("color");
String scaleMode = request.getParameter("scaleMode");
String lang = request.getParameter("lang");
String detectFlashVersion = request.getParameter("detectFlashVersion");
String autoInstallRedirect= request.getParameter("autoInstallRedirect");
String dataFormat= request.getParameter("dataFormat");
String renderer= request.getParameter("renderer");
String renderAt= request.getParameter("renderAt");
int chartWidth = 600;
int chartHeight = 300;
Boolean debugMode=new Boolean("false");
Boolean registerWithJS=new Boolean("false");
int debugModeInt = 0;
int regWithJSInt = 0;
if (null != chartWidthStr && !chartWidthStr.equals("")) {
chartWidth = Integer.parseInt(chartWidthStr);
}
if (null != chartHeightStr && !chartHeightStr.equals("")) {
chartHeight = Integer.parseInt(chartHeightStr);
}
if(null!=debugModeStr && !debugModeStr.equals("")){
debugMode = new Boolean(debugModeStr);
debugModeInt=boolToNum(debugMode);
}
if(null!=registerWithJSStr && !registerWithJSStr.equals("")){
registerWithJS = new Boolean(registerWithJSStr);
regWithJSInt=boolToNum(registerWithJS);
}
if(renderer==null)
renderer="flash"; // default value
if(renderAt==null)
renderAt=chartId+"Div";
String dataSource = "";
// Check whether we've to provide data using dataStr method or dataURL
// method
if (strURL!=null && !strURL.equals("")) {
dataSource = strURL;
dataFormat =( dataFormat==null ? "xmlurl" : dataFormat);
} else if(strXML!=null && !strXML.equals("")){
dataSource = strXML;
dataFormat =( dataFormat==null ? "xml" : dataFormat);
}else if(strJSON!=null && !strJSON.equals("")){
dataSource = strJSON;
dataFormat =( dataFormat==null ? "json" : dataFormat);
}
FCParameters fcParams = new FCParameters(chartSWF, chartId,
""+chartWidth, ""+chartHeight, "" + debugModeInt, "" + regWithJSInt,
wMode, color, scaleMode, lang, detectFlashVersion,
autoInstallRedirect, dataSource, dataFormat, renderer,
renderAt);
String paramsInJSON = fcParams.toJSON();
%>
<!-- START Script Block for Chart <%=chartId%> -->
<% if(renderAt.equals(chartId+"Div")) {
// output this chartIdDiv div only if chart is being rendered in it
%>
<div id='<%=chartId %>Div' align='center'>Chart.</div>
<% } %>
<script type='text/javascript'>
var chart_<%=chartId%> = new FusionCharts(<%=paramsInJSON%>).render();
</script>
<!--END Script Block for Chart <%=chartId%> -->
<%!
/**
* Converts a Boolean value to int value<br>
*
* @param bool Boolean value which needs to be converted to int value
* @return int value correspoding to the boolean : 1 for true and 0 for false
*/
public int boolToNum(Boolean bool) {
int num = 0;
if (bool.booleanValue()) {
num = 1;
}
return num;
}
%>