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

📄 bargraph3d.cs

📁 C#自定义查询控件
💻 CS
📖 第 1 页 / 共 2 页
字号:
// Disclaimer and Copyright Information
// BarGraph3D.cs : 
//
// All rights reserved.
//
// Written by Pardesi Services, LLC
// Version 0.9
//
// 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.Xml;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Collections;

namespace CommonComponent.CommonChart
{
	/// <summary>
	/// 
	/// </summary>
	public class BarGraph3D : CommonChart.BarGraph2D
	{
		protected float m_fDepthFactor;
		public BarGraph3D()
		{
			this.m_GraphType = Type.BarGraph3D;
			this.m_QuadrantToShow = QuadrantType.Quad1;
			m_fDepthFactor = 0.02F;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawGridLines()
		{
			// Check if the client has asked for Grid Lines or not.
			if (false == HasGridLines)
			{
				return true;
			}
			return true;
		}

		override protected bool DrawTickers()
		{
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="iLeftX"></param>
		/// <param name="iLeftY"></param>
		/// <param name="iWidth"></param>
		/// <param name="iHeight"></param>
		/// <param name="dThickness"></param>
		/// <param name="faceColor"></param>
		/// <returns></returns>
		override protected bool DrawBar(Graphics obGraphics, int iLeftX, int iLeftY, float iWidth, float iHeight, double dThickness, Color faceColor)
		{
			Brush faceBrush = null;
			Brush leftBrush = null;
			Brush topBrush = null;
			Brush baseBrush = null;
			Brush backBrush = null;
			Brush rightBrush = null;

			PointF [] faceRect = null;
			PointF [] leftRect = null;
			PointF [] topRect = null;
			PointF [] baseRect = null;
			PointF [] backRect = null;
			PointF [] rightRect = null;

			try
			{
				leftBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -2));
				topBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, 30));
				baseBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -5));
				backBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -10));
				rightBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -20));

				faceRect = new PointF[4];
				leftRect = new PointF[4];
				topRect = new PointF[4];
				baseRect = new PointF[4];
				backRect = new PointF[4];
				rightRect = new PointF[4];

				faceRect[0].X = iLeftX;
				faceRect[0].Y = iLeftY;
				faceRect[1].X = faceRect[0].X + iWidth;
				faceRect[1].Y = faceRect[0].Y;
				faceRect[2].X = faceRect[1].X;
				faceRect[2].Y = faceRect[1].Y + iHeight;
				faceRect[3].X = faceRect[2].X - iWidth;
				faceRect[3].Y = faceRect[2].Y;

				rightRect[0].X = faceRect[1].X;
				rightRect[0].Y = faceRect[1].Y;
				rightRect[1].X = (float)(rightRect[0].X + dThickness);
				rightRect[1].Y = (float)(rightRect[0].Y - dThickness);
				rightRect[2].X = rightRect[1].X;
				rightRect[2].Y = rightRect[1].Y + iHeight;
				rightRect[3].X = rightRect[0].X;
				rightRect[3].Y = rightRect[0].Y + iHeight;

				leftRect[0].X = faceRect[0].X;
				leftRect[0].Y = faceRect[0].Y;
				leftRect[1].X = (float)(leftRect[0].X + dThickness);
				leftRect[1].Y = (float)(leftRect[0].Y - dThickness);
				leftRect[2].X = leftRect[1].X;
				leftRect[2].Y = leftRect[1].Y + iHeight;
				leftRect[3].X = leftRect[0].X;
				leftRect[3].Y = leftRect[0].Y + iHeight;

				backRect[0].X = leftRect[1].X;
				backRect[0].Y = leftRect[1].Y;
				backRect[1].X = rightRect[1].X;
				backRect[1].Y = rightRect[1].Y;
				backRect[2].X = rightRect[2].X;
				backRect[2].Y = rightRect[2].Y;
				backRect[3].X = leftRect[2].X;
				backRect[3].Y = leftRect[2].Y;

				baseRect[0].X = faceRect[0].X;
				baseRect[0].Y = faceRect[0].Y;
				baseRect[1].X = faceRect[1].X;
				baseRect[1].Y = faceRect[1].Y;
				baseRect[2].X = rightRect[1].X;
				baseRect[2].Y = rightRect[1].Y;
				baseRect[3].X = leftRect[1].X;
				baseRect[3].Y = leftRect[1].Y;

				topRect[0].X = faceRect[3].X;
				topRect[0].Y = faceRect[3].Y;
				topRect[1].X = faceRect[2].X;
				topRect[1].Y = faceRect[2].Y;
				topRect[2].X = backRect[2].X;
				topRect[2].Y = backRect[2].Y;
				topRect[3].X = backRect[3].X;
				topRect[3].Y = backRect[3].Y;

				if (this.UseGradientColors)
				{
					Rectangle rect = new Rectangle();
					rect.X = (int)faceRect[0].X;
					rect.Y = (int)faceRect[0].Y;
					rect.Width = (int)Math.Abs(faceRect[0].X - faceRect[1].X);
					rect.Height = (int)iHeight;

					faceBrush = DrawingUtil.GetLinearGradientBrush(rect, faceColor, GraphGradientFactor, LinearGradientMode.Horizontal);
				}
				else
				{
					faceBrush = new SolidBrush(faceColor);
				}

				obGraphics.FillPolygon(baseBrush, baseRect);
				obGraphics.FillPolygon(leftBrush, leftRect);
				obGraphics.FillPolygon(backBrush, backRect);
				obGraphics.FillPolygon(faceBrush, faceRect);
				obGraphics.FillPolygon(rightBrush, rightRect);
				obGraphics.FillPolygon(topBrush, topRect);
			}
			catch (Exception ex)
			{
				Trace.WriteLine(ex.Message);
				throw ex;
			}
			finally
			{
				if (null !=  faceBrush)
				{
					faceBrush.Dispose();
				}

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

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

				if (null !=  leftBrush)
				{
					faceBrush.Dispose();
				}

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

				if (null !=  rightBrush)
				{
					rightBrush.Dispose();
				}
				faceBrush = null;
				leftBrush = null;
				topBrush = null;
				baseBrush = null;
				backBrush = null;
				rightBrush = null;
			}

			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawAxisLines(bool bDrawGrid)
		{
			bool bRet = false;
			if (Alignment.Vertical == this.GraphAlignment)
			{
				bRet =  this.DrawAxisForVerticalAlignment(bDrawGrid);
			}
			else
			{
				bRet = this.DrawAxisForHorizontalAlignment(bDrawGrid);
			}
			return bRet;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawData()
		{
			bool bRet = false;

			// Calculate bar and island width data.
			this.CalculateBarWidth(0);

			// Caluclate the direction for drawing tickers.
			this.CalculateTickerTextDirection();

			// Calculate the direction for drawing island legends.
			this.CalculateIslandLegendTextDirection();

			ArrayList dataList = (ArrayList)this.m_obIslandList[0];
			if (null == dataList || dataList.Count == 0)
			{
				throw new ArgumentException("There is no data list present in the array.");
			}

			int nCount = dataList.Count;
			if (false == this.CalculateBarHeightScale())
			{
				throw new Exception("Failed to calculate the scale factor");
			}

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

			//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.
			if (Alignment.Vertical == this.GraphAlignment)
			{
				bRet = this.DrawDataForVerticalAlignment();
			}
			else
			{
				bRet = this.DrawDataForHorizontalAlignment();
			}

			return bRet;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawDataForVerticalAlignment()
		{
			PointF pt = new PointF();
			pt.X = (float)(this.m_ChartAxis.Origin.X);
			pt.Y = this.m_ChartAxis.Origin.Y;

			double dThickness = this.m_iXAxisSpan * m_fDepthFactor;
			if (this.m_bMutliIslandData)
			{
				dThickness *= 0.5;
			}

			double nHeight = 0;
			double nWidth = 0;
			double dX = 0.0;
			double dY = 0.0;
			//int nStartX = (int)(this.m_ChartAxis.Origin.X + LeftSpacing);
			double diff = m_dEqualBarWidth - m_dDrawBarWidth;
			float fStartY = this.m_ChartAxis.Origin.Y - m_fIslandSpacing/2.0F;
			int nStartX = (int)(this.m_ChartAxis.Origin.X);;

			for (int nIdx = 0; nIdx < this.m_obDataIslandNodes.Count; nIdx++)
			{
				ArrayList obIslandDataList = (ArrayList)this.m_obIslandList[nIdx];
				int nCount = obIslandDataList.Count;
				for (int i = 0; i < nCount; i++)
				{
					Color fillColor = (Color)this.m_arrColors[i];
					GraphDataObject obData = (GraphDataObject)obIslandDataList[i];
					if (null != obData)
					{
						//pt.Y = (float)(this.m_ChartAxis.Origin.Y - ((i+1) * this.m_dEqualBarWidth) + diff);
						//pt.Y = (float)(nStartX + nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing) + i * this.m_dEqualBarWidth);
						pt.Y = (float)(fStartY - nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing) - (i + 1) * this.m_dEqualBarWidth);

						// First draw the front rectangle.
						nHeight = this.m_dDrawBarWidth;
						nWidth = (obData.Y * this.m_dBarHeightScale);

						this.DrawBar(this.m_obGraphics, (int)pt.X, (int)pt.Y, (float)nWidth, (float)nHeight, dThickness, fillColor);

						// Draw the data value text.
						try
						{
							dX = pt.X + dThickness;
							dY = pt.Y - dThickness;
							this.DrawDataValue(this.m_obGraphics, this.m_YTickFont, dX, dY, nWidth, nHeight,
								obData.Y.ToString(), this.m_TickerTextDirection, this.GraphAlignment, this.m_TickColor, fillColor);
						}
						catch (Exception ex)
						{
							Trace.WriteLine(ex.Message);
						}

⌨️ 快捷键说明

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