?
Solved

how to draw the graph in ASP?

Posted on 2003-02-24
7
Medium Priority
?
421 Views
Last Modified: 2012-06-27
how to draw the graph in ASP?
0
Comment
Question by:dhanalakshmi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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