469,943 Members | 2,583 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

chart using asp and html

hii...i am creating a chart using html and asp
the code for it is :
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ LANGUAGE="VBSCRIPT" %>
  3. <% Option Explicit %>
  4.  
  5. <%
  6. Dim data1Array(3)
  7. data1Array(0) = 5
  8. data1Array(1) = 15
  9. data1Array(2) = 25
  10. data1Array(3) = 50
  11.  
  12.  
  13. Dim data2Array(3)
  14. data2Array(0) = 5
  15. data2Array(1) = 10
  16. data2Array(2) = 20
  17. data2Array(3) = 25
  18.  
  19.  
  20. Dim labelArray(15)
  21. labelArray(0) = "1"
  22. labelArray(1) = "2"
  23. labelArray(2) = "2"
  24. labelArray(3) = "2"
  25. labelArray(4) = "2"
  26. labelArray(5) = "2"
  27. labelArray(6) = "7"
  28. labelArray(7) = "8"
  29. labelArray(8) = "9"
  30. labelArray(9) = "1"
  31. labelArray(10) = "11"
  32. labelArray(11) = "12"
  33. labelArray(12) = "13"
  34. labelArray(13) = "14"
  35. labelArray(14) = "15"
  36. labelArray(15) = "16"
  37.  
  38. %> 
  39.  
  40. <%
  41. 'How many pixels high we want our bar graph
  42. Const graphHeight = 300
  43. Const graphWidth = 450
  44. Const barImage = "bluebar.gif"
  45. Const barImage1 = "redbar.gif"
  46. 'h 300 , w 450
  47.  
  48. sub BarChart(data1 , data2, labels, title, axislabel)
  49.     'Print heading
  50.     Response.Write("<TABLE CELLSPACING=0 CELLPADDING=2 BORDER=1 WIDTH=" & graphWidth & ">" & chr(13))
  51.     Response.Write("<TR><TH COLSPAN=" & UBound(data1) - LBound(data1) + 2 & ">" & chr(13))
  52.     Response.Write("<FONT SIZE=+2>" & title & "</FONT></TH></TR>" & chr(13))
  53.     Response.Write("<TR><TD VALIGN=TOP ALIGN=RIGHT>" & chr(13))
  54.  
  55.     'Find the highest value
  56.     Dim hi
  57.     hi = data1(LBound(data1))
  58.  
  59.     Dim i
  60.     for i = LBound(data1) to UBound(data1)
  61.         if data1(i) > hi then hi = data1(i)
  62.     next
  63.  
  64.  
  65. 'calculating  highest value for the second array
  66.     Dim hi1
  67.     hi1 = data2(LBound(data2))
  68.  
  69.     Dim j
  70.     for j = LBound(data2) to UBound(data2)
  71.         if data2(j) > hi1 then hi1 = data2(j)
  72.     next
  73.  
  74. 'Response.Write("the hightest value")
  75. 'Response.Write(hi1)
  76.  
  77.  
  78.     'Print out the highest value at the top of the chart
  79.     'Response.Write(hi & "</TD>")
  80.  
  81.     Dim widthpercent
  82.     widthpercent = CInt((1 / (UBound(data1) - LBound(data1) + 1)) * 100)
  83.     'response.Write(widthpercent)
  84.  
  85.     'Response.Write(data2(0))
  86.     'Response.Write(hi1)
  87.     'Response.Write(graphHeight)
  88.     'Response.Write(cint(data2(0)/hi1 * graphHeight))
  89.     'Response.End
  90.  
  91.     For i = LBound(data1) to UBound(data1) 
  92.         Response.Write("<td> </td>")
  93.         Response.Write(" <TD VALIGN=BASELINE ROWSPAN=2 WIDTH=" & widthpercent & "% >" & chr(13))
  94.         Response.Write(" <IMG SRC=""" & barImage & """ WIDTH=100% align= bottom HEIGHT=" & CInt(data1(i)/hi * graphHeight)  & "/>" & chr(13))
  95.         response.Write(Cint(data1(i)/hi*graphHeight))
  96.         Response.Write(" <TD VALIGN=BASELINE ROWSPAN=2 WIDTH=" & widthpercent & "% >" & chr(13))
  97.  
  98.         'response.end
  99.         Response.Write(" <IMG SRC=""" & barImage1& """ WIDTH=100% align= bottom  HEIGHT=" & CInt(data2(i)/hi1 * graphHeight)  & "/>" & chr(13))
  100.         response.Write(Cint(data2(i)/hi*graphHeight))
  101.         Response.Write(" </TD>" & chr(13))
  102.         'Response.Write("<td> </td>")
  103.         'Response.Write("<td> </td>")
  104.          'response.Write("<br>")
  105.          '
  106.          'response.Write("<br>")    
  107.     Next
  108.     'response.end
  109.  
  110.  
  111.     Response.Write("</TR>")
  112.     Response.Write("<TR><TD VALIGN=BOTTOM ALIGN=RIGHT>0</TD></TR>")
  113.  
  114.     'Write footer
  115.     Response.Write("<TR><TD ALIGN=RIGHT VALIGN=BOTTOM>" & axislabel & "</TD>" & chr(13))
  116.     for i = LBound(labels) to UBound(labels)
  117.         Response.Write("<TD VALIGN=BOTTOM ALIGN=CENTER>" & labels(i) & "</TD>" & chr(13))
  118.     next
  119.     Response.Write("</TR>" & chr(13))
  120.     Response.Write("</TABLE>")
  121. end sub
  122.  
  123.  
  124. %>
  125.  
  126. <HTML>
  127. <BODY>
  128. <CENTER>
  129. <% Call BarChart(data1Array,data2Array,labelArray,"Telephone Sales","Date") %>
  130. </CENTER>
  131. </BODY>
  132. </HTML>
  133.  
now the problem is even tough in the following lines, i pass same value for the HEIGHT ATTRIBUTE with data1(0) and data2(0) ARRAYS the displayed height of the image is not same.
SIMILARLY THE HEIGHT SHOWN WITH OTHER ELEMENTS IS ALSO NOT PROPER
Expand|Select|Wrap|Line Numbers
  1. Response.Write(" <TD VALIGN=BASELINE ROWSPAN=2 WIDTH=" & widthpercent & "% >" & chr(13))
  2. Response.Write(" <IMG SRC=""" & barImage & """ WIDTH=100% align= bottom HEIGHT=" & CInt(data1(i)/hi * graphHeight)  & "/>" & chr(13))
  3. Response.Write(" <TD VALIGN=BASELINE ROWSPAN=2 WIDTH=" & widthpercent & "% >" & chr(13))
  4. Response.Write(" <IMG SRC=""" & barImage1& """ WIDTH=100% align= bottom  HEIGHT=" & CInt(data2(i)/hi1 * graphHeight)  & "/>" & chr(13))
  5.  
i am attatching a image file to make my problem more clear..
thank's..
Attached Images
File Type: jpg results.jpg (13.2 KB, 130 views)
Mar 25 '09 #1
1 1905
jhardman
3,406 Expert 2GB
why is one divided by hi1, and the other is divided by hi? What do you get when you print out CInt(data2(i)/hi1 * graphHeight) and CInt(data1(i)/hi*graphHeight)?
Mar 27 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Mick Turner | last post: by
9 posts views Thread by Patrick.O.Ige | last post: by
8 posts views Thread by LB | last post: by
18 posts views Thread by Marcel Saucier | last post: by
2 posts views Thread by RoseW | last post: by
2 posts views Thread by aashishn86 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.