Current File : /home/caballoscriollos/public_html/espanol/encuesta/graphs/contents/jsp_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 JSP > 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 JSP 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 "Basic Examples" as we start off from concepts explained in that page. </strong></p>
<p class="highlightBlock">The code examples contained in this
page are present in<span class="codeInline"> Download Package > Code
> JSP</span> > <span class="codeInline">FormBased</span> folder. </p>
<p><span class="header">Building the Form </span></p>
<p>The form is contained in <span class="codeInline">Default.jsp</span> and looks as under: </p>
<p><img src="Images/Code_Form.gif" class="imageBorder" /></p>
<p>It's a very simple form which submits to <span class="codeInline">Chart.jsp</span>. As such, we wouldn't go into the code of this form. You can directly open the source from download and see it. </p>
<p><span class="header">Requesting the data and Creating the Chart </span></p>
<p>The work of requesting the data from submitted form and creating the chart is done in <span class="codeInline">Chart.jsp</span>, present in the same folder. It contains the following code: </p>
<p class="codeBlock"><HTML><br />
<HEAD><br />
<TITLE>FusionCharts Free - Form Based Data Charting Example</TITLE><br />
<%<br />
<span class="codeComment"> /*<br />
You need to include the following JS file, if you intend to embed the chart using JavaScript.<br />
Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet ExplorerWhen you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.<br />
*/</span><br />
%><br />
<SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT><br />
<style type="text/css"><br />
<!--<br />
body {<br />
font-family: Arial, Helvetica, sans-serif;<br />
font-size: 12px;<br />
}<br />
.text{<br />
font-family: Arial, Helvetica, sans-serif;<br />
font-size: 12px;<br />
}<br />
--><br />
</style><br />
</HEAD><br />
<BODY><br />
<CENTER><br />
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> Form-Based Data Example</h2><br />
<h4>Restaurant Sales Chart below</h4><br />
<%<br />
<br />
<span class="codeComment"> //We first request the data from the form (Default.jsp)</span><br />
String strSoups="",strSalads="",strSandwiches="",strBeverages="",strDesserts="";<br />
<br />
strSoups = request.getParameter("Soups");<br />
strSalads = request.getParameter("Salads");<br />
strSandwiches = request.getParameter("Sandwiches");<br />
strBeverages = request.getParameter("Beverages");<br />
strDesserts = request.getParameter("Desserts");<br />
<br />
<span class="codeComment">//In this example, we're directly showing this data back on chart.<br />
//In your apps, you can do the required processing and then show the <br />
//relevant data only.</span><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 />
String 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' <br />
decimalPrecision='0' showNames='1'>";<br />
<span class="codeComment">//Add all data</span><br />
strXML = strXML + "<set name='Soups' value='" + strSoups + "' />";<br />
strXML = strXML + "<set name='Salads' value='" + strSalads + "' />";<br />
strXML = strXML + "<set name='Sandwiches' value='" + strSandwiches + "' />";<br />
strXML = strXML + "<set name='Beverages' value='" + strBeverages + "' />";<br />
strXML = strXML + "<set name='Desserts' value='" + strDesserts + "' />";<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 />
%><br />
<jsp:include page="../Includes/FusionChartsRenderer.jsp" flush="true"> <br />
<jsp:param name="chartSWF" value="../../FusionCharts/FCF_Pie3D.swf" /> <br />
<jsp:param name="strURL" value="" /> <br />
<jsp:param name="strXML" value="<%=strXML %>" /> <br />
<jsp:param name="chartId" value="Sales" /> <br />
<jsp:param name="chartWidth" value="600" /> <br />
<jsp:param name="chartHeight" value="350" /><br />
<jsp:param name="debugMode" value="false" /> <br />
<jsp:param name="registerWithJS" value="false" /><br />
</jsp:include><br />
<a href='javascript:history.go(-1);'>Enter data again</a> <BR><br />
<BR><br />
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a><BR><H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5><br />
</CENTER><br />
</BODY><br />
</HTML></p>
<p>As you can see in the above code, we're doing the following:</p>
<ul>
<li>Including <span class="codeInline">FusionCharts.js</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>Rendering a Pie 3D chart by including FusionChartsRenderer.jsp and passing <span class="codeInline">strXML</span> as parameter.</li>
</ul>
<p>When you finally run the code, you'll see a chart as under:</p>
<p> <img src="Images/Code_FormChart.jpg" width="468" height="268" class="imageBorder" /></p></td>
</tr>
</table>
</body>
</html>
Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat