?
Solved

Transfer vb array data to histogram chart in web page

Posted on 2006-03-19
8
Medium Priority
?
329 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:Bball
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 16231463
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
 
LVL 7

Expert Comment

by:rangasuman
ID: 16233480
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
 

Author Comment

by:Bball
ID: 16237352
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Bball
ID: 16237786
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
 
LVL 12

Accepted Solution

by:
TheMegaLoser earned 2000 total points
ID: 16244538
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
 

Author Comment

by:Bball
ID: 16250485
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
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 16251069
A quick serch turned up this:

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

I'm not sure if it's useful.
0
 

Author Comment

by:Bball
ID: 16285376
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

850 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