This example creates a chart using data from an ADO recordset. A tab-delimited string is created from the returned recordset data, and then this string is used with the SetCategoriesFromString and SetSeriesValuesFromString methods to set the chart data.

To run this example, copy the remainder of the text in this topic into an ASP page.

 <%@Language = VBScript %>
 <%' use this meta tag instead of adovbs.inc%>
 <!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->

 <%
    Response.Expires= 0

    Dim categories, values
    Dim Cnxn, strCnxn
    Dim rs, strSQL

    ' This example connects to a sample database named db1.mdb
    ' and charts the table named Info. ADO is used to open a
    ' connection to the database and return the entire recordset. The query
    ' contains two columns: Name and Sales.
    ' The records are then extracted into strings.

    ' Open connection to the "db1.mdb" Access Data Base
    strCnxn= "C:\db1.mdb"
    strCnxn= "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & strCnxn
    Set Cnxn= Server.CreateObject("ADODB.Connection")

    Cnxn.Open strCnxn

    Set Cmd= Server.CreateObject("ADODB.Command")
    Cmd.ActiveConnection= Cnxn

    strSQL = "SELECT * From Info"

    Cmd.CommandText = strSQL
    Set rs= Cmd.Execute

    categories = ""
    values = ""

    ' Start at the first record and move through the entire recordset.
    ' Field 0 is the category name, Field 1 is the sales value.
    ' Create a semicolon-delimited string for the names and one for the values.
    rs.MoveFirst
    While Not rs.EOF
       categories = categories & rs.Fields(0).Value & ";"
       values = values & rs.Fields(1).Value & ";"
       rs.MoveNext
    Wend

    ' Close and release the DB resources
    Cnxn.Close

    Set Cmd = Nothing
    Set rs = Nothing
    Set Cnxn = Nothing

    ' Remove the leftover Semicolon character at the end of the strings.
    categories = Left(categories, Len(categories) - 1)
    values = Left(values, Len(values) - 1)

    ' Create a new Swiff Chart object.
    Dim chart
    Set chart= Server.CreateObject("SwiffChartObject.ChartObj")

    ' Create a chart with one series (called "Sales").
    chart.SetSeriesCaption 0, "Sales"

    ' Set the series categories and values using the strings created from the recordset.
    chart.SetSeparators ";", true
    chart.SetCategoriesFromString categories
    chart.SetSeriesValuesFromString 0, values

    ' Set the chart title to "Sales for 1976".
    chart.SetTitle "Sales for 1976"

    ' Set the chart graphical layout with a Swiff Chart style file.
    ' "C:\myStyle.scs" is a dummy filename, it must be replaced by a correct filename.
    chart.LoadStyle "C:\myStyle.scs"

    ' Finally generate the Flash chart into the Response object.
    chart.ExportAsResponse

    ' Release the chart object
    Set chart= Nothing

    Response.End
%>

See Also

Creating a Chart Using Data Specified in Arrays
Creating a Chart Using Data Specified in Strings
Creating a Chart Using Data From a Text File
Creating a Chart Using Data Specified in URLs