Draw line on canvas using VBScript/ASP
Posted: Tue May 19, 2009 6:15 pm
I created a webpage using similar code to the Tee Chart example shown below. Now I need to draw a line on the canvas. I've used Tee Chart with VB6 but this is the first time I've used it with ASP. I know the canvas drawing code needs to be in the OnBeforeDrawSeries event. But where do I put the sub? In the head? Before the head? In the body? Do I use client-side or server-side script? Help!
<!--METADATA NAME="TeeChart Pro v7 ActiveX Control" TYPE="TypeLib" UUID="{EAE6A729-65BD-489F-BF3F-7FE35B416289}"-->
<%
'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
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
Set Conn = Server.CreateObject("ADODB.Connection")
Set RSt = Server.CreateObject("ADODB.RecordSet")
Conn.Open "DSN=TeeChart Pro System db"
Rst.Open "select OrderNo, ItemTotal from orders where ItemTotal > " & MyVar, Conn, 1, 1
'Connect Series to Recordset
if RSt.RecordCount > 0 then
Chart.Series(0).Datasource = RSt
Chart.Series(0).LabelsSource="OrderNo"
Chart.Series(0).YValues.ValueSource="ItemTotal"
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
Rst.close
Conn.close
Set Rst=nothing
Set Conn=nothing
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=""TeeChartAX300x66.jpg"">" & 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=""ADOTeeChart7.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 © 2004 Steema Software SL</BODY></HTML>" & chr(13))
Response.Write("</body>" & chr(13))
Response.Write("</html>" & chr(13))
End Function
%>
<!--METADATA NAME="TeeChart Pro v7 ActiveX Control" TYPE="TypeLib" UUID="{EAE6A729-65BD-489F-BF3F-7FE35B416289}"-->
<%
'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
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
Set Conn = Server.CreateObject("ADODB.Connection")
Set RSt = Server.CreateObject("ADODB.RecordSet")
Conn.Open "DSN=TeeChart Pro System db"
Rst.Open "select OrderNo, ItemTotal from orders where ItemTotal > " & MyVar, Conn, 1, 1
'Connect Series to Recordset
if RSt.RecordCount > 0 then
Chart.Series(0).Datasource = RSt
Chart.Series(0).LabelsSource="OrderNo"
Chart.Series(0).YValues.ValueSource="ItemTotal"
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
Rst.close
Conn.close
Set Rst=nothing
Set Conn=nothing
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=""TeeChartAX300x66.jpg"">" & 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=""ADOTeeChart7.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 © 2004 Steema Software SL</BODY></HTML>" & chr(13))
Response.Write("</body>" & chr(13))
Response.Write("</html>" & chr(13))
End Function
%>