Click here to Skip to main content
15,884,237 members
Articles / Multimedia / GDI+

A flexible charting library for .NET

Rate me:
Please Sign up or sign in to vote.
4.70/5 (1,112 votes)
6 Jun 200730 min read 8.9M   180.2K   2.1K  
Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use.
using System;
using System.Drawing;

namespace GDIDB
{
	/// <summary>
	/// Class to implement Double Buffering 
	/// NT Almond 
	/// 24 July 2003
	/// </summary>
	/// 
	public class DBGraphics
	{
		private	Graphics	graphics;
		private Bitmap		memoryBitmap;
		private	int			width;
		private	int			height;

		/// <summary>
		/// Default constructor
		/// </summary>
		public DBGraphics()
		{
			width	= 0;
			height	= 0;
		}

		/// <summary>
		/// Creates double buffer object
		/// </summary>
		/// <param name="g">Window forms Graphics Object</param>
		/// <param name="width">width of paint area</param>
		/// <param name="height">height of paint area</param>
		/// <returns>true/false if double buffer is created</returns>
		public bool CreateDoubleBuffer(Graphics g, int width, int height)
		{

			if (memoryBitmap != null)
			{
				memoryBitmap.Dispose();
				memoryBitmap = null;
			}

			if (graphics != null)
			{
				graphics.Dispose();
				graphics = null;
			}

			if (width <= 0 || height <= 0)
				return false;


			if ((width != this.width) || (height != this.height))
			{
				this.width = width;
				this.height = height;

				memoryBitmap	= new Bitmap(width, height);
				graphics		= Graphics.FromImage(memoryBitmap);
			}

			return true;
		}


		/// <summary>
		/// Renders the double buffer to the screen
		/// </summary>
		/// <param name="g">Window forms Graphics Object</param>
		public void Render(Graphics g)
		{
			if (memoryBitmap != null)
				g.DrawImage(memoryBitmap, new Rectangle(0,0, width, height),0,0, width, height, GraphicsUnit.Pixel);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns>true if double buffering can be achieved</returns>
		public bool CanDoubleBuffer()
		{
			return graphics != null;
		}

		/// <summary>
		/// Accessor for memory graphics object
		/// </summary>
		public Graphics g 
		{
			get 
			{ 
				return graphics; 
			}
		}		
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions