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

📄 defaultcs.aspx.cs

📁 Telerik是很大的第三方软件制造商
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Telerik.QuickStart;
using Telerik.WebControls;

namespace Telerik.ChartExamplesCS.YAxis
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class DefaultCS: XhtmlPage
	{
					
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.Label Label8;
		protected System.Web.UI.WebControls.Label Label9;
		protected System.Web.UI.WebControls.Label Label10;
		protected System.Web.UI.WebControls.CheckBox cbAutoScale;
		protected System.Web.UI.WebControls.TextBox txtBoxMinDataValue;
		protected System.Web.UI.WebControls.TextBox txtBoxMaxDataValue;
		protected System.Web.UI.WebControls.TextBox txtBoxMinAxisValue;
		protected System.Web.UI.WebControls.TextBox txtBoxMaxAxisValue;
		protected System.Web.UI.WebControls.TextBox txtBoxStep;
		protected System.Web.UI.WebControls.TextBox txtBox;
		protected System.Web.UI.WebControls.DropDownList ddlLabelAlign;
		protected System.Web.UI.WebControls.TextBox txtBoxMarkLength;
		protected System.Web.UI.WebControls.TextBox txtBoxSpaceToItemLabels;
		protected System.Web.UI.WebControls.TextBox txtBoxSpaceToAxisLabel;
		protected System.Web.UI.WebControls.CheckBox cbNegative;
		protected System.Web.UI.WebControls.CheckBox cbZeroBased;
		protected System.Web.UI.WebControls.Label Label11;
		protected System.Web.UI.WebControls.TextBox txtBoxRotationAngle;
		protected System.Web.UI.WebControls.DropDownList ddlValueFormat;
		protected System.Web.UI.WebControls.TextBox txtBoxCustomFormat;
		protected System.Web.UI.WebControls.TextBox txtBoxAxisLabel;
		protected System.Web.UI.WebControls.Label lblIncorrectSettings;
		protected Telerik.WebControls.RadChart RadChart1;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				InitControls();
				SetControlValues();
			}
		}

		private void InitControls()
		{
			InitControl(ddlLabelAlign, typeof(ChartVAlignment));
			InitControl(ddlValueFormat, typeof(ChartValueFormat));
		}

		private void SetControlValues()
		{
			txtBoxMinDataValue.Text = GetMinValue().ToString();
			txtBoxMaxDataValue.Text = GetMaxValue().ToString();
			cbAutoScale.Checked     = RadChart1.YAxis.AutoScale;
			txtBoxMinAxisValue.Text = RadChart1.YAxis.MinValue.ToString();
			txtBoxMaxAxisValue.Text = RadChart1.YAxis.MaxValue.ToString();
			txtBoxStep.Text         = RadChart1.YAxis.Step.ToString();
			txtBoxAxisLabel.Text    = RadChart1.YAxis.Label.Text;
			SetControlValue(ddlLabelAlign, RadChart1.YAxis.Label.VAlignment.ToString());
			txtBoxMarkLength.Text   = RadChart1.YAxis.MarkLength.ToString();
			txtBoxSpaceToItemLabels.Text = RadChart1.YAxis.SpaceToItem.ToString();
			txtBoxSpaceToAxisLabel.Text = RadChart1.YAxis.SpaceToLabel.ToString();
			// cbNegative.Checked = RadChart1.YAxis.IsAxisNegative;
			cbZeroBased.Checked = RadChart1.YAxis.IsZeroBased;
		}

		private void InitControl(DropDownList ddList, Type type)
		{
			string[] valueNames = Enum.GetNames(type);

			ddList.Items.Clear();

			foreach (string s in valueNames)
			{
				ddList.Items.Add(s);
			}
		}

		private void SetControlValue(DropDownList ddList, string val)
		{
			ddList.Items.FindByValue(val).Selected = true;
		}

		private double GetMinValue()
		{
			double minValue = double.MaxValue;

			foreach (ChartSeries chartSeries in RadChart1.ChartSeriesCollection)
			{
				foreach (ChartSeriesItem item in chartSeries.Items)
				{
					if (item.YValue < minValue)
					{
						minValue = item.YValue;
					}
				}
			}

			return minValue;
		}

		private double GetMaxValue()
		{
			double maxValue = double.MinValue;

			foreach (ChartSeries chartSeries in RadChart1.ChartSeriesCollection)
			{
				foreach (ChartSeriesItem item in chartSeries.Items)
				{
					if (item.YValue > maxValue)
					{
						maxValue = item.YValue;
					}
				}
			}
			return maxValue;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			try
			{
				ApplySettings();
				lblIncorrectSettings.Visible = false;
			}
			catch
			{
				lblIncorrectSettings.Visible = true;
			}
		}

		private void ApplySettings()
		{
			SetNewValues();
			RadChart1.YAxis.AutoScale   = cbAutoScale.Checked;            
			RadChart1.YAxis.MinValue    = double.Parse(txtBoxMinAxisValue.Text);
			RadChart1.YAxis.MaxValue    = double.Parse(txtBoxMaxAxisValue.Text);
			RadChart1.YAxis.Step        = double.Parse(txtBoxStep.Text);
			RadChart1.YAxis.Label.Text  = txtBoxAxisLabel.Text;
			RadChart1.YAxis.Label.VAlignment = (ChartVAlignment) Enum.Parse(typeof(ChartVAlignment), ddlLabelAlign.SelectedItem.Value);			
			RadChart1.YAxis.MarkLength      = int.Parse(txtBoxMarkLength.Text);
			RadChart1.YAxis.SpaceToItem     = int.Parse(txtBoxSpaceToItemLabels.Text);
			RadChart1.YAxis.SpaceToLabel    = int.Parse(txtBoxSpaceToAxisLabel.Text);                        
			RadChart1.YAxis.IsZeroBased     = cbZeroBased.Checked;
			RadChart1.YAxis.LabelRotationAngle = double.Parse(txtBoxRotationAngle.Text);
			RadChart1.YAxis.ValueFormat	= (ChartValueFormat) Enum.Parse(typeof(ChartValueFormat), ddlValueFormat.SelectedItem.Value);
			RadChart1.YAxis.CustomFormat = txtBoxCustomFormat.Text;
		}

		private void SetNewValues()
		{
			Random r = new Random();

			double minValue = double.Parse(txtBoxMinDataValue.Text);
			double maxValue = double.Parse(txtBoxMaxDataValue.Text);

			foreach (ChartSeries series in RadChart1.ChartSeriesCollection)
			{
				foreach (ChartSeriesItem item in series.Items)
				{
					item.YValue = r.Next((int) minValue, (int) maxValue);
				}
			}
		}
			
	}
}

⌨️ 快捷键说明

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