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
BballAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheMegaLoserCommented:
You create an aspx page that returns a picture. Then you reference this script from where you want the histogram placed.

<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,100)
Dim gr As Graphics = System.Drawing.Graphics.FromImage(bmp)

' Loop the array and draw lines
for i = 0 to 100
   gr.Drawline(i, 0, i, array(i))
next i

oNewImg.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)

Note, code isn't compiled but should work. Hope ths helps!
0
rangasumanCommented:
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.
0
BballAuthor Commented:
TheMegaLoser,

I'm trying out your code and I am getting two errors:

From the line:
Dim gr As Graphics = System.Drawing.Graphics.FromImage(bmp)
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

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

BballAuthor Commented:
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.FromImage(bmp)

and states

Exception Details: System.ArgumentNullException: 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
0
TheMegaLoserCommented:
Sorry for that, a minor typo from my part. bmp should of course be oNewImg. Hence the code should be like this (with some further cleaning, and yes, this one compiles).

--- Code start ---
Const iPictureHeight As Integer = 100
Const iPictureWidth As Integer = 100
Dim iColumn As Integer

Response.Clear()

' Create a new bitmap
Dim oNewImg As New System.Drawing.Bitmap(iPictureWidth, iPictureHeight)
Dim gr As Graphics = System.Drawing.Graphics.FromImage(oNewImg)

' Loop the array and draw lines
For iColumn = 0 To iPictureWidth
   ' Subtract from picture height to draw from the bottom up
   gr.DrawLine(System.Drawing.Pens.Blue, iColumn, iPictureHeight, iColumn, iPictureHeight -  ProfitSet1(iColumn))
Next iColumn

' Write the image to the client in jpeg format
oNewImg.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
--- Code stop ---
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BballAuthor Commented:
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


0
TheMegaLoserCommented:
A quick serch turned up this:

http://www25.brinkster.com/mferris/html/downloads.html

I'm not sure if it's useful.
0
BballAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.