how to draw the graph in ASP?

how to draw the graph in ASP?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dhanalakshmiAuthor Commented:
how to draw the graph in ASP?
reply as soon as possible

The first page describes how to do a static bar chart, but continue on to "Dynamically Creating Bar Charts"
You can also use svg to draw dynamic graphs in asp, but you'll have to learn a bit of svg to do it! Look at for the specification. Users will have to download an svg plugin aswell (adobe svg), but that does not take long.

Basically, what you'll need to do in order to do graphs this way is create an asp file with the header and content something like;

Option Explicit
%><?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
<svg xmlns="">
<g id="db-symbol" style="stroke:#000000;">
<rect x="10" y="10" width="20" height="20">              

This would (should, I havn't tested it) simply draw a rectangle. With a little bit of work you can display anything including graphs, and of course, you can set any of the fields such as the width or height to be dynamic within asp, so you can have dynamic graphs.

You can then call the above code from any page where you would like to see it with something like:

<object type=""image/svg+xml"" data=""graph-horizbar.asp">

This is prob. the best way to do produce graphs within asp since you can get the graphs to look as nice as you like, and they will display on any browser that will install the svg plugin. The only problem is that you need to make all the drawing calculations to draw the graph yourself..

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

markhoyCommented: contains the connection string:

'this page provides a generic database include script

' use this connect string for the Access tables
' change the following
'YourDB            to the physical path of your database

'strConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\inetpub\wwwroot\databases\wche.mdb;"
strConnectr="DRIVER=Microsoft Access Driver (*.mdb); UID=admin; UserCommitSync=Yes; Threads=4; SafeTransactions=1; PageTimeout=5; MaxScanRows=8; MaxBufferSize=2048; FIL=MS Access;DriverId=281; DBQ=" & DBPath

' use this connect string for a DSN data store
' change the following



<!-- #INCLUDE FILE="../" -->
<!-- #INCLUDE FILE="../" -->
<style type="text/css">
.vdate{  font-family: "Trebuchet MS", Arial, Verdana; color: #000000; font-weight: bold}
.other{  font-family: "Trebuchet MS", Arial, Verdana; color: #000000; }-->
dim mode
if mode="VOTE" then
'Response.Write "do update"
end if
dim conn
'How many pixels high we want our bar graph
Const graphHeight = 300
Const graphWidth = 450
Const barImage = "bluebar.gif"

sub insert
'Create a connection to our database
  Dim objRS, objConn
  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open strConnect

  'Open the recordset, grabbing the requested table
  Set objRS = Server.CreateObject("ADODB.Recordset")
  objRS.Open "weekend", objConn,adOpenKeyset , adLockPessimistic, adCmdTable

  'Add a new record

on error resume next
  objRS.Update  'needed to solidify our changes!
  'Clean up, and redirect the user
  Set objRS = Nothing

  Set objConn = Nothing
end sub

sub BarChart(data, labels, title, axislabel)
      'Print heading
      Response.Write("<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0 WIDTH=" & graphWidth & ">" & chr(13))
      Response.Write("<TR class=""other""><TH COLSPAN=" & UBound(data) - LBound(data) + 2 & ">")
      Response.Write("<FONT SIZE=+2>" & title & "</FONT></TH></TR>" & chr(13))
      Response.Write("<TR><TD VALIGN=TOP ALIGN=RIGHT>" & chr(13))

      'Find the highest value
      Dim hi
      hi = data(LBound(data))

      Dim i
      for i = LBound(data) to UBound(data) - 1
            if data(i) > hi then hi = data(i)

      'Print out the highest value at the top of the chart
      Response.Write(hi & "</TD>")

      Dim widthpercent
      widthpercent = CInt((1 / (UBound(data) - LBound(data) + 1)) * 100)

      For i = LBound(data) to UBound(data) - 1
            Response.Write(" <TD VALIGN=BOTTOM ROWSPAN=2 WIDTH=" & widthpercent & "% >" & chr(13))
            Response.Write("   <IMG SRC=""" & barImage & """ WIDTH=100% HEIGHT=" & CInt(data(i)/hi * graphHeight) & ">" & chr(13))
            Response.Write(" </TD>" & chr(13))

      Response.Write("<TR><TD VALIGN=BOTTOM ALIGN=RIGHT>0</TD></TR>")
      Response.write("<form action=""barchart.asp"" method=""POST"" id=form1 name=form1>")
      Response.Write("<input type=""hidden"" name=""mode"" value=""VOTE"">")
      'Write footer
      Response.Write("<TR><TD ALIGN=RIGHT VALIGN=BOTTOM class=""other"">" & axislabel & "</TD>" & chr(13))
      for i = LBound(labels) to UBound(labels) - 1
            Response.Write("<TD VALIGN=BOTTOM ALIGN=CENTER class=""vdate"">" & labels(i) & "<BR><input type=""radio"" name=""week"" value="&i+1&"></TD>" & chr(13))
      Response.Write("</TR>" & chr(13))
      Response.Write("<tr><td><input type=""submit"" value=""vote"" id=1 name=1></td></tr></form>" & chr(13))
end sub

Dim strSQL, tdate

tdate= year(DATE())

'strSQL="SELECT DATEPART('m', AS [Month], Count( AS CountOfcountry, country FROM tracking WHERE DATEPART('yyyy', '" & tdate & "' GROUP BY DATEPART('m', tracking.Date), country;"
strSQL="SELECT Count(weekend.week) AS CountOfcountry from weekend GROUP by week"
'Response.Write strSQL
Dim rsProducts
Set rsProducts = Server.CreateObject("ADODB.Recordset")
rsProducts.Open strSQL, strconnect, adOpenStatic, adLockOptimistic,adCmdText

Dim numRecords, newmonth
numRecords = rsProducts.RecordCount
'Response.Write numRecords
Dim unitsSoldArray(), labelArray(), month()

Dim i, c, monthlong, k

'do while c<numRecords-1 AND not rsProducts.EOF
Redim unitsSoldArray(numRecords)
Redim labelArray(numRecords)
'Redim month(numRecords)
if not rsProducts.EOF then
do while  not rsProducts.EOF
    'for i = c to numRecords-1
      unitsSoldArray(c) = rsProducts("CountOfcountry")
      labelArray(c) = " Week " & c
      'month(i)= rsProducts("month")
      'if i>0 then
      'end if
      if rsProducts.EOF then
      redim preserve unitssoldArray(c)
            redim preserve labelArray(c)
      '      monthlong=Getmonth(newmonth)
      end if      
      'BarChart unitsSoldArray,labelArray, "Number of Visits in Country"
      'Response.Write "<HR>"
      'exit for
      'end if
      'if rsProducts.EOF then exit do
      'Response.Write unitsSoldArray(c) & labelArray(c) & "<BR>"
End if
 dim label(4)
'BarChart unitsSoldArray,labelArray, "vote","Weekend"
BarChart unitsSoldArray,label, "vote","November"



      Set rsProducts = Nothing

      Set strconnect = Nothing

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by markhoy

Please leave any comments here within the next seven days.
EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.