您好,登錄后才能下訂單哦!
第八章 圖形化報表
1.Highcharts
2.水晶報表
3.jqchart
4.MSChart:
例如:
//檢索重慶市月平均氣溫 string sql = @"select DATEPART (month,dtmMeasure) as 'Month',AVG (fltTemperature ) as 'AvgTemp' from TblTemperature where chvCityName ='重慶' group by DATEPART (month,dtmMeasure) order by Month desc"; DataSet ds = SqlHelper.Select(CommandType.Text, sql, null); //設置圖表背景顏色 this.Chart1.BackColor = Color.LightPink; //設置圖表邊框樣式 this.Chart1.BorderlineColor = Color.Green; //邊框線寬度 this.Chart1.BorderlineWidth = 5; //圖表邊框西安為細線 this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid; //標題 this.Chart1.Titles.Add("重慶市月平均氣溫走勢圖"); //設置圖表X,Y軸綁定的列 this.Chart1.Series[0].XValueMember = "Month"; this.Chart1.Series[0].YValueMembers = "AvgTemp"; //設置每個數據點標簽上顯示的值為數據點的值 this.Chart1.Series[0].IsValueShownAsLabel = true; //設置數據點標簽的文本格式] this.Chart1.Series[0].LabelFormat = "{0}℃"; //綁定數據源 this.Chart1.DataSource = ds; this.Chart1.DataBind();
//折線圖
//檢索重慶市月平均氣溫 string sql = @"select chvCityName, DATEPART (month,dtmMeasure) as 'Month',AVG (fltTemperature ) as 'AvgTemp' from TblTemperature where chvCityName ='重慶' or chvCityName ='北京' group by chvCityName,DATEPART (month,dtmMeasure) order by Month desc"; DataSet ds = SqlHelper.Select(CommandType.Text, sql, null); //為圖表添加2個序列 this.Chart1.Series.Clear(); this.Chart1.Series.Add("重慶"); this.Chart1.Series.Add("北京"); //設置每一個序列的圖表類型 this.Chart1.Series["重慶"].ChartType = SeriesChartType.Line; this.Chart1.Series["北京"].ChartType = SeriesChartType.Line; //設置圖表背景顏色 this.Chart1.BackColor = Color.Pink; //設置圖表邊框樣式 this.Chart1.BorderlineColor = Color.Green; //邊框線寬度 this.Chart1.BorderlineWidth = 5; //圖表邊框西安為細線 this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid; //標題 this.Chart1.Titles.Add("中國城市月平均氣溫走勢圖"); //圖例 this.Chart1.Legends.Add(""); foreach (DataRow row in ds.Tables [0].Rows ) { //定義數據點 DataPoint point = new DataPoint(Convert.ToDouble(row["Month"]), Convert.ToDouble(row["AvgTemp"])); //設置每個數據點在X軸的標簽文本 point.AxisLabel = string.Format("{0}月", row["Month"]); //設置每個數據點的標簽文本 point.Label = string.Format("{0}℃", row["AvgTemp"]); //設置鼠標懸浮至數據點的提示文本 point.LabelToolTip = string.Format("{0}月平均氣溫:{1}攝氏度", row["Month"], row["AvgTemp"]); this.Chart1.Series[row["chvCityName"].ToString()].Points.Add(point); }
//餅圖
//檢索重慶市月平均氣溫 string sql = @"select (case when intScore<60 then '不及格' when intScore<80 then '及格' when intScore<90 then '良' when intScore<=100 then '優秀' end) as Grade, count(*) as 'Count' from scoreinfo group by(case when intScore<60 then '不及格' when intScore<80 then '及格' when intScore<90 then '良' when intScore<=100 then '優秀' end)"; DataSet ds = SqlHelper1.Select(CommandType.Text, sql, null); //為圖表添加序列 this.Chart1.Series.Clear(); this.Chart1.Series.Add("Score"); //設置序列的圖表類型 this.Chart1.Series["Score"].ChartType = SeriesChartType.Pie; //設置背景顏色 this.Chart1.BackColor = Color.Pink; //設置圖表邊框樣式 this.Chart1.BorderlineColor = Color.Purple; this.Chart1.BorderlineWidth = 5; this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid; this.Chart1.Titles.Add("C#成績統計圖"); //文本顏色 this.Chart1.Series["Score"].LabelForeColor = Color.Gray; //字體大小,樣式 this.Chart1.Series["Score"].Font = new Font("宋體", 14); //計算總人數 int total = 0; foreach (DataRow row in ds.Tables[0].Rows) { total += Convert.ToInt32(row["Count"]); } foreach (DataRow row in ds.Tables[0].Rows) { //定義數據點 DataPoint point = new DataPoint(); //總人數 point.YValues = new double[] { Convert.ToDouble(row["Count"]) }; //設置每一個數據點標簽的文本值為百分比 point.Label = string.Format("{0:f2}%", Convert.ToDouble(row["Count"]) / total * 100); //設置圖例 this.Chart1.Legends.Add(row["Grade"].ToString()); point.LegendText = row["Grade"].ToString(); //將數據點添加到序列中 this.Chart1.Series["Score"].Points.Add(point); } //將數據點標簽顯示到圖示外側 Chart1.Series["Score"]["PieLabelStyle"] = "Outside"; //將第一個數據點展開 Chart1.Series["Score"].Points[0]["Exploded"] = "true";
//柱狀圖
//檢索重慶市月平均氣溫 string sql = @"select (case when intScore<60 then '不及格' when intScore<80 then '及格' when intScore<90 then '良' when intScore<=100 then '優秀' end) as Grade, count(*) as 'Count' from scoreinfo group by(case when intScore<60 then '不及格' when intScore<80 then '及格' when intScore<90 then '良' when intScore<=100 then '優秀' end)"; DataSet ds = SqlHelper1.Select(CommandType.Text, sql, null); //為圖表添加序列 this.Chart1.Series.Clear(); this.Chart1.Series.Add("Score"); //設置序列的圖表類型 this.Chart1.Series["Score"].ChartType = SeriesChartType.Column; //設置背景顏色 this.Chart1.BackColor = Color.Pink; //設置圖表邊框樣式 this.Chart1.BorderlineColor = Color.Purple; this.Chart1.BorderlineWidth = 5; this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid; this.Chart1.Titles.Add("C#成績統計圖"); //文本顏色 this.Chart1.Series["Score"].LabelForeColor = Color.Gray; //字體大小,樣式 this.Chart1.Series["Score"].Font = new Font("宋體", 14); //計算總人數 int total = 0; foreach (DataRow row in ds.Tables[0].Rows) { total += Convert.ToInt32(row["Count"]); } foreach (DataRow row in ds.Tables[0].Rows) { //定義數據點 DataPoint point = new DataPoint(); //總人數 point.YValues = new double[] { Convert.ToDouble(row["Count"]) }; //設置每一個數據點標簽的文本值為百分比 point.Label = string.Format("{0}人", Convert.ToDouble(row["Count"])); point.AxisLabel = row["Grade"].ToString(); //將數據點添加到序列中 this.Chart1.Series["Score"].Points.Add(point); //設置數據點被點擊后的回發值,該值可以在Click事件的ImageMapEventArgs參數中獲取 point.PostBackValue = string.Format("{0}|{1}", row["Grade"], row["Count"]); } //將數據點標簽顯示到圖示外側 Chart1.Series["Score"]["PieLabelStyle"] = "Outside"; //將第一個數據點展開 Chart1.Series["Score"].Points[0]["Exploded"] = "true";
5.XtraReports
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。