Using FusionCharts with C# (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 > CNET > 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="C#" AutoEventWireup="false" CodeFile="SingleSeries.aspx.cs" Inherits="ArrayExample_SingleSeries" %> <HTML> |
In the above code, we first include FusionCharts.js file to enable us embed the chart using JavaScript. We are also adding an ASP control literal which acts as the container for the charts. The CreateCharts() function does the generation, and is the code behind the file to SingleSeries.aspx.cs. Let's see the code of the code behind file SingleSeries.aspx.cs: |
using System; public partial class ArrayExample_SingleSeries : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e)
//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. //Initialize <graph> element //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="C#" AutoEventWireup="false" CodeFile="MultiSeries.aspx.cs" <HTML> |
In the above code, we first include FusionCharts.js file to enable us embed the chart using JavaScript. We also add the ASP literal control which acts as the container for the chart. Take a look at the code behind file MultiSeries.aspx.cs: |
using System; public partial class ArrayExample_MultiSeries : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e)
//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 } } |
|
When you view the chart, you'll see a chart as under: |
In Download Package > Code > CNET > 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. |