codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  HOW CREATE LINE CHARTS IN ASP.NET  JUBACHESQUE at 22:45 on Sunday, November 21, 2004
 

I NEED CREATE GRAPH OF LINE IN ASP.NET.
ANYPEOPLE CAN HELP ME!!
THANKS!!!
JULIANO

  Re: HOW CREATE LINE CHARTS IN ASP.NET  tgreer at 16:05 on Monday, November 22, 2004
 

First thing to realize, no matter what controls or classes the .NET Framework has, when you're in the ASP.NET enviroment, the end result is HTML.

So in order to produce graphics, you have to produce valid HTML.

In HTML, graphics are produced by 1) browser rendering or 2) inline image data.

By "browser rendering", I mean the browser interprets a tag, such as <hr>, and produces graphic ouput (a horizontal rule). With CSS, users can create graphically rich web pages.

However, CSS isn't nearly so intensive as GDI+, and I don't think you can produce sophisticated charts via CSS. You have to produce a graphic image, such as a GIF, JPEG, or PNG.

You can do this, using the System.Drawing and System.Drawing.Imaging classes. You can create an instance of the Bitmap class, which encapsulates GDI+ and so contains the SetPixel method for creating an image one pixel at a time. You can also use the Graphics class, which has methods for drawing lines and polygons.

Once you have created your image in memory, you can write out to your Web Server's file system and reference it with an Image Control, or you can stream it directly to the browser.

Please support CodeToad by clicking one of the ads. If you found my post helpful, please visit my site and thank me by clicking one of MY ads.



<Added>

Here is a small C# program for drawing a line. The WebForm contains a single Image Server control, with no properties set.

This is the code behind:


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace charts
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image1;

private void Page_Load(object sender, System.EventArgs e)
{
DisplayLine();
Image1.ImageUrl = Server.MapPath("")+"temp.jpg";

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DisplayLine()
{
Bitmap b =new Bitmap(250,250);
b.Save(Server.MapPath("")+"temp.jpg",ImageFormat.Jpeg);
Graphics g = Graphics.FromImage(b);
g.Clear(Color.White);
Pen p = new Pen(Color.Blue);
g.DrawLine(p,10,240,240,240);
b.Save(Server.MapPath("")+"temp.jpg",ImageFormat.Jpeg);
}
}
}




  Re: HOW CREATE LINE CHARTS IN ASP.NET  tgreer at 17:22 on Wednesday, November 24, 2004
 

Please reply to this thread to let me know if the solution worked. We want these threads to benefit others in the future who have the same questions.

If it was helpful, please click through some of the ads on the site.


  Re: HOW CREATE LINE CHARTS IN ASP.NET  JUBACHESQUE at 19:21 on Wednesday, November 24, 2004
 

Hello!
I can solutioned my problem whith your sugestion!
my problem, was when i saved my picture graph.
If you want,i can send mu program for you see!
Thanks people.
I'm sore if my english be bad, because, i have difficult to write in english!



  Re: HOW CREATE LINE CHARTS IN ASP.NET  tgreer at 19:52 on Wednesday, November 24, 2004
 

You don't have to apologize for poor English.

You don't actually have to save the image at all. You can create it entirely in memory, and then stream it back to the client.

Here is a description of that technique.

1) Create an ASP.NET project, with two webforms.

2) The first webform will contain an Image control. Set the SRC property of that image control to the Second webform.

2) The Second webform will create the image, using what we've already discussed. Only, instead of using the .Save method to write the image to a file, you instead write the image to the response stream.

To write the image to the response stream, use the following code:

Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);


In that code "b" is the bitmap you created.

The advantage to this technique is that you never have to save a file to the filesystem, and so don't have to keep track of or maintain temporary files.

Furthermore, if you create your image creation code as a Class Library, rather than a webform, you can have a generic image-generation class that you can reuse in Windows and Web applications.

Again, I would appreciate it if you would do two things for me in return: click an add or two here on CodeToad, and then go to my site http://www.tgreer.com and click an ad or two there.


  Re: HOW CREATE LINE CHARTS IN ASP.NET  TechWizard at 08:08 on Sunday, January 09, 2005
 

Don't we need to included namespace using System.Drawing.Imaging; in the heading?

I am also beginning to work with GDI objects here and wanted to know where and what this temp.jpg is and what it does? Can you provide a sample project that I can use in Visual studio? I was not able to get the above sample working completely

thanks

  Re: HOW CREATE LINE CHARTS IN ASP.NET  TechWizard at 14:00 on Monday, January 10, 2005
 

Thanks for your advice. I understand that this consumes time and effort. I sat one whole morning and digged into MSDN and finally managed to make charts of various sizes and types. Your sample coded did get me going and I thank you for posting it. During this time I also found a pretty cool site that has charts which cannot be compared to anything else. Try checking http://www.dotnetcharting.com Its amazing what ASP.NET can do!

Cheers








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  matrix addition
•  Re: Storing data from HTML to Excel or TXT
•  Re: function within loop problem
•  Re: Ô‡´ò¥¯¥é¥Ö¤à ¥Æ©`¥é©`¥á¥¤¥É£ò£±£±¥¢¥¤¥¢¥ó ¤Î£··¬ ¤Ç¤¹
•  Re: Replace
•  Re: タイトリスト AP2アイアン 712ã�®æƒ…å �
•  Re: SMS from Perl using HTTP request
•  Re: Charl Schwartzel
•  Re: Adhyayan - Annual Student Conference and Online Coding Festival


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2013