LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Links

Wiki
Blog

Forum Statistics

Users
Members:
1884
Members Online:
1
Guests Online:
11

Total Post History
Posts:
81461
Topics:
18719

7-Day Post History
New Posts:
4
New Topics:
1
Active Topics:
2

Our newest member
manails232x

Other

FAQ
All times are UTC [ DST ]

Why i cant display the bar chart?

Please wait...

Why i cant display the bar chart?

Postby joyce16 on Fri Sep 24, 2010 7:11 am

Hi.Why i can't display the bar chart?
Here's my code:
  1. Imports Microsoft.VisualBasic
  2. Imports System
  3. Imports System.Drawing
  4. Imports System.Drawing.Drawing2D
  5. Imports System.Drawing.Imaging
  6.  
  7. Public Class Barchart
  8.     'variable declaration
  9.     Public b As Bitmap
  10.     Public title As String = "Default Title"
  11.     Public chartValues As ArrayList = New ArrayList()
  12.     Public Xorigin As Decimal = 0
  13.     Public Yorigin As Decimal = 0
  14.     Public scaleX As Decimal
  15.     Public scaleY As Decimal
  16.     Public Xdivs As Decimal = 2
  17.     Public Ydivs As Decimal = 2
  18.  
  19.     Private rndColor As New Random
  20.     Private width As Integer
  21.     Private height As Integer
  22.     Private g As Graphics
  23.     Private p As Page
  24.  
  25.     Structure datapoint
  26.         Dim x As Decimal
  27.         Dim y As Decimal
  28.         Dim valid As Boolean
  29.  
  30.        
  31.     End Structure
  32.     Public Sub New(ByVal myWidth As Integer, ByVal myHeight As Integer, ByVal myPage As Page)
  33.         width = myWidth
  34.         height = myHeight
  35.         scaleX = myWidth
  36.         scaleY = myHeight
  37.         b = New Bitmap(myWidth, myHeight)
  38.         g = Graphics.FromImage(b)
  39.         p = myPage
  40.        
  41.         Dim blackPen As New Pen(Color.Black, 1)
  42.        
  43.  
  44.        
  45.      
  46.     End Sub
  47.  
  48.     Public Sub addValue(ByVal x As Decimal, ByVal y As Decimal)
  49.         Dim myPoint As datapoint
  50.         myPoint.x = x
  51.         myPoint.y = y
  52.         myPoint.valid = True
  53.         chartValues.Add(myPoint)
  54.     End Sub
  55.     Public Function RandomRGBColor() As Color
  56.         ' Return a random color.  
  57.         Return (Color.FromArgb(255, rndColor.Next(0, 255), rndColor.Next(0, 255), rndColor.Next(0, 255)))
  58.     End Function
  59.  
  60.     Public Sub DrawBarGraph()
  61.         Dim x As Decimal
  62.         Dim y As Decimal
  63.         Dim x0 As Decimal
  64.         Dim y0 As Decimal
  65.  
  66.  
  67.         Dim intSpacing As Integer = 40
  68.         Dim intBarWidth As Integer = 20
  69.         Dim intBarScale As Integer = 10
  70.         Dim intMaxHeight As Integer = 0
  71.         Dim intMaxWidth As Integer = 0
  72.         Dim gWidth As Graphics = Graphics.FromImage(New Bitmap(1, 1))
  73.         Dim strYAxis As String()
  74.         Dim strXAxis As String()
  75.  
  76.        
  77.        
  78.         Dim mylabel As String
  79.         Dim blackPen As New Pen(Color.Black, 1)
  80.         Dim blackBrush As New SolidBrush(Color.Black)
  81.         Dim axesFont As New Font("arial", 10)
  82.  
  83.  
  84.         'first establish working area
  85.         p.Response.ContentType = "image/jpeg"
  86.         g.FillRectangle(New SolidBrush(Color.LightYellow), 0, 0, width, height) 'to draw a rectangle
  87.         g.FillRectangle(New SolidBrush(Color.Ivory), 0, 0, x, y)
  88.  
  89.  
  90.  
  91.         Dim ChartInset As Integer = 50
  92.         Dim ChartWidth As Integer = width - (2 * ChartInset)
  93.         Dim ChartHeight As Integer = height - (2 * ChartInset) 'Height for the chart
  94.         g.DrawRectangle(New Pen(Color.Black, 1), ChartInset, ChartInset, ChartWidth, ChartHeight)
  95.  
  96.         'must draw all text items before doing the rotate below
  97.         g.DrawString(title, New Font("arial", 14), Brushes.Black, width / 3, 10)
  98.  
  99.         Dim objBrush As SolidBrush = New SolidBrush(Color.FromArgb(70, 10, 10))
  100.  
  101.  
  102.  
  103.         'draw X axis labels
  104.         For z As Integer = 0 To Ydivs Step 1
  105.             x = ChartInset + (z * ChartWidth) / Xdivs
  106.             y = ChartHeight + ChartInset
  107.             mylabel = (Xorigin + (scaleX * z / Xdivs)).ToString()
  108.  
  109.             If mylabel.Contains(".5") Then
  110.                 mylabel = mylabel.Replace(".5", ":30")
  111.             Else
  112.                 mylabel &= ":00"
  113.             End If
  114.  
  115.             If Not String.Equals(mylabel, "24:00") Then
  116.                 g.DrawString(mylabel, axesFont, blackBrush, x - 4, y + 10)
  117.             End If
  118.  
  119.  
  120.         Next
  121.  
  122.         'draw Y axis labels
  123.         For z As Integer = 0 To Ydivs Step 1
  124.             x = ChartInset
  125.             y = ChartHeight + ChartInset - (z * ChartHeight / Ydivs)
  126.             mylabel = (Yorigin + (scaleY * z / Ydivs)).ToString()
  127.             g.DrawString(mylabel, axesFont, blackBrush, 5, y - 6)
  128.  
  129.         Next
  130.  
  131.  
  132.  
  133.         'transform drawing coords to lower-left (0,0)
  134.         g.RotateTransform(90)
  135.         g.TranslateTransform(0, -height)
  136.         g.TranslateTransform(-ChartInset, ChartInset)
  137.         g.ScaleTransform(-1, 1)
  138.  
  139.         'draw(Barchart)
  140.         For z As Integer = 0 To Ydivs Step 1
  141.             ' Add the coloured bar  
  142.             g.FillRectangle(New SolidBrush(RandomRGBColor), (z * intSpacing) + (z * intBarWidth) + 15, _
  143.         intMaxHeight - (CInt(chartValues(z)) * intBarScale), intBarWidth, (CInt(chartValues(z)) * intBarScale))
  144.         Next
  145.  
  146.         For z As Integer = 0 To Xdivs Step 1
  147.             ' Add the coloured bar  
  148.             g.FillRectangle(New SolidBrush(RandomRGBColor), (z * intSpacing) + (z * intBarWidth) + 15, _
  149.         intMaxHeight - (CInt(chartValues(z)) * intBarScale), intBarWidth, (CInt(chartValues(z)) * intBarScale))
  150.         Next
  151.  
  152.  
  153.  
  154.         b.Save("C:\Weather\abc.gif", ImageFormat.Gif)
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.     End Sub
  163.     Protected Overrides Sub Finalize()
  164.         g.Dispose()
  165.         b.Dispose()
  166.     End Sub
  167.  
  168. End Class


