您现在的位置: 捷凌网安 >> 服务器 >> WEB开 发 >> ASP.NET >> 正文
ASP.NET 2.0中使用OWC生成图表

作者:佚名 责任编辑:左决 点击数: 更新时间:2008-2-28 9:55:16

 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";
}


  • 上一篇文章:

  • 下一篇文章:
  •  
    最进更新
    普通文章foxpro 更新源表05-05
    普通文章foxpro 让视图与数据源相连05-05
    普通文章foxpro 机动查询和数据输入05-05
    普通文章foxpro 多个本地数据05-05
    普通文章foxpro 维护源表05-05
    普通文章Oracle 10g Release2新功能之05-05
    普通文章将Oracle 10g内置的安全特性05-05
    普通文章ACCESS 2003 建立数据库视频05-05
    普通文章三种SQL分页法效率分析05-05
    普通文章优化MySQL数据库查询的三种方05-05
     
    推荐文章
    推荐文章教你怎样在MySQL中提高全文搜05-05
    推荐文章SQL Server中数据导入导出三05-05
    推荐文章缓冲技术提高JSP程序的性能和04-17
    推荐文章asp去除HTML标记的三个实用函04-17
    推荐文章何时使用DataGrid、DataList04-17
    推荐文章MySQL存储过程示例04-14
    推荐文章华硕搭建Exchange2007企业邮03-14
    推荐文章升级Win 2003到Windows 200803-14
    推荐文章windows Server 2003 搭建域03-14
    推荐文章服务器成为IT中心的6个理由03-11
     
    热点文章 
    普通文章SQL Server 2008分析服务概览05-01
    普通文章Dlink路由器VPN设置04-29
    推荐文章缓冲技术提高JSP程序的性能和04-17
    普通文章教你优化你的ASP程序04-17
    推荐文章asp去除HTML标记的三个实用函04-17
    普通文章ASP添加验证码的解决方法04-17
    推荐文章何时使用DataGrid、DataList04-17
    普通文章Asp.net中禁止用户多次登录04-17
    普通文章MySQL之表结构修改04-14
    推荐文章MySQL存储过程示例04-14

    | 设为首页 | 加入收藏 | 联系站长 | 广告服务 | 友情链接 | 版权申明 | 网站地图 |

    在线交流 捷凌网安主群:51649627
    Copyright 2007-2008 © 捷凌网安. All rights reserved.
    备案序号:蜀ICP备08001812号