/Scripts/FusionCharts/Code/ASPClass/DBExample/BasicDBExample.asp

https://github.com/eriknjenga/ADT · ASP · 93 lines · 57 code · 13 blank · 23 comment · 1 complexity · 05603fa76252323be2f56853f96e3f80 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT"%>
  2. <% option explicit %>
  3. <%
  4. 'We've included ../Includes/FusionCharts_Gen.asp, which contains
  5. 'FusionCharts ASP Class to help us easily embed charts
  6. 'We've also used ../Includes/DBConn.asp to easily connect to a database.
  7. %>
  8. <!--#include file="../Includes/DBConn.asp"-->
  9. <!--#include file="../Includes/FusionCharts_Gen.asp"-->
  10. <HTML>
  11. <HEAD>
  12. <TITLE>
  13. FusionCharts V3 - Database Example
  14. </TITLE>
  15. <%
  16. 'You need to include the following JS file, if you intend to embed the chart using JavaScript.
  17. 'Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
  18. 'When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
  19. %>
  20. <SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT>
  21. <style type="text/css">
  22. <!--
  23. body {
  24. font-family: Arial, Helvetica, sans-serif;
  25. font-size: 12px;
  26. }
  27. .text{
  28. font-family: Arial, Helvetica, sans-serif;
  29. font-size: 12px;
  30. }
  31. -->
  32. </style>
  33. </HEAD>
  34. <BODY>
  35. <CENTER>
  36. <h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts V3</a> -Database and Drill-Down Example</h2>
  37. <%
  38. 'In this example, we show how to connect FusionCharts to a database.
  39. 'For the sake of ease, we've used an MySQL databases containing two
  40. 'tables.
  41. dim FC
  42. ' Create FusionCharts ASP class object
  43. set FC = new FusionCharts
  44. ' Set chart type to pie 3D
  45. Call FC.setChartType("pie3d")
  46. ' Set chart size
  47. Call FC.setSize("650","450")
  48. ' Set Relative Path of swf file.
  49. Call FC.setSWFPath("../../FusionCharts/")
  50. dim strParam
  51. ' Define chart attributes
  52. strParam="caption=Factory Output report;subCaption=By Quantity;pieSliceDepth=30; showBorder=1;showLabels=1;numberSuffix= Units;decimals=0"
  53. ' Set chart attributes
  54. Call FC.setChartParams(strParam)
  55. Dim oRs
  56. 'Create the recordset to retrieve data
  57. Set oRs = Server.CreateObject("ADODB.Recordset")
  58. ' Fetch all factory records using SQL Query
  59. ' Store chart data values in 'total' column/field and category names in 'FactoryName'
  60. dim strQuery
  61. strQuery = "select a.FactoryID, b.FactoryName, sum(a.Quantity) as total from Factory_output a, Factory_Master b where a.FactoryId=b.FactoryId group by a.FactoryId,b.FactoryName"
  62. Set oRs = oConn.Execute(strQuery)
  63. 'Pass the SQL Query result to the FusionCharts ASP Class function
  64. 'along with field/column names that are storing chart values and corresponding category names
  65. 'to set chart data from database
  66. if not oRs.bof then
  67. Call FC.addDataFromDatabase(oRs, "total", "FactoryName", "" ,"")
  68. end if
  69. ' Close Recordset
  70. oRs.Close
  71. set oRs=Nothing
  72. ' Render the chart
  73. Call FC.renderChart(false)
  74. %>
  75. <BR><BR>
  76. <a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
  77. <H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
  78. </CENTER>
  79. </BODY>
  80. </HTML>