在C#中使用owc11 画折线图

1.引入owc对象

    可 通过两种途径使C#支持OWC

    A.安装Fontpage2003

   B.从microsoft网站上下载OWC

     http://www.microsoft.com/downloads/details.aspx?familyid=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=zh-cn

  在ASP.NET项目的“引入”中的“COM”项中选择“office web Components 11”就可以引入owc对象了。

2.引用OWC对象

   using Microsoft.Office.Interop.Owc11;

3.新建 OWC对象

  注:本例用的是一个交叉数据,如下表

缺陷完成数 缺陷未完成数 缺陷新建数   日期

 20               30                       10                2008-01-01

 50               10                       10                2008-01-02

 20               30                       10                2008-01-01

本例中要显示每天缺陷完成数、未完数、新建数情况

 

         ChartSpace mychartSpace = new ChartSpace();
        ChartSpace myspace = 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 = "X轴:天";
        mychart.Axes[1].HasTitle = true;
        mychart.Axes[1].Title.Caption = "Y轴:缺陷数";
        //新建三个系列(相当于数据库交叉的行记录)
        mychart.SeriesCollection.Add(0);mychart.SeriesCollection.Add(0);mychart.SeriesCollection.Add(0);
        mychart.SeriesCollection[0].Caption = "未完成数";
       
        mychart.SeriesCollection[1].Caption = "完成数";
       
        mychart.SeriesCollection[2].Caption = "新建数";
        //设置图表块的属性
        //标题
        string strDate = "";
        string strCreateBugCount = "";
        string strFinishBugCount = "";
        string strUnFinishBugCount = "";
        foreach(var P in "记录集")
        {
            //X坐标的值属性
            strCreateBugCount += P.CreateBugCount.ToString()+"/t";
            strFinishBugCount += P.FinishBugCount.ToString() +"/t";
            strUnFinishBugCount += P.UnFinishBugCount.ToString()+"/t";
            strDate += P.dDate.ToString().Substring(0, 9) + "/t";
        }


        mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDate);
        //y坐标的值属性
        mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strUnFinishBugCount);
        mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strFinishBugCount);
        mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strCreateBugCount);
        //Y轴数据
        //生成图片
      mychartSpace.ExportPicture(Server.MapPath(".") + @"/test.jpg", "jpg", 500, 350);
      //加载图片
      Image1.ImageUrl = Server.MapPath(".") + @"/test.jpg";

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值