Bball
asked on
Transfer vb array data to histogram chart in web page
I have a working web application where the user works through various steps in a simulation providing input along the way. Random events occur to combine with the user's input to produce corresponding calculations and a final profit value. In the end, I have programmed a loop that cycles through the calculations 100 times with a fresh draw of the random events each time to produce 100 final profit values.
Here's the quesion: This application is written in .Net using vb coding behind the page and in various subroutines. The final profit values are stored in a vb array of length 100 titled ProfitSet1. I need to be able to take this data set and produce a histogram in a web page. What is the best way to go about doing that such that when the program is run the histogram can be graphed from this resulting array?
Bball
Here's the quesion: This application is written in .Net using vb coding behind the page and in various subroutines. The final profit values are stored in a vb array of length 100 titled ProfitSet1. I need to be able to take this data set and produce a histogram in a web page. What is the best way to go about doing that such that when the program is run the histogram can be graphed from this resulting array?
Bball
I would suggest you to use Microsoft Office Web Components for this purpose. You can download it from:
http://www.microsoft.com/downloads/details.aspx?familyid=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en
Some good tutorials and source code is available at:
http://www.west-wind.com/presentations/OWCCharting/OWCCharting.asp
http://www.4guysfromrolla.com/webtech/022101-1.shtml
Hope that helps.
http://www.microsoft.com/downloads/details.aspx?familyid=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en
Some good tutorials and source code is available at:
http://www.west-wind.com/presentations/OWCCharting/OWCCharting.asp
http://www.4guysfromrolla.com/webtech/022101-1.shtml
Hope that helps.
ASKER
TheMegaLoser,
I'm trying out your code and I am getting two errors:
From the line:
Dim gr As Graphics = System.Drawing.Graphics.Fr omImage(bm p)
I get the error that 'bmp' is not declared. I'm assuming 'bmp' needs to be created on the page as a blank image and declared on the code behind page as System.Web.UI.WebControls. Image. Is that correct?
From the line:
gr.DrawLine(i, 0, i, ProfitSet1(i))
I get the error 'Overload resolution failed because no accessible 'DrawLine' accepts this number of arguments.' Since this is all new to me, I'm not sure what to do about this one.
Thanks
Bball
I'm trying out your code and I am getting two errors:
From the line:
Dim gr As Graphics = System.Drawing.Graphics.Fr
I get the error that 'bmp' is not declared. I'm assuming 'bmp' needs to be created on the page as a blank image and declared on the code behind page as System.Web.UI.WebControls.
From the line:
gr.DrawLine(i, 0, i, ProfitSet1(i))
I get the error 'Overload resolution failed because no accessible 'DrawLine' accepts this number of arguments.' Since this is all new to me, I'm not sure what to do about this one.
Thanks
Bball
ASKER
TheMegaLoser,
O.K., I figured out that gr.DrawLine needs an argument for the pen so I changed that to the following:
gr.DrawLine(pen.blue,i, 0, i, ProfitSet1(i))
and error goes away.
I'm having more difficulty resolving the first error though. If I declare 'bmp' as either
Protected bmp As System.Drawing.Image
or as
Dim bmp As System.Drawing.Image
depending upon where I put it, I get an error when I debug. The error refers to the line
Dim gr As Graphics = System.Drawing.Graphics.Fr omImage(bm p)
and states
Exception Details: System.ArgumentNullExcepti on: Value cannot be null. Parameter name: image
I think I'm getting a feel for how this is suppose to work but want to make sure I'm headed in the right direction before I proceed.
Thanks for your help!
Bball
O.K., I figured out that gr.DrawLine needs an argument for the pen so I changed that to the following:
gr.DrawLine(pen.blue,i, 0, i, ProfitSet1(i))
and error goes away.
I'm having more difficulty resolving the first error though. If I declare 'bmp' as either
Protected bmp As System.Drawing.Image
or as
Dim bmp As System.Drawing.Image
depending upon where I put it, I get an error when I debug. The error refers to the line
Dim gr As Graphics = System.Drawing.Graphics.Fr
and states
Exception Details: System.ArgumentNullExcepti
I think I'm getting a feel for how this is suppose to work but want to make sure I'm headed in the right direction before I proceed.
Thanks for your help!
Bball
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
TheMegaLoser, thanks for the code. That seems to clear up the compilation issues. I need to pretty up the format of the graph and I think I'm good to go.
One question, the ProfitSet1 array is actually the raw data. I need to sort it into bins for the histogram. Do you know of any canned vb code for this? I can write my own but I thought if you knew of any out there, it would save some time. My searches haven't turned up anything yet in vb, only in javascript so far.
Thanks
One question, the ProfitSet1 array is actually the raw data. I need to sort it into bins for the histogram. Do you know of any canned vb code for this? I can write my own but I thought if you knew of any out there, it would save some time. My searches haven't turned up anything yet in vb, only in javascript so far.
Thanks
A quick serch turned up this:
http://www25.brinkster.com/mferris/html/downloads.html
I'm not sure if it's useful.
http://www25.brinkster.com/mferris/html/downloads.html
I'm not sure if it's useful.
ASKER
I ended up writing my own code for sorting the data into bins. Not that difficult and now I have a working graph. Still much to do on making it look nicer but the solution approach to create a page that returns a picture and then calling that page from where I want it displayed was fantastic. Thank you to TheMegaLoser for providing it!
Bball
Bball
<IMG SRC="histogram.aspx">
In the histogram.aspx code-behind you create the actual picture.
' Clear the response
Response.Clear()
' Create a new bitmap
Dim oNewImg As New System.Drawing.Bitmap(100,
Dim gr As Graphics = System.Drawing.Graphics.Fr
' Loop the array and draw lines
for i = 0 to 100
gr.Drawline(i, 0, i, array(i))
next i
oNewImg.Save(Response.Outp
Note, code isn't compiled but should work. Hope ths helps!