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

📄 defaultcs.aspx.cs

📁 Telerik是很大的第三方软件制造商
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
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.SettingValues
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class DefaultCS: XhtmlPage
	{
		static int maxSales = 5000;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button btnSet;
		protected System.Web.UI.WebControls.TextBox txtBoxSales;
		protected System.Web.UI.WebControls.Label labelSales;
		protected System.Web.UI.WebControls.DropDownList dropDownQuarter;
		protected System.Web.UI.WebControls.Label labelQuarter;
		protected Telerik.WebControls.RadChart RadChart1;
		static double profitRatio = 0.1;

		private void InitComponents ()
		{
			dropDownQuarter.SelectedIndex = 0;
			dropDownQuarter_SelectedIndexChanged(null, System.EventArgs.Empty);
		}

		private void GenRandomSales()
		{
			ChartSeries salesDataSeries = RadChart1.GetChartSeries("SALES");

			if (salesDataSeries != null)
			{
				Random r = new Random();

				if (salesDataSeries.Items.Count > 0)
				{
					foreach (ChartSeriesItem seriesItem in salesDataSeries.Items)
					{
						seriesItem.YValue = r.NextDouble() * maxSales;
					}
				}
				else
				{		
					for (int i = 0; i < 4; i++)
					{
						salesDataSeries.AddItem(r.NextDouble() * maxSales);
					}
				}
			}
		}

		private void CalcProfit()
		{
			ChartSeries salesDataSeries = RadChart1.GetChartSeries("SALES");
			ChartSeries profitDataSeries = RadChart1.GetChartSeries("Profit");

			if ( (salesDataSeries != null)  && (profitDataSeries != null) )
			{
				profitDataSeries.Clear();

				foreach (ChartSeriesItem salesItem in salesDataSeries.Items)
				{
					profitDataSeries.AddItem(salesItem.YValue * profitRatio);
				}
			}
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{				
				InitRadChart();
				
				GenRandomSales();

				CalcProfit();

				InitComponents();                
			}
		}

		private void InitRadChart()
		{
			RadChart1.Clear();
			RadChart1.XAxis.DefaultItemFont = new Font("Arial", 10);
			RadChart1.XAxis.DefaultItemColor = Color.Black;
			RadChart1.XAxis.AutoScale = false;
			RadChart1.XAxis.AddItem("Q1");
			RadChart1.XAxis.AddItem("Q2");
			RadChart1.XAxis.AddItem("Q3");
			RadChart1.XAxis.AddItem("Q4");
			RadChart1.XAxis.LayoutStyle = ChartAxisLayoutStyle.Between;
				
			ChartSeries salesSeries = RadChart1.CreateSeries("SALES", Color.Red, ChartSeriesType.Bar);			
			salesSeries.Appearance.BorderColor = Color.Black;
			salesSeries.Appearance.FillStyle = FillStyle.Solid;
			salesSeries.ShowLabels = false;

			ChartSeries profitSeries = RadChart1.CreateSeries("Profit", Color.Green, ChartSeriesType.Line);            
			profitSeries.Appearance.FillStyle = FillStyle.Solid;			
			profitSeries.LabelAppearance.TextFont   = new Font("Verdana", 6);
			profitSeries.LabelAppearance.TextColor  = Color.Black;									
			profitSeries.LabelAppearance.Background.BorderColor = Color.Black;
			profitSeries.LabelAppearance.Background.MainColor = Color.FromArgb(200, 255, 255, 255);
			profitSeries.LabelAppearance.Background.FillStyle = FillStyle.Solid;
			profitSeries.DefaultLabel = "#Y{N2}";
			profitSeries.PointSize = 4;
		}

		#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.dropDownQuarter.SelectedIndexChanged += new System.EventHandler(this.dropDownQuarter_SelectedIndexChanged);
			this.btnSet.Click += new System.EventHandler(this.btnSet_Click);
			this.Button1.Click += new System.EventHandler(this.Button1_Click_1);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void dropDownQuarter_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			labelSales.Text = "Sales for " + dropDownQuarter.SelectedItem.Text;

			ChartSeries salesSeries = RadChart1.GetChartSeries("SALES");

			if (salesSeries != null)
			{
				txtBoxSales.Text  = salesSeries[dropDownQuarter.SelectedIndex].YValue.ToString("##.##");
			}
		}

		private void btnSet_Click(object sender, System.EventArgs e)
		{
			ChartSeries salesSeries = RadChart1.GetChartSeries("SALES");
			ChartSeries profitSeries = RadChart1.GetChartSeries("Profit");

			if ( (salesSeries != null) && (profitSeries != null) )
			{
				try
				{
					double newValue =  double.Parse(txtBoxSales.Text);

					salesSeries[dropDownQuarter.SelectedIndex].YValue = newValue;
					profitSeries[dropDownQuarter.SelectedIndex].YValue  = newValue * 0.1;
				}
				catch
				{
				}
			}
		}

		private void Button1_Click_1(object sender, System.EventArgs e)
		{
			GenRandomSales();

			CalcProfit();

			InitComponents();
		}			
	}
}

⌨️ 快捷键说明

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