第八章图形化报表
第八章 图形化报表
成都创新互联主营靖安网站建设的网络公司,主营网站建设方案,成都APP应用开发,靖安h5小程序定制开发搭建,靖安网站营销推广欢迎靖安等地区企业咨询
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
本文名称:第八章图形化报表
网站地址:http://myzitong.com/article/ghdgpg.html