how to draw the graph in ASP?

how to draw the graph in ASP?
dhanalakshmiAsked:
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
0
markhoyCommented:
http://www.4guysfromrolla.com/webtech/042199-1.shtml

The first page describes how to do a static bar chart, but continue on to "Dynamically Creating Bar Charts"
0
patp121Commented:
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 http://www.w3.org/TR/SVG/ 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"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
%>
<g id="db-symbol" style="stroke:#000000;">
<rect x="10" y="10" width="20" height="20">              
</g>
</svg>

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">
</object>

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..

Pat
0
Get expert help—faster!

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

markhoyCommented:
datastore.inc 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;"
DBPath=server.mappath("../messages/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
'DSN=maillist

'strConnect


GRAPH CODE:

<!-- #INCLUDE FILE="../DataStore_bar.inc" -->
<!-- #INCLUDE FILE="../adovbs.inc" -->
<HTML>
<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; }-->
</style>
<BODY>
<CENTER>
<%
dim mode
mode=request("mode")
if mode="VOTE" then
'Response.Write "do update"
insert
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
  objRS.AddNew

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

  objConn.Close
  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)
      next

      '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))
      Next

      Response.Write("</TR>")
      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))
      next
      Response.Write("</TR>" & chr(13))
      Response.Write("<tr><td><input type=""submit"" value=""vote"" id=1 name=1></td></tr></form>" & chr(13))
      Response.Write("</TABLE>")
end sub

Dim strSQL, tdate

tdate= year(DATE())

'strSQL="SELECT DATEPART('m', tracking.date) AS [Month], Count(tracking.country) AS CountOfcountry, country FROM tracking WHERE DATEPART('yyyy', tracking.date)= '" & 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
c=0

'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
      'k=i-1
      'newmonth=month((k))
      'else
      'newmonth=month(i)
      'end if
      if rsProducts.EOF then
      redim preserve unitssoldArray(c)
            redim preserve labelArray(c)
            'monthlong=getmonth(month(i))
      '      monthlong=Getmonth(newmonth)
      end if      
      'BarChart unitsSoldArray,labelArray, "Number of Visits in Country"
      'Response.Write "<HR>"
      'exit for
      'else
      
      'end if
      'if rsProducts.EOF then exit do
      'Response.Write unitsSoldArray(c) & labelArray(c) & "<BR>"
      rsProducts.MoveNext
      c=c+1
      loop
End if
      'next
      'labelArray="day,day,day,day"
 'labelArray="w1,w2,w3,w4"
 dim label(4)
 label(0)="3rd"
 label(1)="10th"
 label(2)="17th"
 label(3)="23rd"
c=0
'BarChart unitsSoldArray,labelArray, "vote","Weekend"
BarChart unitsSoldArray,label, "vote","November"
'loop
%>

</CENTER>
<CENTER>

</CENTER><BR>
</BODY>
</HTML>

<%
      rsProducts.Close
      Set rsProducts = Nothing

      'strconnect.Close
      Set strconnect = Nothing
%>
0

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
CleanupPingCommented:
dhanalakshmi:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
GaryCommented:
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.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0
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
ASP

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.