Thanks!
joyce16
Apprentice
Apprentice
 
Posts: 8
Joined: Fri Sep 24, 2010 7:05 am
Unrated

Re: Why i cant display the bar chart?

Postby ca8msm on Fri Sep 24, 2010 8:15 am

Where are you expecting the image to be displayed?
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England
Unrated

Re: Why i cant display the bar chart?

Postby joyce16 on Mon Sep 27, 2010 1:27 am

ca8msm wrote:Where are you expecting the image to be displayed?


I'm expecting the image to be display at the web browers. However,when i put this code b.Save(p.Response.OutputStream, ImageFormat.Jpeg) a error will occur.
joyce16
Apprentice
Apprentice
 
Posts: 8
Joined: Fri Sep 24, 2010 7:05 am
Unrated

Re: Why i cant display the bar chart?

Postby ca8msm on Mon Sep 27, 2010 8:09 am

joyce16 wrote:
ca8msm wrote:Where are you expecting the image to be displayed?


I'm expecting the image to be display at the web browers. However,when i put this code b.Save(p.Response.OutputStream, ImageFormat.Jpeg) a error will occur.

OK, your code above didn't have that line, it just had it saving to local file which is why it wasn't obvious what you were trying to do. What error occurs when you try to write it out to a web browser?
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England
Unrated

Re: Why i cant display the bar chart?

Postby joyce16 on Mon Sep 27, 2010 9:28 am

ca8msm wrote:
joyce16 wrote:
ca8msm wrote:Where are you expecting the image to be displayed?


I'm expecting the image to be display at the web browers. However,when i put this code b.Save(p.Response.OutputStream, ImageFormat.Jpeg) a error will occur.

OK, your code above didn't have that line, it just had it saving to local file which is why it wasn't obvious what you were trying to do. What error occurs when you try to write it out to a web browser?



I'hv already solve the error.I am trying to create a barchart abd line chart using 2 different button. But when i click view barchart, the linechart will appear instead. I have include my file for the programme. Pls help me take a look.I also cannot display my barchart.I can only display the axis. As i am new to asp.net,i dunno many things. Thanks very much for ur help!
You do not have the required permissions to view the files attached to this post.
joyce16
Apprentice
Apprentice
 
Posts: 8
Joined: Fri Sep 24, 2010 7:05 am
Unrated

