Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Integrating with Server-side Scripts Now that we know the basics of how to create a dynamic chart, let's explore how to change the datasource from an array to a database. We will use the table orders that we earlier created, but this time using SQL Server. Using the data from this table, we will create a chart that lets Harry compare the annual revenues for the last three years. Time for action creating a chart in ASP.NET using data from an SQL Server 1. 2. Create a new file in your project and name it as AnnualRevenues.aspx . Include FusionCharts.js in this page by adding the code: <script type="text/javascript" src="Charts/FusionCharts.js"></script> 3. Add a literal control to the form in this file, so that the code is similar to the following: <form id="form1" runat="server"> <asp:Literal ID="l1" runat="server"></asp:Literal> </form> 4. Open the code-behind file AnnualRevenues.aspx.cs and type in the following code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using System.Text; using InfoSoftGlobal; public partial class _AnnualRevenues : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string connStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Fusion Charts\Documents\Visual Studio 2010\WebSites\Harrys Supermarket\App_Data\Harrys_Supermarket.mdf;Integrated Security=True;User Instance=True"; StringBuilder strXML = new StringBuilder(); strXML.Append("<chart caption='Annual Revenue - last 3 years' [ 154 ]