ASP.NET基础教程-利用(OfficeWeb控件)在网页上输出饼图
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://chenxing.blog.51cto.com/240526/58179 |
一、在项目中添加引用MSOWC.DLL,在OFFICE按装目录中可以找到,为OFFICE WEB开发控件
二、在表单上添加一个表格控件,ID为DataGrid.,添加一个IMAGE控件,ID为 IChart
三、在表单的加载事件中添加代码
private void Page_Load(object sender, System.EventArgs e)
{ if(!IsPostBack) { con=new SqlConnection(@ConfigurationSettings.AppSettings["server"]);
con.Open(); oSql=“select 违纪总归类,count(违纪总归类) as 违纪次数 from verify group by dept order by 违纪总归类 DESC "; da=new SqlDataAdapter(oSql,con); ds=new DataSet(); da.Fill (ds,"root");//将装有根结点的表取入内存数据集中 con.Close (); DataGrid.DataSource=ds; if(ds.Tables["root"].Rows.Count>0) { DataGrid.DataBind(); DataGrid.Width=170; Ccount="";//违纪次数 presenter="";//违纪总归类 for(int i=0;i<ds.Tables["root"].Rows.Count;i++) { presenter=presenter+ds.Tables["root"].Rows[i][0].ToString()+'\t'; Ccount=Ccount+ds.Tables["root"].Rows[i][1].ToString()+'\t'; } //创建ChartSpace对象来放置图表 OWC.ChartSpace objCSpace = new OWC.ChartSpaceClass(); //在ChartSpace对象中添加图表,Add方法返回chart对象 OWC.WCChart objChart =objCSpace.Charts.Add (0); //指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到 objChart.Type = OWC.ChartChartTypeEnum.chChartTypePie;//饼图 //指定图表是否需要图例 objChart.HasLegend = false; //给定标题 objChart.HasTitle = true; objChart.Title.Caption= "点检违纪统计表"; //给定x,y轴的图示说明 //添加一组图表数据 objChart.SeriesCollection.Add(0); //给定该组数据的名字 objChart.SeriesCollection[0].SetData (OWC.ChartDimensionsEnum.chDimSeriesNames, + (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral,"点检违纪统计图表"); //给定数据分类 objChart.SeriesCollection[0].SetData (OWC.ChartDimensionsEnum.chDimCategories, + (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral,presenter);//"Jan"+'\t'+"Feb"+'\t'+"Mar"+'\t'+"Apr"+'\t'+"May"+'\t'+"Jun"+'\t' ); //给定数据值 objChart.SeriesCollection[0].SetData (OWC.ChartDimensionsEnum.chDimValues, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral,Ccount);//"100"+'\t'+"20"+'\t'+"50"+'\t'+"60"+'\t'+"240"+'\t'+"20"+'\t'); objChart.SeriesCollection[0].DataLabelsCollection.Add(); objChart.SeriesCollection[0].DataLabelsCollection[0].Position=OWC.ChartDataLabelPositionEnum.chLabelPositionTop; objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue=true; //输出成GIF文件,参数为文件名、格式、图片大小 objChart.SeriesCollection[0].DataLabelsCollection[0].HasCategoryName=true; objChart.FirstSliceAngle=45;//将饼图或圆环图的第一扇区起始角度设置为 45 度。 objCSpace.ExportPicture(Server.MapPath("")+@"\Image\tmpFile_wjzgl.GIF", "GIF", 800,500); //输出成GIF文件,参数为文件名、格式、图片大小 IChart.Height=500; IChart.ImageUrl=@"Image\tmpFile_wjzgl.GIF"; }
}
} ![]() 本文出自 “半瓶香油-好男人时来运转” 博客,请务必保留此出处http://chenxing.blog.51cto.com/240526/58179 本文出自 51CTO.COM技术博客 |



晨星
博客统计信息
热门文章
最新评论
友情链接

