View Code
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CreateChartImage(); } } public DataTable GetTempData() { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DEMO;Integrated Security=True"); string strSql = "SELECT * FROM ChartDB"; SqlDataAdapter da = new SqlDataAdapter(strSql, con); DataSet ds = new DataSet(); da.Fill(ds); if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) { return new DataTable(); } return ds.Tables[0]; } public void CreateChartImage() { DataTable dt = GetTempData(); this.Chart1.Width = 600; this.Chart1.Height = 400; this.Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line; this.Chart1.Series[0].MarkerStyle = MarkerStyle.Circle; this.Chart1.Series[0].MarkerSize = 6; this.Chart1.Series[0].ToolTip = "销售:\t#VALX\n收入:\t#VALY"; this.Chart1.Series[0].IsValueShownAsLabel = true; this.Chart1.ChartAreas[0].AxisX.Title = "销售"; this.Chart1.ChartAreas[0].AxisY.Title = "收入"; this.Chart1.Titles.Add("销售报表"); for (int i = 0; i < this.Chart1.Legends.Count; i++) { this.Chart1.Legends[i].Docking = Docking.Bottom; this.Chart1.Legends[i].Alignment = StringAlignment.Center; this.Chart1.Legends[i].LegendStyle = LegendStyle.Row; } for (int i = 0; i < dt.Rows.Count; i++) { this.Chart1.Series[0].Points.AddXY(dt.Rows[i]["Worker"].ToString(), dt.Rows[i]["ProductPrice"].ToString()); if (decimal.Parse(dt.Rows[i]["ProductPrice"].ToString()) > 30000) { this.Chart1.Series[0].Points[i].MarkerColor = Color.Red; this.Chart1.Series[0].LegendText = "销售收入"; } } }
怀揣着一点点梦想的年轻人
相信技术和创新的力量
喜欢快速反应的工作节奏
相信技术和创新的力量
喜欢快速反应的工作节奏