How to draw a line with asp.net? RRS feed

  • Question

  • User-1946046797 posted

    I need to draw a line to display changes of numbers?

    Firstly ,I need to access Oracle database, and extract data. Then in accordance with these data, draw a line.


    Friday, January 20, 2006 10:00 PM

All replies

  • User-1513591455 posted

    Since you are in teh GDI area, I assume you want some control over colour ,angle, etc.

    Create a bitmap of some convenient size.  Use GDI to draw the lines, text, circles, or whatever.  Render the bitmap to the web page (can be as gif, jpeg, etc.).  You will find plenty of articles around the web on this

    Saturday, January 21, 2006 12:52 PM
  • User-1372641848 posted

    If you want to draw line then following code will do that for you.

    // Create Bitmap

    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100, 100);

    // Get Graphics object

    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

    // Create white background


    // Draw Line

    g.DrawLine(System.Drawing.Pens.Black, 10, 10, 100, 10);


    Also read about other overloads for Graphics.DrawLine Method on msdn

    Saturday, January 21, 2006 12:59 PM
  • User-1946046797 posted
    Jigar,Thank you!
    But I tried many times.  I am using VB.NET, I need to compose a ASP.NET for IE browser.
    What you write is with C#,But I am with VB.
    Do the function Drawing   and arguments PaintEventArgs need  some certain Namespase ? where  do I  add then? 
    Monday, January 23, 2006 1:07 AM
  • User-1372641848 posted

    This is VB Code which creates image, draws line on image streams back to browser. copy and paste that code in your aspx page and run.

    I do not work in VB but it took me 1 minute to find a place which can convert my C# code to VB on google.

    <%@ Page Language="vb" %>

    <%@ Import Namespace="System.Drawing" %>

    <script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)

    ' Create Bitmap

    Dim bmp As New System.Drawing.Bitmap(100, 100)

    ' Get Graphics object

    Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)

    ' Create white background


    ' Draw Line

    g.DrawLine(System.Drawing.Pens.Black, 10, 10, 100, 10)


    Response.ContentType = "image/gif"

    bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)


    End Sub 'Page_Load



    Monday, January 23, 2006 12:22 PM
  • User-1946046797 posted

    Jigar, Thank you  very very much.

    Your code has worked properly. I hope I can develop my program as soon as possible.


    Monday, January 23, 2006 7:54 PM