Server-side DB & client-side chart

M

Mick Turner

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
 
C

Chris Barber

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.


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
 
B

Brynn

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




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.


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!
 
C

Chris Hohmann

Mick Turner said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top