If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > insert a chart on a page

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-04, 08:25
faamugol faamugol is offline
Registered User
 
Join Date: Mar 2004
Posts: 58
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
Reply With Quote
  #2 (permalink)  
Old 03-02-04, 01:38
Bullschmidt Bullschmidt is offline
Guru
 
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
Reply With Quote
  #3 (permalink)  
Old 03-02-04, 05:28
faamugol faamugol is offline
Registered User
 
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..
Reply With Quote
  #4 (permalink)  
Old 03-02-04, 08:10
Bullschmidt Bullschmidt is offline
Guru
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On