Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to draw the graph in ASP?

Posted on 2003-02-24
7
Medium Priority
?
423 Views
Last Modified: 2012-06-27
how to draw the graph in ASP?
0
Comment
Question by:dhanalakshmi
6 Comments
 

Author Comment

by:dhanalakshmi
ID: 8007331
how to draw the graph in ASP?
reply as soon as possible
0
 
LVL 7

Expert Comment

by:markhoy
ID: 8007358
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
 

Expert Comment

by:patp121
ID: 8008470
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
markhoy earned 80 total points
ID: 8008592
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
 

Expert Comment

by:CleanupPing
ID: 9576918
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
 
LVL 58

Expert Comment

by:Gary
ID: 9753998
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question