Re: Why i cant display the bar chart?

Postby ca8msm on Mon Sep 27, 2010 9:45 am

joyce16 wrote:I'hv already solve the error.I am trying to create a barchart abd line chart using 2 different button. But when i click view barchart, the linechart will appear instead. I have include my file for the programme. Pls help me take a look.I also cannot display my barchart.I can only display the axis. As i am new to asp.net,i dunno many things. Thanks very much for ur help!


So you've solved the initial error about displaying the chart on the web page and you have a new error with something else now?

I downloaded your attached file and even on compiling the project it had multiple errors such as:
Error 1 Name 'Request' is not declared. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 82 20 C:\...\Project_FYP\
Error 2 Name 'Request' is not declared. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 83 20 C:\...\Project_FYP\
Error 3 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 146 34 C:\...\Project_FYP\
Error 4 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 146 82 C:\...\Project_FYP\
Error 5 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 149 34 C:\...\Project_FYP\
Error 6 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 149 82 C:\...\Project_FYP\
Error 7 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 152 97 C:\...\Project_FYP\
Error 8 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 155 92 C:\...\Project_FYP\


I'd suggest breaking your application up into separate test scripts and trying to get one thing to work at a time, it's pretty confusing reading your posts as to exactly what isn't working and what you are trying to do.
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England
Unrated

Re: Why i cant display the bar chart?

Postby joyce16 on Mon Sep 27, 2010 9:58 am

ca8msm wrote:
joyce16 wrote:I'hv already solve the error.I am trying to create a barchart abd line chart using 2 different button. But when i click view barchart, the linechart will appear instead. I have include my file for the programme. Pls help me take a look.I also cannot display my barchart.I can only display the axis. As i am new to asp.net,i dunno many things. Thanks very much for ur help!


So you've solved the initial error about displaying the chart on the web page and you have a new error with something else now?

I downloaded your attached file and even on compiling the project it had multiple errors such as:
Error 1 Name 'Request' is not declared. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 82 20 C:\...\Project_FYP\
Error 2 Name 'Request' is not declared. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 83 20 C:\...\Project_FYP\
Error 3 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 146 34 C:\...\Project_FYP\
Error 4 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 146 82 C:\...\Project_FYP\
Error 5 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 149 34 C:\...\Project_FYP\
Error 6 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 149 82 C:\...\Project_FYP\
Error 7 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 152 97 C:\...\Project_FYP\
Error 8 'Char' values cannot be converted to 'Integer'. Use 'Microsoft.VisualBasic.AscW' to interpret a character as a Unicode value or 'Microsoft.VisualBasic.Val' to interpret it as a digit. C:\Documents and Settings\CEISMS1\Desktop\Weather\Project_FYP\App_Code\BarChart.vb 155 92 C:\...\Project_FYP\


I'd suggest breaking your application up into separate test scripts and trying to get one thing to work at a time, it's pretty confusing reading your posts as to exactly what isn't working and what you are trying to do.


I can't display the bar chart due to the error and i don noe how to solve them. Could u give me some hints as to where i haf gone wrong? Thanks very much for ur help once again..
joyce16
Apprentice
Apprentice
 
Posts: 8
Joined: Fri Sep 24, 2010 7:05 am
Unrated

Re: Why i cant display the bar chart?

Postby ca8msm on Mon Sep 27, 2010 10:07 am

Are you referring to the errors I listed above?

If so, then the first one is because you are trying to access the Request object from a class file in the App_Code folder and it should only really be accessed from the code behind of a Page (there are exceptions but not for this case).

If you read the second error message, it tells you what the error is and gives you two recommended approaches to dealing with it depending on you need to do.
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England
Unrated

Re: Why i cant display the bar chart?

Postby joyce16 on Mon Sep 27, 2010 10:22 am

ca8msm wrote:Are you referring to the errors I listed above?

If so, then the first one is because you are trying to access the Request object from a class file in the App_Code folder and it should only really be accessed from the code behind of a Page (there are exceptions but not for this case).

If you read the second error message, it tells you what the error is and gives you two recommended approaches to dealing with it depending on you need to do.


Yes. I am referring to the errors that you listed above.
joyce16
Apprentice
Apprentice
 
Posts: 8
Joined: Fri Sep 24, 2010 7:05 am
Unrated

Re: Why i cant display the bar chart?

Postby joyce16 on Tue Sep 28, 2010 7:03 am

I have already solve all those error. However, when i click on view barchart, the image that came out is the image from view linechart. I think the linechart code overwrite it. I'm not sure how to check. Could you help me check what is wrong is the code,Could u also explain why i can't display the barchart. Thanks very very much!:)
You do not have the required permissions to view the files attached to this post.
joyce16
Apprentice
Apprentice
 
Posts: 8
Joined: Fri Sep 24, 2010 7:05 am
Unrated