Line Graph

Results 1 to 2 of 2

Thread: Line Graph

  1. #1
    Join Date
    Dec 1969

    Default Line Graph

    hi,<BR><BR>does anyone have any code written for drawing line chart? if yes, can u kindly gimme the link or code?<BR><BR>thx<BR>Phil

  2. #2
    Join Date
    Dec 1969

    Default RE: Line Graph

    using System;<BR>using System.Collections;<BR>using System.Drawing;<BR>using System.Drawing.Imaging;<BR>using System.Drawing.Drawing2D;<BR><BR>namespace CS_TEST<BR>{<BR> <BR> public class randomLineGraphExample : System.Web.UI.Page<BR> {<BR> private Bitmap m_objBmp;<BR> private Graphics m_objGrx;<BR> private Point[] m_pntCoords = new Point[10];<BR> private int m_xLower = 0;<BR> private int m_xUpper = 20;<BR> <BR> private void Page_Load(object sender, System.EventArgs e)<BR> {<BR> init();<BR> fillCoords();<BR> plotCoords();<BR> renderOutput();<BR> }<BR><BR> private void init()<BR> {<BR> m_objBmp = new Bitmap(200, 200);<BR> m_objGrx = Graphics.FromImage(m_objBmp);<BR> m_objGrx.SmoothingMode = SmoothingMode.AntiAlias; <BR> }<BR><BR> private void fillCoords()<BR> {<BR> Random r = new System.Random();<BR> Random rX = new System.Random();<BR> int X = 0;<BR> int i;<BR><BR> for(i=0; i&#060;m_pntCoords.Length; i++)<BR> {<BR> X = rX.Next(m_xLower, m_xUpper);<BR> m_pntCoords[i] = new Point(X, r.Next(0,200));<BR> m_xLower += 20;<BR> m_xUpper += 20;<BR> }<BR><BR> }<BR><BR> private void plotCoords()<BR> {<BR> m_objGrx.DrawLines(new Pen(Brushes.Red, 1.0f), m_pntCoords);<BR> }<BR><BR> private void renderOutput()<BR> {<BR> int intJpgCodec;<BR><BR> //Get codecs<BR> ImageCodecInfo[] icf = ImageCodecInfo.GetImageEncoders();<BR><BR> for(intJpgCodec = 0; intJpgCodec &#060; icf.GetUpperBound(0); intJpgCodec ++)<BR> {<BR> if(icf[intJpgCodec].FormatDescription == "JPEG")<BR> break;<BR> }<BR><BR> //Set quality<BR> EncoderParameters encps = new EncoderParameters( 2 );<BR> EncoderParameter encp = new EncoderParameter( System.Drawing.Imaging.Encoder.Quality, <BR> (long) 100);<BR> encps.Param[0] = encp;<BR> Encoder myEncoder = Encoder.ColorDepth;<BR> encp = new EncoderParameter(myEncoder, 24L);<BR> encps.Param[1] = encp;<BR> m_objBmp.Save( Response.OutputStream, icf[intJpgCodec], encps ); <BR> }<BR> }<BR>}<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts