<% 'We've included ../Includes/FusionCharts.asp, which contains functions 'to help us easily embed the charts. %> FusionCharts - Multiseries chart using data from database

Output of various factories

<% 'In this example, we show how to connect FusionCharts to a database. 'For the sake of ease, we've used an Access databases containing two 'tables. Dim resultCategories, resultData, strQuery 'strXML will be used to store the entire XML document generated Dim strXML, intCounter intCounter = 0 ' Creating ADODB object. Set resultCategories = Server.CreateObject("ADODB.Recordset") ' SQL query for category labels strQueryCategories = "select distinct Format(Factory_Output.DatePro,'mm-dd-yyyy') as DatePro from Factory_Output " ' Connect to the DB and Query database Set resultCategories = oConn.Execute(strQueryCategories) ' SQL query for factory output data strQueryData = "select Factory_Master.FactoryName, Format(Factory_Output.DatePro,'mm-dd-yyyy') as DatePro, Factory_Output.Quantity from Factory_Master Factory_Master, Factory_Output Factory_Output where Factory_Output.FactoryID = Factory_Master.FactoryId order by Factory_Output.FactoryID, Factory_Output.DatePro" ' Query database Set resultData = oConn.Execute(strQueryData) 'strXML will be used to store the entire XML document generated 'Generate the chart element strXML = "" ' Build category XML strXML = strXML & buildCategories(resultCategories, "DatePro") ' Build datasets XML strXML = strXML & buildDatasets ( resultData, "Quantity", "FactoryName") 'Finally, close element strXML = strXML & "" 'Create the chart - Pie 3D Chart with data from strXML Call renderChart("../../FusionCharts/MSLine.swf", "", strXML, "FactorySum", 700, 400, false, false) ' Free database resource Set resultCategories = Nothing Set resultData = Nothing '*********************************************************************************************** ' * Function to build XML for categories ' * @param result Database resource ' * @param labelField Field name as String that contains value for chart category labels ' * ' * @return categories XML node ' * Function buildCategories ( result, labelField ) Dim sXML sXML = "" If Not result Is Nothing Then sXML = "" While Not result.Eof sXML = sXML & "" result.MoveNext Wend sXML = sXML & "" End If buildCategories = sXML End Function '*********************************************************************************************** ' * Function to build XML for datesets that would contain chart data ' * @param result Database resource. The data should come ordered by a control break ' field which would require to identify datasets and set its value to ' dataset's series name ' * @param valueField Field name as String that contains value for chart dataplots ' * @param controlBreak Field name as String that contains value for chart dataplots ' * ' * @return Dataset XML node ' * Function buildDatasets (result, valueField, controlBreak ) Dim sXML sXML = "" if Not result Is Nothing Then controlBreakValue ="" While Not result.Eof If ( controlBreakValue <> result(controlBreak) ) Then controlBreakValue = result(controlBreak) If Trim(sXML) = "" Then sXML = sXML & "" & "" Else sXML = sXML & "" & "" End If End If sXML = sXML & "" result.MoveNext Wend sXML = sXML & "" End If buildDatasets = sXML End Function %>

 

This is very simple implementation using a simple database. Complexity of real implementataion can vary as per database structure.