`

在asp.net中调用Office来制作各种(3D)统计图

阅读更多
作者:未知   由于本文网上多处见到 对于谁是作者 无法肯定

 

 

1、下载owc11 COM组件

http://www.microsoft.com/downloads/details.aspx?FamilyID=7287252c-402e-4f72-97a5-e0fd290d4b76&displaylang=en 

2、注册owc11

  在工程中添加 C:\Program Files\Common Files\Microsoft Shared\Web Components\11  文件下的owc11.dll引用  或者按如下图所以添加com

Add reference to Web Components

 

3、在工程中添加

    using OWC11;

4、开始coding  举例如下:

 

 public class ChartFactory
 {
  public ChartFactory()
  {
   InitTypeMap();
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  protected System.Web.UI.WebControls.Image imgHondaLineup;
  private string[] chartCategoriesArr;
  private string[] chartValuesArr;
  private OWC11.ChartChartTypeEnum chartType =  OWC11.ChartChartTypeEnum.chChartTypeColumn3D;//默认值
  private static Hashtable chartMap = new Hashtable();
  private static string chartTypeCh = "垂直柱状图" ;
  private static string chartTitle = "";

  private void InitTypeMap()
  {
   chartMap.Clear();
   OWC11.ChartChartTypeEnum[] chartTypes = new OWC11.ChartChartTypeEnum[]{ ChartChartTypeEnum.chChartTypeColumnClustered,
                    ChartChartTypeEnum.chChartTypeColumn3D,
                    ChartChartTypeEnum.chChartTypeBarClustered,
                    ChartChartTypeEnum.chChartTypeBar3D,
                    ChartChartTypeEnum.chChartTypeArea,
                    ChartChartTypeEnum.chChartTypeArea3D,
                    ChartChartTypeEnum.chChartTypeDoughnut,
                    ChartChartTypeEnum.chChartTypeLineStacked,
                    ChartChartTypeEnum.chChartTypeLine3D,
                    ChartChartTypeEnum.chChartTypeLineMarkers,
                    ChartChartTypeEnum.chChartTypePie,
                    ChartChartTypeEnum.chChartTypePie3D,
                    ChartChartTypeEnum.chChartTypeRadarSmoothLine,
                    ChartChartTypeEnum.chChartTypeSmoothLine};
   string[] chartTypesCh = new string [] {"垂直柱状统计图","3D垂直柱状统计图","水平柱状统计图","3D水平柱状统计图","区域统计图","3D区域统计图","中空饼图","折线统计图","3D折线统计图","折线带点统计图","饼图","3D饼图","网状统计图","弧线统计图"};
   
   for(int i=0;i<chartTypes.Length;i++)
   {
    chartMap.Add(chartTypesCh[i],chartTypes[i]);
   }
  }

  public ChartSpaceClass BuildCharts ()
  {
   string chartCategoriesStr = String.Join ("\t", chartCategoriesArr);
   string chartValuesStr = String.Join ("\t", chartValuesArr);

   OWC11.ChartSpaceClass       oChartSpace = new OWC11.ChartSpaceClass ();

   // ------------------------------------------------------------------------
   // Give pie and doughnut charts a legend on the bottom. For the rest of
   // them let the control figure it out on its own.
   // ------------------------------------------------------------------------

   chartType = (ChartChartTypeEnum)chartMap[chartTypeCh];

   if (chartType == ChartChartTypeEnum.chChartTypePie ||
    chartType == ChartChartTypeEnum.chChartTypePie3D ||
    chartType == ChartChartTypeEnum.chChartTypeDoughnut)
   {
    oChartSpace.HasChartSpaceLegend = true;
    oChartSpace.ChartSpaceLegend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
   }

   oChartSpace.Border.Color = "blue";
   oChartSpace.Charts.Add(0);
   oChartSpace.Charts[0].HasTitle = true;
   oChartSpace.Charts[0].Type = chartType;
   oChartSpace.Charts[0].ChartDepth = 125;
   oChartSpace.Charts[0].AspectRatio = 80;
   oChartSpace.Charts[0].Title.Caption = chartTitle;
   oChartSpace.Charts[0].Title.Font.Bold = true;

   oChartSpace.Charts[0].SeriesCollection.Add(0);
   oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection.Add ();

   // ------------------------------------------------------------------------
   // If you're charting a pie or a variation thereof percentages make a lot
   // more sense than values...
   // ------------------------------------------------------------------------
   if (chartType == ChartChartTypeEnum.chChartTypePie ||
    chartType == ChartChartTypeEnum.chChartTypePie3D ||
    chartType == ChartChartTypeEnum.chChartTypeDoughnut)
   {
    oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
    oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
   }
    // ------------------------------------------------------------------------
    // Not so for other chart types where values have more meaning than
    // percentages.
    // ------------------------------------------------------------------------
   else
   {
    oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = false;
    oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = true;
   }
               
   // ------------------------------------------------------------------------
   // Plug your own visual bells and whistles here
   // ------------------------------------------------------------------------
   oChartSpace.Charts[0].SeriesCollection[0].Caption = String.Empty;
   oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Name = "verdana";
   oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Size = 10;
   oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Bold = true;
   oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Color = "red";
   oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionCenter;
   
   if (chartType == ChartChartTypeEnum.chChartTypeBarClustered ||
    chartType == ChartChartTypeEnum.chChartTypeBar3D ||
    chartType == ChartChartTypeEnum.chChartTypeColumnClustered ||
    chartType == ChartChartTypeEnum.chChartTypeColumn3D)
   {
    oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;
   }
   
   oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimCategories,
    Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartCategoriesStr);

   oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimValues,
    Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartValuesStr);

   return oChartSpace;
  }

  #region  属性设置
  public string[] chartCategoriesArrValue
  {
   get
   {
    return chartCategoriesArr;
   }
   set
   {
    chartCategoriesArr = value;
   }
  }

  public string[] chartValuesArrValue
  {
   get
   {
    return chartValuesArr;
   }
   set
   {
    chartValuesArr = value;
   }
  }
  public string chartTypeValue
  {
   get
   {
    return chartTypeCh;
   }
   set
   {
    chartTypeCh = value;
   }
  }
  public string chartTitleValue
  {
   get
   {
    return chartTitle;
   }
   set
   {
    chartTitle = value;
   }
  }
  #endregion
 }

 

//调用   首先需要在页面上放置一个Image来显示产生的统计图

  public void ShowChart()
  {

//初始化赋值
   chartFactory.chartCategoriesArrValue = chartCategories;
   chartFactory.chartValuesArrValue = chartValues;
   chartFactory.chartTitleValue = chartTitle;
   chartFactory.chartTypeValue = chartType;

   OWC11.ChartSpaceClass oChartSpace = chartFactory.BuildCharts();
   string path = Server.MapPath(".") + @"\images\Chart.jpeg";  //产生图片并保存 页可以是png gif图片
   oChartSpace.ExportPicture(path,"jpeg", 745, 500);
   Image1.ImageUrl = path;  // 显示统计图
  }

// 保存统计图请参照上一篇文章

//由于每次生成的统计图都会覆盖原来的图片所以有必要的话可以用日期加时间的方式来作为图片的名字,但是这样将会产生很多图片需及时处理,如不需要只需取同名覆盖原来图片即可。

分享到:
评论

相关推荐

    asp.net中调用Office来制作3D统计图的实例代码

    在***中调用Office组件来制作3D统计图,既能够利用Office强大的图形处理能力,又能够结合Web应用程序的优势,为用户提供在线的数据展示功能。 首先,我们需要了解的是在***中如何调用Office组件。由于***主要运行在...

    OWC11画统计图(vb.net)

    通过OWC11,即使是初学者也能快速掌握如何在ASP.NET中绘制统计图表。 #### 技术背景 **Office Web Components (OWC)** 是一套集成在Microsoft Office 2000中的组件库,提供了多种工具用于处理和展示数据。这些组件...

    echarts 生成统计图时,自动保存图片到服务器,并使用freemarker生成带图片和循环表格的word

    在ECharts中生成统计图,首先需要引入ECharts库,然后配置图表的选项(option),包括数据、图表类型、颜色、轴标签等,最后调用`myChart.setOption(option)`方法初始化和更新图表。 保存ECharts图表到服务器通常...

    OWC c# 统计图片生成

    标题中的“OWC c# 统计图片生成”指的是使用C#编程语言,结合OWC(Office Web Components)库来创建统计图表的图像生成技术。OWC是微软提供的一组Web控件,允许开发者在Web应用程序中嵌入类似于Excel、Word和...

    c#中读写office工具

    在IT行业中,尤其是在软件开发领域,C#是一种广泛使用的编程语言,它提供了丰富的库和工具来处理各种任务,包括与Microsoft Office的交互。本篇文章将深入探讨如何在C#中读写Office文件,特别是Excel,并利用OWC11库...

    源码统计器1.1版(源码+软件)

    最后在CountThread线程中加入判断,如果文件类型为TYPE_MY,则调用函数GetMyFileLines ( )进行统计。 具体操作可参考源代码相应的处理。 6、 软件所使用的资源绝大部分位于资源文件中,便于用户更改其语言版本以用...

    asp+ACCESS图书管理系统设计(源代码+论文+开题报告+答辩PPT).zip

    在这个系统中,ASP(Active Server Pages)作为前端脚本语言,负责处理用户交互,生成动态网页;而ACCESS数据库则作为后端数据存储和管理工具,用于存储图书信息、借阅记录等数据。 ASP是一种微软公司的服务器端...

    ASP+ACCESS学籍信息管理系统DA版(源代码+论文+答辩PPT).zip

    ACCESS是微软Office套件中的一个关系型数据库管理系统,使用Jet引擎作为其数据存储后端。它的优点包括: 1. 用户友好:提供图形化界面,方便用户创建、编辑和管理数据库。 2. 数据类型丰富:支持各种常用的数据类型...

    OA自动化管理系统设计说明书.docx

    - **浏览器兼容性**: ASP.NET程序在服务器端执行,最终生成的HTML页面可以在各种浏览器中正常显示。 - **语言兼容性**: ASP.NET支持多种脚本语言,如VBScript、JavaScript等,同时也支持.NET框架中的其他编程语言。 ...

    2021-2022计算机二级等级考试试题及答案No.1778.docx

    23. 页面事件:在ASP.NET中,Page_Load事件在页面加载时自动调用。 24. 循环执行次数:For循环`For I%= -1 to -17 Step -2`共执行6次。 25. Excel2000介绍:Excel2000是Microsoft Office2000套装的一部分,用于...

    2021-2022计算机二级等级考试试题及答案No.18887.docx

    在实现递归调用的过程中,每次函数调用都需要保存当前状态以便于后续返回,这就需要一种有效的数据结构来管理这些状态。栈是一种后进先出(LIFO)的数据结构,非常适合用于递归调用的管理。每当发生一次函数调用,...

    2021-2022计算机二级等级考试试题及答案No.5500.docx

    7. **ASP.NET支持的语言**:ASP.NET支持VB .NET(A)、Javascript(B)和C#(D),但不支持PHP(C)。 8. **高速缓冲存储器**:微型计算机配置高速缓冲存储器(Cache)是为了缓解CPU和内存之间速度差异的问题,提高...

    计算机网络应用设计实验报告.pdf

    在源程序中,使用VC++和VS2008开发环境,通过CInternetSession类来创建FTP连接,并利用GetFtpConnection方法与服务器建立TCP连接。当连接成功时,程序会列出FTP服务器上的所有文件。CInternetException类用于捕获和...

    2021-2022计算机二级等级考试试题及答案No.11024.docx

    例如,在ASP.NET中,`Response.Write()`用于输出数据到客户端浏览器。 #### 6. Servlet初始化方法 - **知识点**: 当Servlet首次被请求时,服务器会调用`init()`方法。 - **解析**: 在Servlet生命周期中,`init()`...

    Visual Basic多用途编程可视化编程Visual Basic多用途编程可视化编程

    它可以与ASP.NET等现代Web开发技术相结合,帮助开发者构建功能强大且易于维护的Web应用程序。 **5. 数据分析和科学计算** 除了传统的应用程序开发外,Visual Basic还可以应用于数据分析和科学计算领域。借助Visual...

Global site tag (gtag.js) - Google Analytics