Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003
    Location
    Malaysia
    Posts
    1

    Question Unanswered: Display multiple lines on 1 chart (ASP and OWC)

    Hi All,
    I manage to display 1st line into the chart(LoadPercentage). However, when I tried to put the 2nd line(ActiveSessions), it overwrites the 1st line. And how to display the correct information for the legend instead of Series1, etc...

    Chart : X-Axis 0-100
    Y-Axis Date

    My WTSApplication.mdb data
    Table : ServerMonitoring
    Field : Server LoadPercentage ActiveSessions Date
    Server1 10 2 11/02/03 1:00
    Server1 20 3 11/02/03 2:00

    Here is my code :
    <%@ Language=VBScript %>
    <%
    Option Explicit
    Response.Expires = -1
    Response.ContentType = "image/gif"

    'Page-level variables
    '--------------------
    Dim m_cn 'connection object
    Dim m_rs 'Recordset object
    Dim m_cspace 'OWC.ChartSpace object
    Dim m_fso 'file system object
    Dim m_objBinaryFile 'BinaryFileStream object

    Dim m_sServer 'server data desired (query string parameter)

    Dim sSQL 'SQL statement to execute
    Dim c 'OWC Constants object
    Dim cht 'Temp ref to a chart
    Dim ax 'Temp ref to an axis
    Dim fnt 'Temp ref to an OWCFont
    Dim sFullFileName 'Full path to temp file for exported GIF

    'get the server param; default is Server1 if not specified
    m_sServer = Request.QueryString("Server")
    if len(m_sServer) = 0 then m_sServer = "Server1"

    'create the ADO Connection and Recordset objects
    set m_cn = Server.CreateObject("ADODB.Connection")
    set m_rs = Server.CreateObject("ADODB.Recordset")

    'connect to the database and open a recordset using client-side cursor engine so
    'that the chart can do sorts to determine series and categories
    m_cn.Open "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath(".") & "\WTSApplication.mdb"

    sSQL = "SELECT * FROM ServerMonitoring WHERE Server = 'Server1' ORDER BY Date ASC"

    m_rs.CursorLocation = 3 'adUseClient
    m_rs.Open sSQL, m_cn, 3 'adOpenStatic

    'Add a Clustered Column Chart with a legend to the Chartspace
    set m_cspace = server.CreateObject("OWC.Chart")
    set cht = m_cspace.Charts.Add()
    set c = m_cspace.Constants
    cht.Type = c.chChartTypeLine
    cht.HasLegend = True

    set m_cspace.DataSource = m_rs


    'cht.SetData c.chDimValues, 0, "LoadPercentage"
    'cht.SetData c.chDimValues, 0, "ActiveSessions"
    cht.SetData c.chDimCategories, 0, "Date"


    'add a chart title and format the title
    cht.HasTitle = True
    cht.Title.Caption = "Server " & m_sServer
    set fnt = cht.Title.Font
    fnt.Name = "Tahoma"
    fnt.Size = 10
    fnt.Bold = True

    'add a title to the category axis and format the title
    set ax = cht.Axes(c.chAxisPositionBottom)
    ax.HasTitle = True
    ax.Title.Caption = "Date"
    set fnt = ax.Title.Font
    fnt.Name = "Tahoma"
    fnt.Size = 8
    fnt.Bold = True

    'add a title to the value axis and format the title
    set ax = cht.Axes(c.chAxisPositionLeft)
    ax.NumberFormat = "General"
    ax.HasTitle = True
    ax.Title.Caption = "Value"
    set fnt = ax.Title.Font
    fnt.Name = "Tahoma"
    fnt.Size = 8
    fnt.Bold = True

    'Save the current chart to a GIF file with a temporary, unique filename
    set m_fso = CreateObject("Scripting.FileSystemObject")
    sFullFileName = Server.MapPath(".") & "\" & m_fso.GetTempName()
    m_cspace.ExportPicture sFullFileName, "gif", 800, 400

    'Use On Error Resume Next to make sure we eventually delete
    'the temporary GIF file even if something fails in the next couple
    'of functions
    on error resume next

    'The GIF file has been created. Return the contents of the GIF file as
    'binary data using the BinaryFileStream ActiveX DLL
    set m_objBinaryFile = server.CreateObject("BinaryFileStream.Object")
    Response.BinaryWrite m_objBinaryFile.GetFileBytes(CStr(sFullFileName))

    'Delete the GIF file since it is no longer needed
    m_objBinaryFile.DeleteFile CStr(sFullFileName)

    %>

    Thank you very much.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2002
    Location
    North Wales, UK
    Posts
    114
    I had a similar problem recently although creating another chart in the chart workspace was ok for what I needed. The M$ support on this matter is quite poort really
    J^ - web | email
    newsASP Developer

  3. #3
    Join Date
    Mar 2004
    Posts
    2
    I have exactly the same problem, the only difference between my code and yours is this:

    Code:
    'set the Chartspace's data source to the Recordset and add the
    'SalesPerson field for series names, the Month field for the chart's
    'categories and the Sales field for the chart's values
    
    set m_cspace.DataSource = m_rs
    objChart.SetData c.chDimSeriesNames, 0, "debilt_hirlam"
    objChart.SetData c.chDimCategories, 0, m_station & "_hirlam.fictievedatum"
    objChart.SetData c.chDimValues, 0, Array(m_station & "_hirlam.fictievedatum", m_station & "_xhirlam.fictievedatum")
    
    'add a chart title and format the title
    objChart.HasTitle = True
    objChart.Title.Caption = m_station & " van " & m_dag & "-" & m_maand & "-" & m_jaar & " tot " & m_dag2 & "-" & m_maand2 & "-" & m_jaar2 & " (+" & m_vp & " )"
    set fnt = objChart.Title.Font
    fnt.Name = "Tahoma"
    fnt.Size = 10
    fnt.Bold = True
    
    for each ax in objChart.Axes
        ax.HasTitle = True
        if ax.Type = c.chCategoryAxis then
            ax.Title.Caption = "datum"
    	set fnt = ax.Title.Font
    	fnt.Name = "Tahoma"
    	fnt.Size = 8
    	fnt.Bold = True
        else
            ax.Title.Caption = "temperatuur in C"
    	set fnt = ax.Title.Font
    	fnt.Name = "Tahoma"
    	fnt.Size = 8
    	fnt.Bold = True
        end if
    next
    I also tried something like this:

    Code:
    'set the Chartspace's data source to the Recordset and add the
    'SalesPerson field for series names, the Month field for the chart's
    'categories and the Sales field for the chart's values
    
    set m_cspace.DataSource = m_rs
    objChart.SetData c.chDimSeriesNames, 0, "debilt_hirlam"
    for each objSeries in objChart.SeriesCollection
    	objSeries.SetData c.chDimCategories, 0, m_station & "_hirlam.fictievedatum"
    	objSeries.SetData c.chDimValues, 0, m_station & "_hirlam.t2m"
    next
    But nothing seems to work, I only get errors, and if I get no error I get no line, sometimes even no record in the legend

    Does anyone know a good solution, I spend hours searching the web for something to help...

  4. #4
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    <<Does anyone know a good solution, I spend hours searching the web...>>

    I've got a free barchart ASP class (no components) downloadable from my Web site at http://www.bullschmidt.com/barchart.asp to help turn data stored in a table (or SQL statement) into a barchart.

    And it can handle more than one set of data...
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •