Current File : /home/caballoscriollos/www/espanol/encuesta/graphs/contents/asp_form.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 > Charting Data from Forms </h2></td>
</tr>
<tr>
<td valign="top" class="text"><p>In this section, we'll show you how to use FusionCharts with ASP to plot data collected in forms. </p>
<p>We'll build a simple restaurant sales example, where the user will enter the items sold by a restaurant in a given week. This data will be submitted in a form to the server. We'll acquire this data and plot in on a chart. For the sake of simplicity, we wouldn't do any processing on this data. However, your real life applications might process data before presenting it on the chart. </p>
<p><strong>Before you go further with this page, we recommend you to please see the previous section "<a href="ASP_BasicExample.html">Basic Examples</a>" as we start off from concepts explained in that page. </strong></p></td>
</tr>
<tr>
<td valign="top" class="highlightBlock">The code examples contained in this page are present in<span class="codeInline"> Download Package > Code > ASP</span> > <span class="codeInline">FormBased</span> folder. </td>
</tr>
<tr>
<td valign="top" class="text"> </td>
</tr>
<tr>
<td valign="top" class="header">Building the Form </td>
</tr>
<tr>
<td valign="top" class="text">The form is contained in <span class="codeInline">Default.asp</span> and looks as under: </td>
</tr>
<tr>
<td valign="top" class="text"><img src="Images/Code_Form.gif" class="imageBorder" /></td>
</tr>
<tr>
<td valign="top" class="text">It's a very simple form which submits to <span class="codeInline">Chart.asp</span>. As such, we wouldn't go into the code of this form. You can directly open the source from download and see it. </td>
</tr>
<tr>
<td valign="top" class="text"> </td>
</tr>
<tr>
<td valign="top" class="header">Requesting the data and Creating the Chart </td>
</tr>
<tr>
<td valign="top" class="text">The work of requesting the data from submitted form and creating the chart is done in <span class="codeInline">Chart.asp</span>, present in the same folder. It contains the following code: </td>
</tr>
<tr>
<td valign="top" class="codeBlock"><p class="codeBlock"><%@ Language=VBScript %><br />
<HTML><br />
<HEAD><br />
<TITLE>FusionCharts Free - Form Based Data Charting Example</TITLE><br />
<SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT><br />
</HEAD><br />
<!-- #INCLUDE FILE="../Includes/FusionCharts.asp" --><br />
<BODY><br />
<% <br />
<br />
<span class="codeComment">'We first request the data from the form (Default.asp)</span><br />
Dim intSoups, intSalads, intSandwiches, intBeverages, intDesserts<br />
intSoups = Int(Request.Form("Soups"))<br />
intSalads = Int(Request.Form("Salads"))<br />
intSandwiches = Int(Request.Form("Sandwiches"))<br />
intBeverages = Int(Request.Form("Beverages"))<br />
intDesserts = Int(Request.Form("Desserts"))<br />
<br />
<span class="codeComment">'Now that we've the data in variables, we need to convert this into XML.<br />
'The simplest method to convert data into XML is using string concatenation. </span><br />
Dim strXML<br />
<span class="codeComment">'Initialize <graph> element</span><br />
strXML = "<graph caption='Sales by Product Category' subCaption='For this week' showPercentageInLabel='1' pieSliceDepth='25' showNames='1' decimalPrecision='0' >"<br />
<span class="codeComment"> 'Add all data</span><br />
strXML = strXML & "<set name='Soups' value='" & intSoups & "' />"<br />
strXML = strXML & "<set name='Salads' value='" & intSalads & "' />"<br />
strXML = strXML & "<set name='Sandwiches' value='" & intSandwiches & "' />"<br />
strXML = strXML & "<set name='Beverages' value='" & intBeverages & "' />"<br />
strXML = strXML & "<set name='Desserts' value='" & intDesserts & "' />"<br />
<span class="codeComment"> 'Close <graph> element</span><br />
strXML = strXML & "</graph>"<br />
<br />
<span class="codeComment"> 'Create the chart - Pie 3D Chart with data from strXML</span><br />
Call renderChart("../../FusionCharts/FCF_Pie3D.swf", "", strXML, "Sales", 600, 350)<br />
%></p>
<p></BODY><br />
</HTML></p></td>
</tr>
<tr>
<td valign="top" class="text"><p>As you can see in the above code, we're doing the following:</p>
<ul>
<li>Including <span class="codeInline">FusionCharts.js</span> and<span class="codeInline"> FusionCharts.asp</span> in this page. </li>
<li>Requesting data from the submitted form and storing it in local variables</li>
<li>Creating an XML data document using string concatenation and storing it in <span class="codeInline">strXML</span> variable </li>
<li>Creating a Pie 3D chart using <span class="codeInline">renderChart()</span> function and passing <span class="codeInline">strXML</span> as <span class="codeInline">dataXML</span> for the chart. </li>
</ul>
<p>When you finally run the code, you'll see a chart as under: </p></td>
</tr>
<tr>
<td valign="top" class="text"><img src="Images/Code_FormChart.jpg" class="imageBorder" /></td>
</tr>
</table>
</body>
</html>
Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat