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

📄 chartbox.cs

📁 是用c#实现的一个有关于报表设计的程序代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
#region License
/*
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/
#endregion

using System;
using System.Drawing;
using System.Data;
using System.ComponentModel;
using System.Collections;


namespace daReport
{
	/// <summary>
	/// Class representing the ChartBox object.
	/// </summary>
	/// <remarks>The ChartBox is used in reports where graphical representation of data is used.</remarks>
	public class ChartBox : ICustomPaint 
	{
		#region Declarations
		/// <summary>
		/// Enumeration of possible chart types
		/// </summary>
		public enum ChartType
		{
			/// <summary>Bar Graph</summary>
			Bar = 1,
			/// <summary>Pie Chart</summary>
			Pie
		};

		private Rectangle mRegion = new Rectangle(0,0,0,0);
		private Rectangle mMapArea = new Rectangle(0,0,0,0);
		private Rectangle mLegendArea = new Rectangle(0,0,0,0);
		
		private string mName = "chart0";
		private string mTitle = "Chart mTitle";
		private string mXLabel = "Categories";
		//private string yLabel = "Values";
		private ChartType mChartType = ChartType.Bar;
		private string[] mXCategories = new string[0];
		private ArrayList mYSeries = new ArrayList();
		private string[] mSeriesNames = new string[0];
		private bool mShowLegend = false;

		private Color mBorderColor = Color.Black;
		private Color mMapAreaColor = Color.WhiteSmoke;
		private int mBorderWidth = 1;
		private Font mTitleFont = new Font("Tahoma",8,FontStyle.Bold);
		private Font mLabelFont = new Font("Tahoma",8,FontStyle.Regular);
		private Color[] mSeriesColors = new Color[0];
		private Color[] mPieColors = new Color[0];

		private float mMaxY = 100f;
		private float mMinY = 0f;

		private bool mSelectable = true;
		#endregion

		#region Public Properties

		/// <summary>
		/// Gets/Sets the border color for the ChartBox
		/// </summary>
		/// <remarks>This property sets the border color of the ChartBox object. This can be any color
		/// from the System.Drawing.Color structure
		/// </remarks>
		public Color BorderColor
		{
			get {return mBorderColor;}
			set {mBorderColor = value;}
		}


		/// <summary>
		/// Gets/Sets the border width for the ChartBox
		/// </summary>
		/// <remarks>
		/// BorderWidth of the ChartBox. If this is set to zero, then the border is invisible
		/// </remarks>
		public int BorderWidth
		{
			get {return mBorderWidth;}
			set {mBorderWidth = value;}
		}


		/// <summary>
		/// Gets/Sets the font used for any labels displayed on the ChartReport
		/// </summary>
		public Font LabelFont
		{
			get {return mLabelFont;}
			set {mLabelFont = value;}
		}


		/// <summary>
		/// The background color displayed behind the chart image
		/// </summary>
		/// <remarks>This property sets the background color displayed behind the chart image. This can be any color
		/// from the System.Drawing.Color structure
		/// </remarks>
		[Description("The color for map area within the chart.")]
		public Color MapAreaColor
		{
			get {return mMapAreaColor;}
			set {mMapAreaColor = value;}
		}


		/// <summary>
		/// Gets/Sets the name of the chart.
		/// </summary>
		/// <remarks>This property is used in code when setting other properties programmaticly.</remarks>
		[Description("The name of the chart. This property is used in code when setting other properties programmaticly.")]
		public string Name
		{
			get {return mName;}
			set {mName = value;}
		}


		/// <summary>
		/// Gets/Sets whether to display the ChartBox's legend
		/// </summary>
		[Description("Show legend in chart.")]
		public bool ShowLegend
		{
			get {return mShowLegend;}
			set {mShowLegend = value;}
		}


		/// <summary>
		/// Gets/Sets the title: value used at the top of the chart
		/// </summary>
		[Description("The Title of the chart.")]
		public string Title
		{
			get {return mTitle;}
			set {mTitle = value;}
		}


		/// <summary>
		/// Gets/Sets the font used for the title of the ChartReport
		/// </summary>
		public Font TitleFont
		{
			get {return mTitleFont;}
			set {mTitleFont = value;}
		}


		/// <summary>
		/// Gets/Sets the type of the ChartBox
		/// </summary>
		[Description("The type of data presentation.")]
		public ChartType Type
		{
			get {return mChartType;}
			set {mChartType = value;}
		}


		/// <summary>
		/// XCategories is a string array of the categories defined in the chart data.
		/// </summary>
		[Browsable(false)]
		public string[] XCategories
		{
			get {return mXCategories;}
			set {mXCategories = value;}
		}


		/// <summary>
		/// Gets/Sets the value used for labelling the X-axis of the ChartReport
		/// </summary>
		[Description("The X-axis label.")]
		public string XLabel
		{
			get {return mXLabel;}
			set {mXLabel = value;}
		}


		#endregion

		#region Public Overrides

		/// <summary>
		/// This function adds the current objects information to the XmlTextWriter
		/// </summary>
		/// <param name="CurrentWriter">Current XmlTextWriter to append object information to</param>
		public override void AddXMLToWriter(ref System.Xml.XmlTextWriter CurrentWriter)
		{
			CurrentWriter.WriteStartElement("chartBox");
			CurrentWriter.WriteAttributeString("name", Helpers.TextSafeForXML(this.mName));
			CurrentWriter.WriteAttributeString("x", this.X.ToString());
			CurrentWriter.WriteAttributeString("y", this.Y.ToString());
			CurrentWriter.WriteAttributeString("width", this.Width.ToString());
			CurrentWriter.WriteAttributeString("height", this.Height.ToString());
			CurrentWriter.WriteAttributeString("type", this.mChartType.ToString());
			CurrentWriter.WriteAttributeString("horAlignment", this.horizontalAlignment.ToString());
			CurrentWriter.WriteAttributeString("verAlignment", this.verticalAlignment.ToString());
			CurrentWriter.WriteAttributeString("selectable", this.mSelectable.ToString());
			CurrentWriter.WriteAttributeString("ObjectRepeatability", this.ObjectRepeatability.ToString());
			CurrentWriter.WriteStartElement("title");
			CurrentWriter.WriteString(Helpers.TextSafeForXML(this.mTitle));
			CurrentWriter.WriteEndElement(); //end of title element
			CurrentWriter.WriteStartElement("titleFont");
			CurrentWriter.WriteAttributeString("family", this.mTitleFont.FontFamily.Name);
			CurrentWriter.WriteAttributeString("size", this.mTitleFont.Size.ToString());
			CurrentWriter.WriteAttributeString("style", this.mTitleFont.Style.ToString());
			CurrentWriter.WriteEndElement(); //end of titleFont element
			CurrentWriter.WriteStartElement("xLabel");
			CurrentWriter.WriteString(Helpers.TextSafeForXML(this.mXLabel));
			CurrentWriter.WriteEndElement(); //end of xLabel element
			CurrentWriter.WriteStartElement("labelFont");
			CurrentWriter.WriteAttributeString("family", this.mLabelFont.FontFamily.Name);
			CurrentWriter.WriteAttributeString("size", this.mLabelFont.Size.ToString());
			CurrentWriter.WriteAttributeString("style", this.mLabelFont.Style.ToString());
			CurrentWriter.WriteEndElement(); //end of labelFont element
			CurrentWriter.WriteStartElement("mapAreaColor");
			CurrentWriter.WriteString(this.mMapAreaColor.Name);
			CurrentWriter.WriteEndElement(); //end of mapAreaColor element
			CurrentWriter.WriteStartElement("showLegend");
			CurrentWriter.WriteString(this.mShowLegend.ToString());
			CurrentWriter.WriteEndElement(); //end of showLegend element
			CurrentWriter.WriteStartElement("border");
			CurrentWriter.WriteAttributeString("width", this.mBorderWidth.ToString());
			CurrentWriter.WriteAttributeString("color", this.mBorderColor.Name);
			CurrentWriter.WriteEndElement(); //end of border element
			CurrentWriter.WriteEndElement(); //end of chartBox element
		}


		/// <summary>
		///  Gets or sets the horizontal alignment of the ChartBox
		/// </summary>
		[Description("Horizontal alignment in the page, relative to margins. This property overrides element coordinates.")]
		public override ICustomPaint.HorizontalAlignmentTypes HorizontalAlignment
		{
			get {return horizontalAlignment;}
			set 
			{
				horizontalAlignment = value;
				switch (horizontalAlignment)
				{
					case ICustomPaint.HorizontalAlignmentTypes.Center:
						mRegion.X = (document.DefaultPageSettings.Bounds.Width-document.Margins.Right+document.Margins.Left)/2 - Width/2;
						break;

					case ICustomPaint.HorizontalAlignmentTypes.Right:
						mRegion.X = document.DefaultPageSettings.Bounds.Right - document.Margins.Right - Width;
						break;

					case ICustomPaint.HorizontalAlignmentTypes.Left:
						mRegion.X = document.Margins.Left;
						break;
				}
			}
		}


		/// <summary>
		/// Clones the structure of the ChartBox, including all properties
		/// </summary>
		/// <returns><see cref="daReport.ChartBox">daReport.ChartBox</see></returns>
		public override object Clone()
		{
			ChartBox tmp = new ChartBox(0,0,0,0,document);
			tmp.X = this.X;
			tmp.Y = this.Y;
			tmp.Width = this.Width;
			tmp.Height = this.Height;
			tmp.BorderWidth = this.BorderWidth;
			tmp.BorderColor = this.BorderColor;
			tmp.Type = this.Type;
			tmp.mTitleFont = this.mTitleFont;
			tmp.mTitle = this.mTitle;
			tmp.ShowLegend = this.ShowLegend;
			tmp.MapAreaColor = this.MapAreaColor;
			tmp.mLabelFont = this.mLabelFont;
			tmp.XLabel = this.XLabel;
			tmp.Name = "chart"+tmp.GetHashCode().ToString();

			return tmp;
		}


		/// <summary>
		///  Gets or sets the XMLNode for the current object
		/// </summary>
		/// <remarks>
		/// This property is used to read and write the objects information from the XML
		/// template documents.
		/// </remarks>
		[Browsable(false)]
		public override void LoadFromXMLNode(System.Xml.XmlNode CurrentNode)
		{
			this.X= Convert.ToInt32( CurrentNode.Attributes["x"].Value );
			this.Y= Convert.ToInt32( CurrentNode.Attributes["y"].Value );
			this.Width= Convert.ToInt32( CurrentNode.Attributes["width"].Value );
			this.Height = Convert.ToInt32( CurrentNode.Attributes["height"].Value );

			this.mName = CurrentNode.Attributes["name"]==null ? "chart0" : Helpers.SafeXMLToText(CurrentNode.Attributes["name"].Value) ;
			
			if (CurrentNode.Attributes["horAlignment"] != null)
				this.horizontalAlignment = ICustomPaint.ResolveHorizontalAlignment(CurrentNode.Attributes["horAlignment"].Value);

			if (CurrentNode.Attributes["verAlignment"] != null)
				this.verticalAlignment = ICustomPaint.ResolveVerticalAlignment(CurrentNode.Attributes["verAlignment"].Value);

			if (CurrentNode.Attributes["Selectable"] != null)
				this.mSelectable = Convert.ToBoolean(CurrentNode.Attributes["Selectable"].Value);

			if (CurrentNode.Attributes["ObjectRepeatability"] != null)
				this.objectRepeatability = ICustomPaint.ResolveObjectRepeatability(CurrentNode.Attributes["ObjectRepeatability"].Value);

			string theType = CurrentNode.Attributes["type"]==null ? "Bars" : CurrentNode.Attributes["type"].Value;
			switch (theType)
			{

				case "Pie":
					this.mChartType= ChartBox.ChartType.Pie;
					break;

				default :
					this.mChartType= ChartBox.ChartType.Bar;
					break;
			}

			System.Xml.XmlNodeList childNodes = CurrentNode.ChildNodes;

			for (int i=0;i<childNodes.Count;i++)

⌨️ 快捷键说明

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