PageRenderTime 28ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/technical_documentation/FusionChartsFree/Code/ASP/DB_JS/Default.asp

https://github.com/eladioruiz/golf
ASP | 208 lines | 120 code | 41 blank | 47 comment | 5 complexity | db8cd36603d9b4ce18f4d89c65480fdd MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <%@ Language=VBScript %>
  2. <HTML>
  3. <HEAD>
  4. <TITLE>
  5. FusionCharts Free - Client Side Dynamic Chart ( using Database) Example
  6. </TITLE>
  7. <%
  8. 'We've included ../Includes/FusionCharts.asp, which contains functions
  9. 'to help us easily embed the charts.
  10. %>
  11. <!-- #INCLUDE FILE="../Includes/FusionCharts.asp" -->
  12. <!-- #INCLUDE FILE="../Includes/DBConn.asp" -->
  13. <%
  14. 'In this example, we show a combination of database + JavaScript rendering using FusionCharts.
  15. 'The entire app (page) can be summarized as under. This app shows the break-down
  16. 'of factory wise output generated. In a pie chart, we first show the sum of quantity
  17. 'generated by each factory. These pie slices, when clicked would show detailed date-wise
  18. 'output of that factory.
  19. 'The XML data for the pie chart is fully created in ASP at run-time. ASP interacts
  20. 'with the database and creates the XML for this.
  21. 'Now, for the column chart (date-wise output report), we do not submit request to the server.
  22. 'Instead we store the data for the factories in JavaScript arrays. These JavaScript
  23. 'arrays are rendered by our ASP Code (at run-time). We also have a few defined JavaScript
  24. 'functions which react to the click event of pie slice.
  25. 'We've used an Access database which is present in ../DB/FactoryDB.mdb.
  26. 'It just contains two tables, which are linked to each other.
  27. 'Before the page is rendered, we need to connect to the database and get the
  28. 'data, as we'll need to convert this data into JavaScript variables.
  29. 'The following string will contain the JS Data and variables.
  30. 'This string will be built in ASP and rendered at run-time as JavaScript.
  31. Dim jsVarString
  32. jsVarString = ""
  33. 'Database Objects
  34. Dim oRs, oRs2, strQuery, indexCount
  35. indexCount = 0
  36. 'Create the recordset to retrieve data
  37. Set oRs = Server.CreateObject("ADODB.Recordset")
  38. 'Iterate through each factory
  39. strQuery = "select * from Factory_Master"
  40. Set oRs = oConn.Execute(strQuery)
  41. While not oRs.EOF
  42. indexCount = indexCount + 1
  43. 'Create JavaScript code to add sub-array to data array
  44. 'data is an array defined in JavaScript (see below)
  45. 'We've added vbTab & vbCRLF to data so that if you View Source of the
  46. 'output HTML, it will appear properly. It helps during debugging
  47. jsVarString = jsVarString & vbTab & vbTab & "data[" & indexCount & "] = new Array();" & vbCRLF
  48. 'Now create second recordset to get date-wise details for this factory
  49. Set oRs2 = Server.CreateObject("ADODB.Recordset")
  50. strQuery = "select * from Factory_Output where FactoryId=" & ors("FactoryId") & " order by DatePro Asc" & vbCRLF
  51. Set oRs2 = oConn.Execute(strQuery)
  52. While not oRs2.EOF
  53. 'Put this data into JavaScript as another nested array.
  54. 'Finally the array would look like data[factoryIndex][i][dataLabel,dataValue]
  55. jsVarString = jsVarString & vbTab & vbTab & "data[" & indexCount & "].push(new Array('" & datePart("d",ors2("DatePro")) & "/" & datePart("m",ors2("DatePro")) & "'," & ors2("Quantity") & "));" & vbCRLF
  56. oRs2.MoveNext()
  57. Wend
  58. 'Close recordset
  59. Set oRs2 = Nothing
  60. oRs.MoveNext()
  61. Wend
  62. %>
  63. <SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js">
  64. //You need to include the above JS file, if you intend to embed the chart using JavaScript.
  65. //Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
  66. //When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
  67. </SCRIPT>
  68. <SCRIPT LANGUAGE="JavaScript" >
  69. //Here, we use a mix of server side script (ASP) and JavaScript to
  70. //render our data for factory chart in JavaScript variables. We'll later
  71. //utilize this data to dynamically plot charts.
  72. //All our data is stored in the data array. From ASP, we iterate through
  73. //each recordset of data and then store it as nested arrays in this data array.
  74. var data = new Array();
  75. <%
  76. 'Write the data as JavaScript variables here
  77. Response.Write(jsVarString)
  78. 'The data is now present as arrays in JavaScript. Local JavaScript functions
  79. 'can access it and make use of it. We'll see how to make use of it.
  80. %>
  81. /**
  82. * updateChart method is invoked when the user clicks on a pie slice.
  83. * In this method, we get the index of the factory, build the XML data
  84. * for that that factory, using data stored in data array, and finally
  85. * update the Column Chart.
  86. * @param factoryIndex Sequential Index of the factory.
  87. */
  88. function updateChart(factoryIndex){
  89. //defining array of colors
  90. //We also initiate a counter variable to help us cyclically rotate through
  91. //the array of colors.
  92. var FC_ColorCounter=0;
  93. //var arr_FCColors= new Array(20);
  94. var arr_FCColors= new Array("1941A5" , "AFD8F8", "F6BD0F", "8BBA00", "A66EDD", "F984A1", "CCCC00", "999999", "0099CC", "FF0000", "006F00", "0099FF", "FF66CC", "669966", "7C7CB4", "FF9933", "9900FF", "99FFCC", "CCCCFF", "669900");
  95. //Storage for XML data document
  96. var strXML = "<graph caption='Factory " + factoryIndex + " Output ' subcaption='(In Units)' xAxisName='Date' decimalPrecision='0'>";
  97. //Add <set> elements
  98. var i=0;
  99. for (i=0; i<data[factoryIndex].length; i++){
  100. strXML = strXML + "<set name='" + data[factoryIndex][i][0] + "' value='" + data[factoryIndex][i][1] + "' color='"+ arr_FCColors[++FC_ColorCounter % arr_FCColors.length] +"' />";
  101. }
  102. //Closing graph Element
  103. strXML = strXML + "</graph>";
  104. //Update it's XML
  105. updateChartXML("FactoryDetailed",strXML);
  106. }
  107. </SCRIPT>
  108. <style type="text/css">
  109. <!--
  110. body {
  111. font-family: Arial, Helvetica, sans-serif;
  112. font-size: 12px;
  113. }
  114. .text{
  115. font-family: Arial, Helvetica, sans-serif;
  116. font-size: 12px;
  117. }
  118. -->
  119. </style>
  120. </HEAD>
  121. <BODY>
  122. <CENTER>
  123. <h3><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> Database + JavaScript Example</h3>
  124. <h5>Inter-connected charts - Click on any pie slice to see detailed chart below.</h5>
  125. <p>The charts in this page have been dynamically generated using data contained in a database. We've NOT hard-coded the data in JavaScript.</p>
  126. <%
  127. 'Initialize the Pie chart with sum of production for each of the factories
  128. 'strXML will be used to store the entire XML document generated
  129. Dim strXML
  130. 'Re-initialize Index
  131. indexCount=0
  132. 'Generate the graph element
  133. strXML = "<graph caption='Factory Output report' subCaption='By Quantity' decimalPrecision='0' showNames='1' numberSuffix=' Units' pieSliceDepth='20' formatNumberScale='0' >"
  134. 'Move back to first index of the factory master recordset
  135. oRs.MoveFirst()
  136. While Not oRs.Eof
  137. 'Update index count - sequential
  138. indexCount = indexCount + 1
  139. 'Now create second recordset to get details for this factory
  140. Set oRs2 = Server.CreateObject("ADODB.Recordset")
  141. strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" & ors("FactoryId")
  142. Set oRs2 = oConn.Execute(strQuery)
  143. 'Generate <set name='..' value='..' link='..' />
  144. 'Note that we're setting link as updateChart(factoryIndex) - JS Function
  145. strXML = strXML & "<set name='" & ors("FactoryName") & "' value='" & ors2("TotOutput") & "' link='javascript:updateChart(" & indexCount & ")'/>"
  146. 'Close recordset
  147. Set oRs2 = Nothing
  148. oRs.MoveNext
  149. Wend
  150. 'Finally, close <graph> element
  151. strXML = strXML & "</graph>"
  152. Set oRs = nothing
  153. 'Create the chart - Pie 3D Chart with data from strXML
  154. Call renderChart("../../FusionCharts/FCF_Pie3D.swf", "", strXML, "FactorySum", 650, 300)
  155. %>
  156. <BR>
  157. <%
  158. 'Column 2D Chart with changed "No data to display" message
  159. 'We initialize the chart with <graph></graph>
  160. Call renderChart("../../FusionCharts/FCF_Column2D.swf?ChartNoDataText=Please click on a pie slice above to view detailed data.", "", "<graph></graph>", "FactoryDetailed", 600, 300)
  161. %>
  162. <BR><BR>
  163. <a href='../NoChart.html' target="_blank">Unable to see the chart(s) above?</a>
  164. <BR><H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
  165. </CENTER>
  166. </BODY>
  167. </HTML>