⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.cs

📁 C#自定义查询控件
💻 CS
📖 第 1 页 / 共 5 页
字号:
// Disclaimer and Copyright Information
// Graph.cs : 
//
// All rights reserved.
//
// Written by Pardesi Services, LLC
// Version 1.01
//
// Distribute freely, except: don't remove our name from the source or
// documentation (don't take credit for my work), mark your changes (don't
// get me blamed for your possible bugs), don't alter or remove this
// notice.
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc. to
// softomatix@CommonComponent.com
///////////////////////////////////////////////////////////////////////////////
//

using System;
using System.Xml;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
using System.Data;


namespace CommonComponent.CommonChart
{
	public interface  IGraph
	{
	   bool DrawGraph(ImageFormat imgFormat,ref Stream obOutputStream);
       bool DrawGraph(ref Stream obOutputStream);
	}
	// The Grpah type enumeration
	public enum Type 
	{
		BarGraph2D = 0,
		BarGraph3D = 1,
		LineGraph2D = 2,
		LineGraph3D = 4,
		PieGraph2D = 5,
		PieGraph3D = 6,
		PointGraph = 7,
		AreaGraph = 8,
		SplineGraph = 9,
		SplineAreaGraph = 10,
		StackBarGraph2D = 11,
		StackBarGraph3D = 12,
		BlocksGraph2D = 13,
		BlocksGraph3D = 14,
	}

	public enum Alignment
	{
		Vertical = 0,
		Horizontal = 1,
	}

	/*
	 *							Y1
	 *							|
	 *				Quad2		|	Quad1
	 *							|
	 *							|O
	 *			X1-------------------------------X2
	 *							|
	 *				Quad3		|	Quad4
	 *							|
	 *							|
	 *							Y2
	 * 
	 *	The above figure shows the fourd qudarants that chart can be shown in.
	 * 
	*/
	public enum QuadrantType
	{
		Quad1 = 1,				// Data for first qudarant only
		Quad2 = 2,				// Data for second quadrant only
		Quad3 = 3,				// Data for third quadrant only
		Quad4 = 4,				// Data for fourth quadrant only
		Quad12 = 12,			// Data for first & second quadarant
		Quad14 = 14,			// Data for first & fourth quadrant
		Quad23 = 23,			// Data for second and thord quadrant
		Quad34 = 34,			// Data for quadrant third and four
		Quad1234 = 1234,		// Data for all four quadrants
	}

	/// <summary>
	/// This enum specifies if the legend will be draw inside or outside
	/// the chart.
	/// </summary>
	public enum LegendLocationType
	{
		OutsideChart = 0,
		InsideChart = 1,
	}

	/// <summary>
	/// This enum specifies the outside position of legend.
	/// </summary>
	public enum PositionType
	{
		Left = 0,
		Right = 1,
		Top = 2,
		Bottom = 3,
		Middle = 4,
		LeftTop = 5,
		RightTop = 6,
		LeftBottom = 7,
		RightBottom = 8,
	}

	/// <summary>
	/// This enum specifies how the legends will be draw. There are two
	/// ways you can do it. Top to bottom or left to right.
	/// </summary>
	public enum LegendAlignmentType
	{
		Horizontal = 0,
		Vertical = 1,
	}

