网站建设
  简约型网页设计套餐998
  实惠型网站建设套餐2580
  综合型网站制作套餐4980
  网站改版与网站维护
  行业网站建设方案
  大型网站建设解决方案
  企业网站建设流程
  帝网科技网站设计与网站制作
建站FAQ
·网站空间问题解答
·企业邮箱问题解答
 
酷站欣赏
·房产酷站(379)
·综合门户(8 9)
·建筑装饰(603)
·手机通讯(354)
·生活购物(376)
·医疗保健(199)
·文化摄影(602)
·休闲体育(399)
>>更多酷站欣赏
网站优化
·Google(谷歌)优化   ·百度(BaiDu)优化
·雅虎(Yahoo)优化    ·Alexa排名优化   
·Google AdSense   ·DMOZ目录提交  
建站知识
·网站建设知识·网站名词解释·网站运营知识
·网络营销知识·搜索引擎知识·实用技术文摘
网站推广
百度网站推广 google网站推广
搜狐网站推广 网易网站推广
新浪网站推广   雅虎网站推广
  您当前位置: 当前位置:帝网科技 >> web开发 >> .NET专栏 >> 浏览文章
 
 
ASP.NET 2.0中使用OWC生成图表
作者:编辑整理 来源:帝网科技 日期:2009年02月08日 点击数:


  ASP.NET 2.0中,要显示图型的话,可以用MS office 2003的OWC组件,可以十分方便地看到图表。在工程中,首先添加microsoft office web components 11.0的引用就可以了,然后要using Microsoft.Office.Interop.Owc11;

  1、生成柱状图

  //创建X坐标的值,表示月份 int[] Month = new int[3] { 1, 2, 3 }; //创建Y坐标的值,表示销售额 double[] Count = new double[3] { 120,240,220}; //创建图表空间 ChartSpace mychartSpace = new ChartSpace(); //在图表空间内添加一个图表对象 ChChart mychart = mychartSpace.Charts.Add(0); //设置图表类型,本例使用柱形 mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered; //设置图表的一些属性 //是否需要图例 mychart.HasLegend = true; //是否需要主题 mychart.HasTitle = true; //主题内容 mychart.Title.Caption = "一季度总结"; //设置x,y坐标 mychart.Axes[0].HasTitle = true; mychart.Axes[0].Title.Caption = "月份"; mychart.Axes[1].HasTitle = true; mychart.Axes[1].Title.Caption = "销量"; //添加三个图表块 mychart.SeriesCollection.Add(0); mychart.SeriesCollection.Add(0); mychart.SeriesCollection.Add(0); //设置图表块的属性 //标题 mychart.SeriesCollection[0].Caption = "一月份"; //X坐标的值属性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[0]); //y坐标的值属性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[0]); //第二个块 mychart.SeriesCollection[1].Caption = "二月份"; //X坐标的值属性 mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[1]); //y坐标的值属性 mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[1]); //第三个块 mychart.SeriesCollection[2].Caption = "三月份"; //X坐标的值属性 mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[2]); //y坐标的值属性 mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[2]); //生成图片 mychartSpace.ExportPicture(Server.MapPath(".") + @"\test.jpg", "jpg", 500, 450); //加载图片 Image1.ImageUrl = Server.MapPath(".") + @"\test.jpg"; }

  2、生成饼状图

  protected void Page_Load(object sender, EventArgs e) { //创建X坐标的值,表示月份 int[] Month ={ 1, 2, 3 }; //创建Y坐标的值,表示销售额 double[] Count ={ 120, 240, 220 }; string strDataName = ""; string strData = ""; //创建图表空间 ChartSpace mychartSpace = new ChartSpace(); //在图表空间内添加一个图表对象 ChChart mychart = mychartSpace.Charts.Add(0); //设置每块饼的数据 for (int i = 0; i < Count.Length; i++) { strDataName += Month[i] + "\t"; strData += Count[i].ToString() + "\t"; } //设置图表类型,本例使用柱形 mychart.Type = ChartChartTypeEnum.chChartTypePie; //设置图表的一些属性 //是否需要图例 mychart.HasLegend = true; //是否需要主题 mychart.HasTitle = true; //主题内容 mychart.Title.Caption = "一季度总结"; //添加图表块 mychart.SeriesCollection.Add(0); //设置图表块的属性 //分类属性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName); //值属性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData); //显示百分比 ChDataLabels mytb= mychart.SeriesCollection[0].DataLabelsCollection.Add(); mytb.HasPercentage = true; //生成图片 mychartSpace.ExportPicture(Server.MapPath(".") + @"\test.gif", "gif", 500, 450); //加载图片 Image1.ImageUrl = Server.MapPath(".") + @"\test.gif"; }

  相关文章
 
·ASP.NET使用log4Net日志组件教程(日志
·ASP.NET MVC 框架
·C#实现的BinaryTree
·WebForms使用System.Web.Routing
·ASP.NET获取远程网页下载到本地文件
·一个“简单”的ASP.NET的服务器控件
·ASP.net与PHP两大网站开发架构优势对比
·教你七招提高.NET网站性能
·ASP.NET未来:简化开发 HTML5性能提升
·ASP.NET实现类似Excel的数据透视表
·FileUpload上传多文件出现错误的解决方
·.NET从优酷专辑中采集所有视频及信息(
·ASP.NET 4中的SEO改进
·详解Asp.net MVC DropDownLists
·提高ASP.NET应用程序性能的几招方法
·asp.net实现51job地区选择效果
·ASP.NET中创建GeoRSS订阅源
·ASP.NET 4.0开发更加简便
·ASP.NET页面间数据传递的方法
·ASP.NET的SEO:使用.ashx文件——排除
 
 

公司环境 | 合作伙伴 | 人才招聘 | 付款方式 | 关于我们

地址:广州市天河区中山大道中120号D805 电话:020-82529556 传真:020-82529556
广州帝网网络科技有限公司 版权所有 粤ICP备08119341号