FusionCharts and ASP.NET > Using dataXML method |
Previously, we had seen how to use the dataURL method to create a dynamic column chart using FusionCharts. Here, we'll be creating the same chart but using dataXML method. As we had earlier seen, the dataXML method just requires one page:
The above page is present in the downloads under the folder FusionCharts2_3 > Sample Code > DBExamples > ASP_NET> dataXML. The page Chart.aspx is responsible for everything - rendering the year down box, getting the selected year, creating the XML data for that year and then rendering the chart for that year. The code for this page can be reproduced as under: |
<%@ Import Namespace="System.Data"
%> <%@ Import Namespace="System.Data.SQLClient" %> <script runat="server"> 'Initialize a variable that will store FusionCharts XML Data document Dim strFCdataXML as String 'Year for which the data is to be shown Dim strSelectedYear as String Sub Page_Load(obj as Object, e as EventArgs) 'If coming for the first time, fill the select (drop down list) If Not IsPostBack Then 'Establish a connection Dim DS As DataSet Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter 'Get the list of years from the database. MyConnection = New SqlConnection(ConfigurationSettings.AppSettings("appDSN")) MyCommand = New SqlDataAdapter("SELECT DISTINCT YEAR(OrderDate) As Year FROM Orders ORDER BY 1", MyConnection) 'Fill
the dataset Public Function getFCXMLData() as String 'Fill
the dataset
|
In the above code, we're doing the following:
When you now see Chart.aspx in your browser, you'll get the following output: |