	/// <summary>
	/// 
	/// </summary>
	public enum TextDirectionType
	{
		Horizontal = 0,
		Vertical = 1,
		Diagonal = 2,
	}

	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public abstract class Graph:IGraph
	{
		protected Bitmap m_obBitmap;
		protected Graphics m_obGraphics;

		protected Type m_GraphType;
		protected BackgroundType m_BackgroundType;
		protected SmoothingType m_Smoothing;
		protected LGradientType m_LGradientType;		// Linear gradient type for background
		protected CGradientType m_CGradientType;		// Circular gradient type for background
		protected HatchType		m_HatchType;			// Hatch style for background

		protected LegendLocationType m_LegendLocation;	// Inside or Outside
		protected LegendAlignmentType m_LegendAlignment;// Verical or horizontal
		protected PositionType m_LegendPosition;
		private PositionType m_LogoPosition;			// Position to draw logo.

		protected TextDirectionType m_TickerTextDirection;
		protected TextDirectionType m_IslandLegendTextDirection;

		protected bool m_bUseRandomColors;
		protected bool m_bUseGradientColors;
		protected bool m_bHasLegends;
		protected bool m_bHasBorder;
		protected bool m_bHasTickers;
		protected bool m_bDrawLogo;
		internal bool m_bMutliIslandData;
		
		protected bool m_bDrawIslandLegend;
		internal short m_sLegendCount;
		protected short m_sBgGradientFactor;
		protected short m_sGraphGradientFactor;
		protected int m_iWidth;
		protected int m_iHeight;

		private int m_iDataPointCount;
		
		internal float m_fMaxLegendTextWidth;
		internal float m_fMaxLegendTextHeight;
		internal float m_fAvgLegendTextWidth;
		internal float m_fTotalLegendTextWidth;
		internal float m_fMaxIslandLegendTextWidth;
		internal float m_fMaxIslandLegendTextHeight;
		internal float m_fAvgIslandLegendTextWidth;
		internal float m_fTotalIslandLegendTextWidth;
		protected short m_sVertcalLegendSpacing;
		protected short m_sHorizontalLegendSpacing;
		protected short m_sLegendTextSpacing;
		protected short m_sLegendWidth;
		protected short m_sLegendHeight;
		protected short m_sTickerSize;

		private short m_sSubGridLines;

		internal float m_fLeftSpacing;
		internal float m_fRightSpacing;
		internal float m_fTopSpacing;
		internal float m_fBottomSpacing;
		internal float m_fIslandSpacing;
		internal float m_fLeftOverHeight;
		internal float m_fLeftOverWidth;

		protected double m_dTitlePaddingFromTop;		// title padding from top
		protected int m_iXAxisLabelPadding;				// x-axis label padding from axis line
		protected int m_iYAxisLabelPadding;				// y-axis label padding from axis line.
		
		protected int m_iTickStep;
		protected string m_strTitle;
		protected string m_strBgImagePath;				// Full path for back ground image.
		protected Font m_TitleFont;						// font used for displaying title
		protected Font m_XAxisLabelFont;				// font used for displaying x-axis label
		protected Font m_YAxisLabelFont;				// font used for displaying y-axis label
		protected Font m_XTickFont;
		protected Font m_YTickFont;
		protected Font m_LegendFont;
		protected Font m_IslandLegendFont;
		protected Font m_TickerDataFont;
		protected Font m_TickerDescFont;
		protected Color m_BgColor;
		protected Color m_TitleColor;
		
		protected Color m_GridColor;
		protected Color m_SubGridColor;
		protected Color m_LegendColor;
		protected Color m_TickColor;
		protected Color m_HatchColor;
		protected Color [] m_GradientColors;

		protected XmlDocument m_obGraphData;			// XML document storing data for display

		protected QuadrantType m_QuadrantToShow;
		protected ChartAxis m_ChartAxis;
		protected RectangleF m_LegendRectangle;
		protected Point m_Origin;
		protected PointF m_XAxisLabelLocation;
		protected PointF m_YAxisLabelLocation;
		protected string m_strFile;
		private string m_strLogoImageFile;
		protected long m_lNumRecords;
		protected int m_iXAxisSpan;
		protected int m_iYAxisSpan;

		internal int m_iNumberOfDataIslands;
		internal float m_fMinXDataValue;
		internal float m_fMinYDataValue;
		internal float m_fMaxXDataValue;
		internal float m_fMaxYDataValue;

		protected XmlNodeList m_obDataNodes;
		protected XmlNodeList m_obDataIslandNodes;
		protected ArrayList m_obIslandList;
		protected ArrayList m_arrColors;
		protected StringCollection m_LegendsList;
		protected StringCollection m_IslandLegendsList;
		protected ArrayList m_arrLegendTextWidth;
		protected ArrayList m_arrIslandLegendTextWidth;
		protected StringCollection m_ColorNames;

		/* Calculated dimensions for use during rendering */
		internal RectangleF m_ChartRectangle;
		internal RectangleF m_TopLeftRectangle;
		internal RectangleF m_TopRightRectangle;
		internal RectangleF m_BottomLeftRectangle;
		internal RectangleF m_BottomRightRectangle;
		internal RectangleF m_TopMiddleRectangle;
		internal RectangleF m_BottomMiddleRectangle;
		internal RectangleF m_RightMiddleRectangle;
		internal RectangleF m_LeftMiddleRectangle;
		internal PointF m_ChartCenter;

		internal float m_fTitleHeight;
		internal float m_fTitleWidth;

		internal bool m_bMultiRowHorizontalLegends;
		internal short m_sLegendRowCount;
		internal int m_iMaxLegendsInRow;
		internal short m_sLegendsBuffer;
		internal float m_fLegendRectWidth;
		internal float m_fLegendRectHeight;

		public Graph()
		{
			m_ChartAxis = new ChartAxis();

			m_Smoothing = SmoothingType.HighQuality;
			m_BackgroundType = BackgroundType.SolidColor;
			m_LGradientType = LGradientType.TopToBottom;

			m_TickerTextDirection = TextDirectionType.Horizontal;
			m_IslandLegendTextDirection = TextDirectionType.Horizontal;

			m_LogoPosition = PositionType.Left;

			m_bUseRandomColors = true;
			m_bUseGradientColors = false;
			m_bHasBorder = false;
			m_bHasLegends = false;
			m_bHasTickers = true;
			m_bMutliIslandData = false;
			m_bDrawIslandLegend = true;
			m_bDrawLogo = false;

			m_sBgGradientFactor = 100;
			m_sGraphGradientFactor = 100;

			this.m_sLegendCount = 0;
			this.m_fMaxLegendTextWidth = 0.0F;
			this.m_fMaxLegendTextHeight = 0.0F;
			this.m_fAvgLegendTextWidth = 0.0F;
			this.m_fTotalLegendTextWidth = 0.0F;
			this.m_sTickerSize = 3;
			this.m_sSubGridLines = 1;

			m_fLeftSpacing = 30.0F;
			m_fRightSpacing = 30.0F;
			m_fTopSpacing = 30.0F;
			m_fBottomSpacing = 30.0F;
			m_fIslandSpacing = 10.0F;
			m_fLeftOverHeight = 0.0F;
			m_fLeftOverWidth = 0.0F;

			// TODO: Add support for customization of legend attributes
			this.m_sVertcalLegendSpacing = 5;
			this.m_sHorizontalLegendSpacing = 5;
			this.m_sLegendTextSpacing = 5;
			this.m_sLegendWidth = 7;
			this.m_sLegendHeight = 7;

			this.m_iDataPointCount = 0;

			this.m_dTitlePaddingFromTop = 5.0;

			this.m_BgColor = Color.White;
			this.m_TitleColor = Color.Black;
			this.m_GridColor = Color.Black;
			this.m_LegendColor = Color.Black;
			this.m_TickColor = Color.Black;
			this.m_HatchColor = Color.Black;
			this.m_SubGridColor = Color.Gray;

			m_GradientColors = null;

			this.m_TitleFont = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Pixel);
			this.m_XAxisLabelFont = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel);
			this.m_YAxisLabelFont = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel);
			this.m_XTickFont = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel);
			this.m_YTickFont = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel);
			this.m_LegendFont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel);
			this.m_IslandLegendFont = new Font("Arial", 14, FontStyle.Bold, GraphicsUnit.Pixel);
			this.m_TickerDataFont= new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel);
			this.m_TickerDescFont = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel);

			this.m_strTitle = "Chart Title";
			
			this.m_strBgImagePath = "";

			this.m_iNumberOfDataIslands = 0;
			this.m_lNumRecords = 0;

			this.m_fMinXDataValue = 0.0F;
			this.m_fMinXDataValue = 0.0F;
			this.m_fMaxXDataValue = 0.0F;
			this.m_fMaxYDataValue = 0.0F;

			m_fTitleHeight = 0.0F;
			m_fTitleWidth = 0.0F;

			m_sLegendsBuffer = 2;
			m_sLegendRowCount = 1;
			m_iMaxLegendsInRow = 0;

			m_fLegendRectHeight = 0.0F;
			m_fLegendRectWidth = 0.0F;

			m_strFile = "graph.jpg";
			m_strLogoImageFile = "";
		}

		/// <summary>
		/// 
		/// </summary>
		public void CleanUp()
		{
			if (null != this.m_obGraphics)
			{
				this.m_obGraphics.Dispose();
			}

			if (null != this.m_obBitmap)
			{
				this.m_obBitmap.Dispose();
			}

			this.m_obGraphics = null;
			this.m_obBitmap = null;
		}

		/// <summary>
		/// 
		/// </summary>
		protected bool MultiIslandData
		{
			get{return this.m_bMutliIslandData;}
			set{this.m_bMutliIslandData = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		protected int DataPointCount
		{
			get{return this.m_iDataPointCount;}
			set{this.m_iDataPointCount = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		protected Type GraphType
		{
			get{return this.m_GraphType;}
			set{this.m_GraphType = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		public SmoothingType Smoothing
		{
			get{return this.m_Smoothing;}
			set{this.m_Smoothing = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		public bool UseRandomColors
		{
			get{return this.m_bUseRandomColors;}
			set{this.m_bUseRandomColors = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		public StringCollection Colors
		{
			get{return this.m_ColorNames;}
			set{this.m_ColorNames = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		public float LeftSpacing
		{
			get{return this.m_fLeftSpacing;}
			set{this.m_fLeftSpacing = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		public float RightSpacing
		{
			get{return this.m_fRightSpacing;}
			set{this.m_fRightSpacing = value;}
		}

		/// <summary>
		/// 
		/// </summary>
		///
		public float TopSpacing
		{
			get{return this.m_fTopSpacing;}
			set{this.m_fTopSpacing = value;}
		}
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -