Using FusionCharts with VB.NET (ASP.NET) > Charting data from Array |
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:
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. The code examples contained in this page are present in Download Package > Code > VBNET > ArrayExample folder. |
Creating a single series chart from data contained in arrays |
The code to create a single series chart is contained in SingleSeries.aspx and can be listed as under: |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SingleSeries.aspx.vb" Inherits="ArrayExample_SingleSeries" %> <HTML> |
In the above code, we first include FusionCharts.js 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. Let's see the code of the code behind file SingleSeries.aspx.vb: |
Imports Utilities Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'In this example, we plot a single series chart from data contained 'Let's store the sales data for 6 products in our array). We also store 'Now, we need to convert this data into XML. We convert using string concatenation. 'Convert data to XML and append 'Create the chart - Column 3D Chart with data contained in strXML |
We included Utilities 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 getFCColor() function in cyclic iteration returns these color values. When you view the chart, you'll see a chart as under: |
Creating a multi-series chart from data contained in arrays |
Let us now create a multi-series chart from data contained in arrays. We create a file MultiSeries.aspx with the following code: |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MultiSeries.aspx.vb" <HTML> |
In the above code, we first include FusionCharts.js file to enable us embed the chart using JavaScript. We then call method CreateChart() from the code behind to generate code for chart. Take a look at the code behind file MultiSeries.aspx.vb: |
Imports InfoSoftGlobal Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Public Function CreateChart() As String 'In this example, we plot a multi series chart from data contained 'Let's store the sales data for 6 products in our array. We also store 'Now, we need to convert this data into multi-series XML. 'Initialize <graph> element 'Initialize <categories> element - necessary to generate a multi-series chart 'Initiate <dataset> elements 'Iterate through the data 'Close <categories> element 'Close <dataset> elements 'Assemble the entire XML now 'Create the chart - MS Column 3D Chart with data contained in strXML End Function |
|
When you view the chart, you'll see a chart as under: |
In Download Package > Code > VBNET > ArrayExample, 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. |