By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,321 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,321 IT Pros & Developers. It's quick & easy.

Server-side DB & client-side chart

P: n/a
I have connected to SQL Server database (server-side vbscript) and read some
data from the tables. This works correctly. I now have the data in an array
(server-side).

I have to draw a line-chart based on that data, for which purpose I need to
create client-side component (this works also perfectly).

PROBLEM: I cannot use the server-side array for drawing the chart.

Here's the code shortly:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Graph</title>
</head>
<%
Session.Timeout = 10
Response.Expires = -1000
Dim objConn, objRS, strQuery
Dim objRS2, strQuery2
Dim strConnection
Dim dataArray(999)

Set objConn = Server.CreateObject("ADODB.Connection")
strConnection = "DSN=LocalServer;Database=ASPTest;UID=sa;PWD=; "
objConn.Open strConnection

'count number of records
strQuery = "SELECT Count(*) AS recCount FROM tblCurrent"
set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strQuery, objConn, 3, 3

Response.Write(objRS("recCount") & "<br><br>")

'read the firstname and the lastname
strQuery2 = "SELECT * FROM tblCurrent"
set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open strQuery2, objConn, 3, 3

for i = 0 to (objRS("recCount")-1)
dataArray(i) = objRS2("fCurrent")
Response.Write (dataArray(i) & "<br>")
objRS2.movenext
next

objConn.Close
set objConn = nothing

%>
<script language="vbscript">
function updateData()
TChart1.AddSeries(asFastLine)
TChart1.Series(0).Clear
TChart1.Zoom.Enable = true
TChart1.Legend.CheckBoxes = true

with TChart1
.Zoom.Animated = true
.Zoom.AnimatedSteps = 5
end with

TChart1.Series(0).AddArray 9, array1
end function
</script>
<body>

<input type="button" value="Example" name="btnChart" onClick="updateData()"
style="position:absolute;top:550px;left:10px">

<OBJECT classid="clsid:536600D3-70FE-4C50-92FB-640F6BFC49AD"
codebase="TeeChart6.ocx#version=6,0,0,0"
id=TChart1
TYPE="application/x-oleobject"
width=500
height=400
align=center
hspace=0
vspace=0
style="position:absolute;top:100px;left:100px">
</OBJECT>

</body>
</html>

Anyone know, how to use the server-side array in my client-side code for
drawing the chart?

TIA

Mike
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Idea.

Write out Javascript that 'creates' an array on the client side to then pass
to the component.

eg.

Response.Write "<SCRIPT language=Javascript>"
Response.Write " var parrArray = new Array();"
Response.Write " parrArray = '[12,13,14,15]';"
Response.Write "</SCRIPT>

Of course the 12...15 would be output probably by a loop of some sort.

Anyway, once you have the array at the client end then pass that to the
client-side component.

Hope this helps.

Chris.
"Mick Turner" <c_******@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP11.phx.gbl...
I have connected to SQL Server database (server-side vbscript) and read some
data from the tables. This works correctly. I now have the data in an array
(server-side).

I have to draw a line-chart based on that data, for which purpose I need to
create client-side component (this works also perfectly).

PROBLEM: I cannot use the server-side array for drawing the chart.

Here's the code shortly:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Graph</title>
</head>
<%
Session.Timeout = 10
Response.Expires = -1000
Dim objConn, objRS, strQuery
Dim objRS2, strQuery2
Dim strConnection
Dim dataArray(999)

Set objConn = Server.CreateObject("ADODB.Connection")
strConnection = "DSN=LocalServer;Database=ASPTest;UID=sa;PWD=; "
objConn.Open strConnection

'count number of records
strQuery = "SELECT Count(*) AS recCount FROM tblCurrent"
set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strQuery, objConn, 3, 3

Response.Write(objRS("recCount") & "<br><br>")

'read the firstname and the lastname
strQuery2 = "SELECT * FROM tblCurrent"
set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open strQuery2, objConn, 3, 3

for i = 0 to (objRS("recCount")-1)
dataArray(i) = objRS2("fCurrent")
Response.Write (dataArray(i) & "<br>")
objRS2.movenext
next

objConn.Close
set objConn = nothing

