Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    58

    Unanswered: insert a chart on a page

    Hello,

    I work in ASP with SQL server.I'd like to insert a chart on a page which I like to use data from my database (via a system DSN).


    Question: how do I get that chart to link to a data source?

    here is the code I use :

    <!-- #include file="conf/sqlserver.asp" -->

    <%

    ' constanten
    dim myConn
    DBName = "NUTS_MEETDB2"
    sqlserverlocation = sqlserver
    sqldbname = DBNAME
    'call RunChart()
    'Response.BinaryWrite(RunChart)
    'Example uses TeeChart's example System ODBC datasource.


    'Send output to browser. 1st time in call CreatePage
    'then call RunChart method to build Chart contents
    if Request.QueryString("CreateChart")=1 Then
    Response.BinaryWrite(RunChart)
    else
    CreatePage
    end if
    'call RunChart
    Function RunChart()

    dim img
    dim Chart
    dim MyVar

    'Create Chart
    Set Chart = CreateObject("TeeChart.TChart")

    'Setup Series
    Chart.AddSeries(scBar)
    Chart.Series(0).Marks.Visible=False

    'Chart.Series(0).asBar.BarStyle=bsPyramid

    'Chart appearance
    Chart.Legend.Visible=False
    Chart.Axis.Bottom.Labels.Angle=90
    Chart.Height=400
    Chart.Width=500
    Chart.Panel.Gradient.Visible=True
    Chart.Header.Text(0)="TeeChart ADO example"
    Chart.Header.Font.Bold=True
    Chart.Axis.Bottom.Title.Caption="Product name"
    Chart.Axis.Bottom.Title.Font.Bold=True
    Chart.Axis.Left.Title.Font.Bold=True

    'Create a random condition to vary the output
    Randomize
    MyVar = (40000)+CInt(rnd*20000)
    'Chart.Axis.Left.Title.Caption="Order Item Totals > " & MyVar

    'Connect to database
    ErrString = ""
    Err.Clear

    call OpenDatabase()


    SQLST = "Select tijdstip, datameeting from Meeting"

    Set RSt = Server.CreateObject("ADODB.RecordSet")
    Set myConRst = myConn.Execute(SQLST, , 1)
    RSt.Open SQLST, myConn, 1
    On error resume next

    if err then
    Response.Write err.Description
    end if


    'Connect Series to Recordset
    if RSt.RecordCount > 0 then
    Chart.Series(0).Datasource = RSt
    Chart.Series(0).LabelsSource="time"
    Chart.Series(0).YValues.ValueSource="Data"
    else
    Chart.Series(0).Fillsamplevalues(10)
    Chart.Header.Text(0)="ADO database returned no values - using random data"
    end if

    'Cleanup and set Chart to send to browser
    call CloseDatabase()
    img=Chart.Export.asPNG.SaveToStream
    Set Chart=nothing
    RunChart=img

    End function

    Function CreatePage
    Response.Write("<html>" & chr(13))
    Response.Write("<HEAD><title>TeeChart Pro AX Control ADO with ASP example</title>" & chr(13))
    Response.Write("<LINK REL=STYLESHEET TYPE=""text/css"" HREF=""Style.css""></HEAD><BODY>" & chr(13))
    Response.Write("<img src=""TeeChart5.png"">" & chr(13))
    Response.Write("<br><br>" & chr(13))
    Response.Write("<a href=""ASPHome.htm"">Back to Contents page</a>" & chr(13))
    Response.Write("<hr>" & chr(13))
    Response.Write("<img id=Img1 src=""ADOTeeChart5.asp?CreateChart=1"">" & chr(13))
    Response.Write("<p>Please note that server Datsources should be System DSNs not User DSNs.</p>" & chr(13))
    Response.Write("<HR>Copyright 2002 Steema Software SL</BODY></HTML>" & chr(13))
    Response.Write("</body>" & chr(13))
    Response.Write("</html>" & chr(13))
    End Function

    function OpenDatabase()

    Application.lock

    sConnection = "DRIVER={SQL SERVER};Server=" & sqlserverlocation & ";Database=" & sqldbname & ";UID=AiSE_RW;PWD=3333"
    Set myConn = Server.CreateObject("ADODB.Connection")
    myConn.open sConnection

    end function

    function CloseDatabase()

    On error resume next
    RSt.Close
    myConn.Close
    Set RSt = nothing
    set myConn = nothing
    application.unlock

    end function

    %>

    Can any one help me or to give me a code that should work


    I'm new in ASP.
    Thanks,
    Faamugol

  2. #2
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    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...

    Also you may want to check out the following:

    Components: Graphics & Charts
    http://www.aspin.com/home/components/graphics
    Lists components.

    And in general parts of your charting would be done within recordset looping. Thus the chart object (or class) itself might not actually be connected in any way to the database itself.
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

  3. #3
    Join Date
    Mar 2004
    Posts
    58
    Thank you Paul Schmidt for your answer..

    I' ve tried your code but I' m still not getting any result..
    Do I have to install any ActiveX component to run your example...

    I read data from a database: sql server or from a xml file..

    How to a manage to link my series to my database.

    I' ll appreciate any help..

  4. #4
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    No you don't have to use any ActiveX component.

    To create a bar chart on a Web page you would include another Web page called jpschart.asp:
    <!--#include file="jpschart.asp"-->

    And the trick for using the chart with a recordset is the same concept as writing data to an HTML table from a recordset and that is this - within your loop through the recordset you retrieve values such as objRS("Sales") and in this case write those values to the chart object instead of writing those values to the HTML table.
    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
  •