FusionChartsRenderer.jsp 5.5 KB

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