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

📄 piegraph2d.cs

📁 C#自定义查询控件
💻 CS
字号:
// Disclaimer and Copyright Information
// PieGraph2D.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.Diagnostics;
using System.Drawing;
using System.Collections;

namespace CommonComponent.CommonChart
{
	/// <summary>
	/// 
	/// </summary>
	public class PieGraph2D : CommonChart.PieGraph
	{
		public PieGraph2D()
		{
			// 
			// TODO: Add constructor logic here
			//
			this.m_GraphType = Type.PieGraph2D;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawData()
		{
			//TODO: For now we will process only first array of data list. Later
			//		on implementation needs to take into account that there may
			//		be more than one list.
			
			float fRadius = 0.0F;
			PointF ptCenter;
			Pen piePen = null;
			Pen obTickerPen = null;
			SolidBrush tickerBrush = null;
			RectangleF boundingRect;
			try
			{
				// Calculate bounding sqaure size and other measurements.
				this.CalculateDrawingMeasurements();

				ArrayList dataList = (ArrayList)this.m_obIslandList[0];
				double sum =0.0;
				foreach ( GraphDataObject obData in dataList)
				{
				  sum =sum+ obData.Y;				  
				}
				
				if(sum!=100)
				{
					foreach ( GraphDataObject obData in dataList)
					{
						 obData.Y=(float)(obData.Y*100/sum);				  
					}
				}

				if (null == dataList || dataList.Count == 0)
				{
					throw new Exception("There is no data list present in the array.");
				}

				int nCount = dataList.Count;

				// Generate the random colors.
				if (this.UseRandomColors)
				{
					ColorUtil.GenerateRandomColors(nCount, out m_arrColors);
				}
				else
				{
					ColorUtil.GenerateColorValues(Colors, out this.m_arrColors);
				}

				// Create Black pen for drawing pie outlines.
				piePen = new Pen(new SolidBrush(Color.Gray));
				piePen.Width = 0.1F;

				// Create brush for drawing tickers.
				if (this.HasTickers)
				{
					tickerBrush = new SolidBrush(this.m_TickColor);
					obTickerPen = new Pen(tickerBrush);
				}
				
				boundingRect = new RectangleF();
				boundingRect.Width = BoundingSquareSize;
				boundingRect.Height = BoundingSquareSize;
				//boundingRect.Y = this.m_ChartAxis.Origin.Y - (this.BoundingSquareSize + LeftOverHeight/2.0F);
				boundingRect.Y = this.m_ChartRectangle.Y + (LeftOverHeight/2.0F);

				ptCenter = new PointF();
				ptCenter.Y = boundingRect.Y + boundingRect.Height/2.0F;

				// Calculate radius.
				fRadius = boundingRect.Width/2.0F;

				//float fStartX = this.m_ChartAxis.Origin.X + LeftSpacing + LeftOverWidth/2.0F;
				float fStartX = this.m_ChartRectangle.X + LeftOverWidth/2.0F;
				for (int nIdx = 0; nIdx < this.m_obDataIslandNodes.Count; nIdx++)
				{
					ArrayList obIslandDataList = (ArrayList)this.m_obIslandList[nIdx];

					boundingRect.X = fStartX;
					if (nIdx > 0)
					{
						boundingRect.X += nIdx * (IslandSpacing + BoundingSquareSize);
					}
					ptCenter.X = boundingRect.X + boundingRect.Width/2.0F;

					float currentDegree = 0.0F;
					for (int idx = 0; idx < nCount; idx++)
					{
						GraphDataObject obData = (GraphDataObject)obIslandDataList[idx];
						if (null != obData)
						{
							float val = (float)((obData.Y / ((float)100.0)) * 360.0);
							if (val > 0.0)
							{
								this.m_obGraphics.FillPie(new SolidBrush((Color)(this.m_arrColors[idx])),
									boundingRect.X, boundingRect.Y, boundingRect.Width, boundingRect.Height,
									currentDegree, val);
								this.m_obGraphics.DrawPie(piePen, boundingRect, currentDegree, val);

								if (this.HasTickers)
								{
									this.DrawChartTicker(this.m_obGraphics,
										tickerBrush,
										obTickerPen,
										new Point((int)ptCenter.X, (int)ptCenter.Y),
										fRadius,
										m_fRadialTickerBuffer,
										(currentDegree + val/2.0F),
										obData.Y.ToString(),
										this.m_LegendsList[idx]);
								}

								// increment the currentDegree
								currentDegree += (float)(obData.Y / 100 * 360);
							}
						}
					}

					// Draw Island legend.
					if (this.DrawIslandLegend)
					{
						PointF txtPt = new PointF(boundingRect.X, boundingRect.Y);
						this.DrawIslandLegendText(m_IslandLegendsList[nIdx], m_obGraphics, IslandLegendFont, txtPt, BoundingSquareSize, this.m_TickColor);
					}
				}
			}
			finally
			{
				if (null != piePen)
				{
					piePen.Dispose();
				}

				if (null != tickerBrush)
				{
					tickerBrush.Dispose();
				}
			}
			
			return true;
		}
	}
}

⌨️ 快捷键说明

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