%>
<script language="vbscript">
function updateData()
TChart1.AddSeries(asFastLine)
TChart1.Series(0).Clear
TChart1.Zoom.Enable = true
TChart1.Legend.CheckBoxes = true

with TChart1
.Zoom.Animated = true
.Zoom.AnimatedSteps = 5
end with

TChart1.Series(0).AddArray 9, array1
end function
</script>
<body>

<input type="button" value="Example" name="btnChart" onClick="updateData()"
style="position:absolute;top:550px;left:10px">

<OBJECT classid="clsid:536600D3-70FE-4C50-92FB-640F6BFC49AD"
codebase="TeeChart6.ocx#version=6,0,0,0"
id=TChart1
TYPE="application/x-oleobject"
width=500
height=400
align=center
hspace=0
vspace=0
style="position:absolute;top:100px;left:100px">
</OBJECT>

</body>
</html>

Anyone know, how to use the server-side array in my client-side code for
drawing the chart?

TIA

Mike

Jul 19 '05 #2

P: n/a

I use this technique alot ... 'cept I get lazy with my response writes
.... just throw the array into a delimited string, and write the string
into the javascript

Response.Write "var arrString = " & yourDelimitedString
then just include the split command to get this into your array

Brynn
www.coolpier.com


On Thu, 29 Jan 2004 14:42:15 -0000, "Chris Barber"
<ch***@blue-canoe.co.uk.NOSPAM> wrote:
Idea.

Write out Javascript that 'creates' an array on the client side to then pass
to the component.

eg.

Response.Write "<SCRIPT language=Javascript>"
Response.Write " var parrArray = new Array();"
Response.Write " parrArray = '[12,13,14,15]';"
Response.Write "</SCRIPT>

Of course the 12...15 would be output probably by a loop of some sort.

Anyway, once you have the array at the client end then pass that to the
client-side component.

Hope this helps.

Chris.
"Mick Turner" <c_******@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP11.phx.gbl...
I have connected to SQL Server database (server-side vbscript) and read some
data from the tables. This works correctly. I now have the data in an array
(server-side).

I have to draw a line-chart based on that data, for which purpose I need to
create client-side component (this works also perfectly).

PROBLEM: I cannot use the server-side array for drawing the chart.

Here's the code shortly:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Graph</title>
</head>
<%
Session.Timeout = 10
Response.Expires = -1000
Dim objConn, objRS, strQuery
Dim objRS2, strQuery2
Dim strConnection
Dim dataArray(999)

Set objConn = Server.CreateObject("ADODB.Connection")
strConnection = "DSN=LocalServer;Database=ASPTest;UID=sa;PWD=; "
objConn.Open strConnection

'count number of records
strQuery = "SELECT Count(*) AS recCount FROM tblCurrent"
set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strQuery, objConn, 3, 3

Response.Write(objRS("recCount") & "<br><br>")

'read the firstname and the lastname
strQuery2 = "SELECT * FROM tblCurrent"
set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open strQuery2, objConn, 3, 3

for i = 0 to (objRS("recCount")-1)
dataArray(i) = objRS2("fCurrent")
Response.Write (dataArray(i) & "<br>")
objRS2.movenext
next

objConn.Close
set objConn = nothing

%>
<script language="vbscript">
function updateData()
TChart1.AddSeries(asFastLine)
TChart1.Series(0).Clear
TChart1.Zoom.Enable = true
TChart1.Legend.CheckBoxes = true

with TChart1
.Zoom.Animated = true
.Zoom.AnimatedSteps = 5
end with

TChart1.Series(0).AddArray 9, array1
end function
</script>
<body>

<input type="button" value="Example" name="btnChart" onClick="updateData()"
style="position:absolute;top:550px;left:10px">

<OBJECT classid="clsid:536600D3-70FE-4C50-92FB-640F6BFC49AD"
codebase="TeeChart6.ocx#version=6,0,0,0"
id=TChart1
TYPE="application/x-oleobject"
width=500
height=400
align=center
hspace=0
vspace=0
style="position:absolute;top:100px;left:100px">
</OBJECT>

</body>
</html>

Anyone know, how to use the server-side array in my client-side code for
drawing the chart?

TIA

Mike


Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!
Jul 19 '05 #3

P: n/a
"Mick Turner" <c_******@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP11.phx.gbl...
I have connected to SQL Server database (server-side vbscript) and read some data from the tables. This works correctly. I now have the data in an array (server-side).

I have to draw a line-chart based on that data, for which purpose I need to create client-side component (this works also perfectly).

PROBLEM: I cannot use the server-side array for drawing the chart.

Here's the code shortly:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Graph</title>
</head>
<%
Session.Timeout = 10
Response.Expires = -1000
Dim objConn, objRS, strQuery
Dim objRS2, strQuery2
Dim strConnection
Dim dataArray(999)

Set objConn = Server.CreateObject("ADODB.Connection")
strConnection = "DSN=LocalServer;Database=ASPTest;UID=sa;PWD=; "
objConn.Open strConnection

'count number of records
strQuery = "SELECT Count(*) AS recCount FROM tblCurrent"
set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strQuery, objConn, 3, 3

Response.Write(objRS("recCount") & "<br><br>")

'read the firstname and the lastname
strQuery2 = "SELECT * FROM tblCurrent"
set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open strQuery2, objConn, 3, 3

for i = 0 to (objRS("recCount")-1)
dataArray(i) = objRS2("fCurrent")
Response.Write (dataArray(i) & "<br>")
objRS2.movenext
next

objConn.Close
set objConn = nothing

%>
<script language="vbscript">
function updateData()
TChart1.AddSeries(asFastLine)
TChart1.Series(0).Clear
TChart1.Zoom.Enable = true
TChart1.Legend.CheckBoxes = true

with TChart1
.Zoom.Animated = true
.Zoom.AnimatedSteps = 5
end with

TChart1.Series(0).AddArray 9, array1
end function
</script>
<body>

<input type="button" value="Example" name="btnChart" onClick="updateData()" style="position:absolute;top:550px;left:10px">

<OBJECT classid="clsid:536600D3-70FE-4C50-92FB-640F6BFC49AD"
codebase="TeeChart6.ocx#version=6,0,0,0"
id=TChart1
TYPE="application/x-oleobject"
width=500
height=400
align=center
hspace=0
vspace=0
style="position:absolute;top:100px;left:100px">
</OBJECT>

</body>
</html>

Anyone know, how to use the server-side array in my client-side code for drawing the chart?


<%@LANGUAGE="VBSCRIPT"%>
<%
Dim cn,rs,arr,str
Set cn = CreateObject("ADODB.Connection")
cn.Open "<Your DSN-Less OLEDB Connection String>"
Set rs = cn.Execute "SELECT fCurrent FROM tblCurrent"
If Not rs.EOF Then arr = rs.GetRows()
rs.Close : Set rs = Nothing
cn.Close : Set cn = Nothing
If IsArray(arr) Then str = Join(arr,",")
%>
<html>
<head>
<title>Graph</title>
<script language="vbscript">
function updateData()
Dim array1
array1 = Array(<%=str%>)
TChart1.AddSeries(asFastLine)
TChart1.Series(0).Clear
TChart1.Zoom.Enable = true
TChart1.Legend.CheckBoxes = true
with TChart1
.Zoom.Animated = true
.Zoom.AnimatedSteps = 5
end with
TChart1.Series(0).AddArray 9, array1
end function
</script>
</head>
<body>
<input type="button" value="Example" name="btnChart"
onClick="updateData()"
style="position:absolute;top:550px;left:10px">
<OBJECT classid="clsid:536600D3-70FE-4C50-92FB-640F6BFC49AD"
codebase="TeeChart6.ocx#version=6,0,0,0"
id=TChart1
TYPE="application/x-oleobject"
width=500
height=400
align=center
hspace=0
vspace=0
style="position:absolute;top:100px;left:100px">
</OBJECT>
</body>
</html>

Notes:
1. When referencing a database, please provide DDL and sample data.
Here's an article:
http://aspfaq.com/5006

2. Please consider using a DSN-Less OLEDB connection string. Here's an
article:
http://aspfaq.com/2126

3. Please try to avoid using "SELECT *". Here's an article:
http://aspfaq.com/2096

HTH
-Chris Hohmann

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.