Draw line on canvas using VBScript/ASP

TeeChart for ActiveX, COM and ASP
Post Reply
ITI
Newbie
Newbie
Posts: 8
Joined: Tue Apr 05, 2005 4:00 am

Draw line on canvas using VBScript/ASP

Post by ITI » 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 &copy; 2004 Steema Software SL</BODY></HTML>" & chr(13))
Response.Write("</body>" & chr(13))
Response.Write("</html>" & chr(13))
End Function

%>

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Wed May 20, 2009 1:58 pm

Hi Bob,

This works fine here:

Code: Select all

<script LANGUAGE="VBScript">
Sub TChart1_OnBeforeDrawSeries()
  TChart1.Canvas.DrawLine 10, 10, 50, 50
End Sub
</script>
And note that it's more common to use OnAfterDraw event to draw on the canvas:

Code: Select all

<script LANGUAGE="VBScript">
Sub TChart1_OnAfterDraw()
  TChart1.Canvas.DrawLine 10, 10, 50, 50
End Sub
</script>
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

ITI
Newbie
Newbie
Posts: 8
Joined: Tue Apr 05, 2005 4:00 am

drawing a line on a chart

Post by ITI » Wed May 20, 2009 2:23 pm

Thank you for the information about the correct event to use. But you do not say where the script should go - in the head, in the body, before the head. I've tried putting the code everywhere but the event does not seem to be triggered.

Using the sample code I posted, can you show where your code should be placed?

Thank you.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Wed May 20, 2009 3:06 pm

Hi Bob,

I've added the code before the head as the other events in the example "TeeFromWebClient.asp" provided with the installer.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

ITI
Newbie
Newbie
Posts: 8
Joined: Tue Apr 05, 2005 4:00 am

still no line

Post by ITI » Thu May 21, 2009 1:26 pm

This is not working for me. Please see the code below. I am using the code from example ADOTeeChart7.asp. I added the event code above the head as you suggested (I changed the name from TChart1 to Chart since that is the name of the object. When I run it, I am not getting a line on the canvas.


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


<script LANGUAGE="VBScript">
Sub Chart_OnAfterDraw()
Chart.Canvas.DrawLine 10, 10, 50, 50
End Sub
</script>


<%
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 &copy; 2004 Steema Software SL</BODY></HTML>" & chr(13))
Response.Write("</body>" & chr(13))
Response.Write("</html>" & chr(13))
End Function

%>

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu May 21, 2009 2:17 pm

Hi Bob,

For getting such events working you need to have a live chart object in the ASP page. You can create a TeeChart template file (*.tee) serverside and load it at the client. Something as in the TeeFromWebClient.asp example, which has double click event implemented.

Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply