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

📄 linegraph2d.cs

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

namespace CommonComponent.CommonChart
{
	/// <summary>
	/// 
	/// </summary>
	public class LineGraph2D : CommonChart.LineGraph
	{
		protected Color m_LineColor;
		public LineGraph2D()
		{
			m_LineColor = Color.Blue;
			this.m_GraphType = Type.LineGraph2D;
			this.m_QuadrantToShow = QuadrantType.Quad1;
		}

		/// <summary>
		/// 
		/// </summary>
		public Color LineColor
		{
			get{return this.m_LineColor;}
			set{this.m_LineColor = value;}
		}

		/// <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.

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

			int nCount = dataList.Count;

			if (this.UseRandomColors)
			{
				ColorUtil.GenerateRandomColors(this.m_obDataIslandNodes.Count, out m_arrColors);
				}
			else
			{
				ColorUtil.GenerateColorValues(this.Colors, out m_arrColors);
			}

			PointF pt1 = new PointF();
			PointF pt2 = new PointF();

			RectangleF markerRect = new RectangleF();
			markerRect.Height = (float)(this.m_iYAxisSpan * 0.02);
			markerRect.Width = (float)(this.m_iYAxisSpan * 0.02);

			//m_obGraphics.SmoothingMode = SmoothingMode.AntiAlias;
			//SolidBrush obMarker = new SolidBrush(Color.Red);
			for (int nIdx = 0; nIdx < this.m_obDataIslandNodes.Count; nIdx++)
			{
				Color lineColor = (Color)this.m_arrColors[nIdx];
				Color markerColor = Color.White;//(Color)this.m_arrMarkerColors[nIdx];
				Pen obPen = new Pen(new SolidBrush(lineColor));
				SolidBrush obMarker = new SolidBrush(markerColor);

				ArrayList obIslandDataList = (ArrayList)this.m_obIslandList[nIdx];
				for (int i = 0; i < nCount - 1; i++)
				{
					GraphDataObject obData1 = (GraphDataObject)obIslandDataList[i];
					GraphDataObject obData2 = (GraphDataObject)obIslandDataList[i+1];
					if (null != obData1 && null != obData2)
					{
						pt1.X = this.m_ChartAxis.Origin.X + (float)(obData1.X * this.m_fXScale);
						pt1.Y = this.m_ChartAxis.Origin.Y - (float)(obData1.Y * this.m_fYScale);

						pt2.X = this.m_ChartAxis.Origin.X + (float)(obData2.X * this.m_fXScale);
						pt2.Y = this.m_ChartAxis.Origin.Y - (float)(obData2.Y * this.m_fYScale);

						this.m_obGraphics.DrawLine(obPen, pt1, pt2);

						markerRect.X = pt1.X - 2;
						markerRect.Y = pt1.Y - 2;

						this.m_obGraphics.FillEllipse(obMarker, markerRect);

						markerRect.X = pt2.X - 2;
						markerRect.Y = pt2.Y - 2 - 2;

						this.m_obGraphics.FillEllipse(obMarker, markerRect);

						// Draw the data value text.
						try
						{
							this.DrawDataValue(this.m_obGraphics, this.m_YTickFont, pt1.X, pt1.Y, obData1.Y.ToString(), this.m_TickColor);
							this.DrawDataValue(this.m_obGraphics, this.m_YTickFont, pt2.X, pt2.Y, obData2.Y.ToString(), this.m_TickColor);
						}
						catch (Exception ex)
						{
							Trace.WriteLine(ex.Message);
						}
					}
				}

				obPen.Dispose();
				obMarker.Dispose();
			}

			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawLegends()
		{
			// Legends count is the number of data islands that needs to be drawn.
			this.m_sLegendCount = (short)this.m_iNumberOfDataIslands;

			this.CalculateLegendsRectangle(this.m_sLegendCount);
			switch (this.LegendAlignment)
			{
				case LegendAlignmentType.Horizontal:
					return this.DrawHorizontalLegends();
				case LegendAlignmentType.Vertical:
					return this.DrawVerticalLegends();
			}
			return false;
		}
	}
}

⌨️ 快捷键说明

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