Current File : /home/caballoscriollos/www/espanol/encuesta/graphs/contents/asp_drill.html
<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FusionCharts Free Documentation</title>
<link rel="stylesheet" href="Style.css" type="text/css" />
</head>
<body>
<table width="98%" border="0" cellspacing="0" cellpadding="3" align="center">
<tr>
<td><h2 class="pageHeader">Using FusionCharts with ASP > Creating Drill-down charts </h2></td>
</tr>
<tr>
<td valign="top" class="text"><p>In our previous example, we had used FusionCharts to plot a chart using data stored in database. We'll now extend that example itself to create a drill-down chart which can show more information.</p>
<p><strong>Before you go further with this page, we recommend you to please see the previous sections like "Basic Examples", Creating Data from Array" as we start off from concepts explained in those pages. </strong></p>
<p>If you recall from previous example, we were showing the sum of factory output in a pie chart as under: </p></td>
</tr>
<tr>
<td valign="top" class="text"><img src="Images/Code_DBOut.jpg" class="imageBorder" /></td>
</tr>
<tr>
<td valign="top" class="text">In this example, we'll extend this example, so that when a user clicks on a pie slice for a factory, he can drill down to see date wise production for that factory. </td>
</tr>
<tr>
<td valign="top" class="text"> </td>
</tr>
<tr>
<td valign="top" class="header">Setting up the pie chart for Link </td>
</tr>
<tr>
<td valign="top" class="text">To set up the pie chart to enable links for drill-down involves just minor tweaking of our previous <span class="codeInline">BasicDBExample.asp</span>. We basically need to add the <span class="codeInline">link</span> attribute for each<span class="codeInline"> <set></span> element. We create a new page <span class="codeInline">Default.asp</span> (in<span class="codeInline"> DB_DrillDown</span> folder) from the previous page with the following code changes:
<p class="highlightBlock">The code examples contained in this page are contained in<span class="codeInline"> Download Package > Code > ASP > DB_DrillDown</span> folder. </p></td>
</tr>
<tr>
<td valign="top" class="codeBlock"><p><%@ Language=VBScript %><br />
<HTML><br />
<HEAD><br />
<TITLE> FusionCharts Free - Database and Drill-Down Example </TITLE><br />
<SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT><br />
</HEAD><br />
<!-- #INCLUDE FILE="../Includes/FusionCharts.asp" --><br />
<!-- #INCLUDE FILE="../Includes/DBConn.asp" --><br />
<BODY><br />
<%<br />
<span class="codeComment">'In this example, we show how to connect FusionCharts to a database.<br />
'For the sake of ease, we've used an Access database which is present in<br />
'../DB/FactoryDB.mdb. It just contains two tables, which are linked to each<br />
'other. <br />
<br />
'Database Objects - Initialization</span><br />
Dim oRs, oRs2, strQuery<br />
<span class="codeComment">'strXML will be used to store the entire XML document generated</span><br />
Dim strXML<br /><br/> <span class="codeComment">'Create the recordset to retrieve data</span><br />
Set oRs = Server.CreateObject("ADODB.Recordset")</p>
<p> <span class="codeComment">'Generate the graph element</span><br />
strXML = "<graph caption='Factory Output report' subCaption='By Quantity' decimalPrecision='0' showNames='1' numberSuffix=' Units' pieSliceDepth='30' formatNumberScale='0' >"<br />
<br />
<span class="codeComment"> 'Iterate through each factory</span><br />
strQuery = "select * from Factory_Master"<br />
Set oRs = oConn.Execute(strQuery)<br />
<br />
While Not oRs.Eof<br />
<span class="codeComment">'Now create second recordset to get details for this factory</span><br />
Set oRs2 = Server.CreateObject("ADODB.Recordset")<br />
strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" & ors("FactoryId")<br />
Set oRs2 = oConn.Execute(strQuery) <br />
<span class="codeComment"> 'Generate <set name='..' value='..' link='..' /><br />
'Note that we're setting link as Detailed.asp?FactoryId=<<FactoryId>> and then URL Encoding it</span><br />
<strong> strXML = strXML & "<set name='" & ors("FactoryName") & "' value='" & ors2("TotOutput") & "' link='" & Server.URLEncode("Detailed.asp?FactoryId=" & ors("FactoryId")) & "'/>"</strong><br />
<span class="codeComment"> 'Close recordset</span><br />
Set oRs2 = Nothing<br />
oRs.MoveNext<br />
Wend<br />
<span class="codeComment">'Finally, close <graph> element</span><br />
strXML = strXML & "</graph>"<br />
Set oRs = nothing<br />
<br />
<span class="codeComment">'Create the chart - Pie 3D Chart with data from strXML</span><br />
Call renderChart("../../FusionCharts/FCF_Pie3D.swf", "", strXML, "FactorySum", 650, 450) <br />
%><br />
</BODY><br />
</HTML></p></td>
</tr>
<tr>
<td valign="top" class="text"><p>As you can see in the code above, we're doing the following:</p>
<ol>
<li>Include <span class="codeInline">FusionCharts.js</span> JavaScript class and <span class="codeInline">FusionCharts.asp</span> , to enable easy embedding of FusionCharts.</li>
<li>We then include <span class="codeInline"> DBConn.asp</span>, which contains connection parameters to connect to Access database. </li>
<li>Thereafter, we generate the XML data document by iterating through the recordset. We store the XML data in <span class="codeInline">strXML</span> variable. To each <span class="codeInline"><set></span> element, we add the <span class="codeInline">link</span> attribute, which points to <span class="codeInline">Detailed.asp</span> - the page that contains the chart to show details. We pass the factory id of the respective factory by appending it to the link. We finally URL Encode the link, which is a very important step. </li>
<li>Finally, we render the chart using <span class="codeInline">renderChart()</span> method and pass <span class="codeInline">strXML</span> as <span class="codeInline">dataXML</span>. </li>
</ol>
<p>Let's now shift our attention to <span class="codeInline">Detailed.asp</span> page. </p></td>
</tr>
<tr>
<td valign="top" class="text"> </td>
</tr>
<tr>
<td valign="top" class="header">Creating the detailed data chart page </td>
</tr>
<tr>
<td valign="top" class="text">The page <span class="codeInline">Detailed.asp</span> contains the following code: </td>
</tr>
<tr>
<td valign="top" class="codeBlock"><p><%@ Language=VBScript %><br />
<HTML><br />
<HEAD><br />
<TITLE> FusionCharts Free - Database and Drill-Down Example </TITLE><br />
<SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT><br />
</HEAD><br />
<!-- #INCLUDE FILE="../Includes/FusionCharts.asp" --><br />
<!-- #INCLUDE FILE="../Includes/DBConn.asp" --><br />
<span class="codeComment">'We've also included ../Includes/FC_Colors.asp, having a list of colors<br/>
'to apply different colors to the chart's columns.</span>
<br/>
<!-- #INCLUDE FILE="../Includes/FC_Colors.asp" --><br />
<BODY>
<br />
<%<br />
<span class="codeComment"> 'This page is invoked from Default.asp. When the user clicks on a pie<br />
'slice in Default.asp, the factory Id is passed to this page. We need<br />
'to get that factory id, get information from database and then show<br />
'a detailed chart.<br />
<br />
'First, get the factory Id</span><br />
Dim FactoryId<br />
<span class="codeComment"> 'Request the factory Id from Querystring</span><br />
FactoryId = Request.QueryString("FactoryId")<br />
<br />
Dim oRs, strQuery<br />
<span class="codeComment"> 'strXML will be used to store the entire XML document generated</span><br />
Dim strXML, intCounter <br />
intCounter = 0<br />
<br />
Set oRs = Server.CreateObject("ADODB.Recordset")<br />
<span class="codeComment"> 'Generate the graph element string</span><br />
strXML = "<graph caption='Factory " & FactoryId &" Output ' subcaption='(In Units)' xAxisName='Date' showValues='1' decimalPrecision='0'>"<br />
<span class="codeComment"> 'Now, we get the data for that factory</span><br />
strQuery = "select * from Factory_Output where FactoryId=" & FactoryId<br />
Set oRs = oConn.Execute(strQuery)<br />
While Not oRs.Eof <br />
<span class="codeComment"> 'Here, we convert date into a more readable form for set name.</span><br />
strXML = strXML & "<set name='" & datePart("d",ors("DatePro")) & "/" & datePart("m",<BR />
ors("DatePro")) & "' value='" & ors("Quantity") & "' color='" & getFCColor() & "' />" <br />
Set oRs2 = Nothing<br />
oRs.MoveNext<br />
Wend<br />
<span class="codeComment"> 'Close <graph> element</span><br />
strXML = strXML & "</graph>"<br />
Set oRs = nothing<br />
<br />
<span class="codeComment"> 'Create the chart - Column 2D Chart with data from strXML</span><br />
Call renderChart("../../FusionCharts/FCF_Column2D.swf", "", strXML, "FactoryDetailed", 600, 300)<br />
%><br />
</CENTER><br />
</BODY><br />
</HTML></p> </td>
</tr>
<tr>
<td valign="top" class="text"><p>In this page, we're:</p>
<ol>
<li>Including <span class="codeInline">FusionCharts.js</span> JavaScript class and <span class="codeInline">FusionCharts.asp</span> , to enable easy embedding of FusionCharts.</li>
<li>Requesting the factory id for which we've to show detailed data. This data was sent to us as query string, as a part of pie chart link.</li>
<li>We get the requisite data for this factory from database and then convert it into XML using string concatenation.</li>
<li>Finally, we render a Column 2D chart using <span class="codeInline">renderChart()</span> method to show detailed data.</li>
</ol>
<p>When you now run the app, you'll see the detailed page as under: </p></td>
</tr>
<tr>
<td valign="top" class="text"><img src="Images/Code_Drill.jpg" class="imageBorder" /> </td>
</tr>
</table>
</body>
</html>
Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat