/Scripts/FusionCharts/Code/ASP/DBExample/Default.asp

https://github.com/eriknjenga/ADT · ASP · 92 lines · 60 code · 8 blank · 24 comment · 1 complexity · 5a076410c4df68ba283aebc530eba217 MD5 · raw file

  1. <%@ Language=VBScript %>
  2. <HTML>
  3. <HEAD>
  4. <TITLE>
  5. FusionCharts - Database and Drill-Down Example
  6. </TITLE>
  7. <%
  8. 'You need to include the following JS file, if you intend to embed the chart using JavaScript.
  9. 'Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
  10. 'When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
  11. %>
  12. <SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT>
  13. <style type="text/css">
  14. <!--
  15. body {
  16. font-family: Arial, Helvetica, sans-serif;
  17. font-size: 12px;
  18. }
  19. .text{
  20. font-family: Arial, Helvetica, sans-serif;
  21. font-size: 12px;
  22. }
  23. -->
  24. </style>
  25. </HEAD>
  26. <%
  27. 'We've included ../Includes/FusionCharts.asp, which contains functions
  28. 'to help us easily embed the charts.
  29. %>
  30. <!-- #INCLUDE FILE="../Includes/FusionCharts.asp" -->
  31. <!-- #INCLUDE FILE="../Includes/DBConn.asp" -->
  32. <BODY>
  33. <CENTER>
  34. <h2>FusionCharts Database and Drill-Down Example</h2>
  35. <h4>Click on any pie slice to see detailed data.</h4>
  36. <p class='text'>Or, right click on any pie to enable slicing or rotation mode. </p>
  37. <%
  38. 'In this example, we show how to connect FusionCharts to a database.
  39. 'For the sake of ease, we've used an Access database which is present in
  40. '../DB/FactoryDB.mdb. It just contains two tables, which are linked to each
  41. 'other.
  42. 'Database Objects - Initialization
  43. Dim oRs, oRs2, strQuery
  44. 'strXML will be used to store the entire XML document generated
  45. Dim strXML
  46. 'We also keep a flag to specify whether we've to animate the chart or not.
  47. 'If the user is viewing the detailed chart and comes back to this page, he shouldn't
  48. 'see the animation again.
  49. Dim animateChart
  50. animateChart = Request.QueryString("animate")
  51. 'Set default value of 1
  52. if animateChart="" then
  53. animateChart = "1"
  54. end if
  55. 'Create the recordset to retrieve data
  56. Set oRs = Server.CreateObject("ADODB.Recordset")
  57. 'Generate the chart element
  58. strXML = "<chart caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' formatNumberScale='0' numberSuffix=' Units' animation=' " & animateChart & "'>"
  59. 'Iterate through each factory
  60. strQuery = "select * from Factory_Master"
  61. Set oRs = oConn.Execute(strQuery)
  62. While Not oRs.Eof
  63. 'Now create second recordset to get details for this factory
  64. Set oRs2 = Server.CreateObject("ADODB.Recordset")
  65. strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" & ors("FactoryId")
  66. Set oRs2 = oConn.Execute(strQuery)
  67. 'Generate <set label='..' value='..' link='..' />
  68. 'Note that we're setting link as Detailed.asp?FactoryId=<<FactoryId>>
  69. strXML = strXML & "<set label='" & ors("FactoryName") & "' value='" & ors2("TotOutput") & "' link='" & Server.URLEncode("Detailed.asp?FactoryId=" & ors("FactoryId")) & "'/>"
  70. 'Close recordset
  71. Set oRs2 = Nothing
  72. oRs.MoveNext
  73. Wend
  74. 'Finally, close <chart> element
  75. strXML = strXML & "</chart>"
  76. Set oRs = nothing
  77. 'Create the chart - Pie 3D Chart with data from strXML
  78. Call renderChart("../../FusionCharts/Pie3D.swf", "", strXML, "FactorySum", 600, 300, false, false)
  79. %>
  80. <BR><BR>
  81. <a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
  82. </CENTER>
  83. </BODY>
  84. </HTML>