blog.Toby

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            130 隨筆 :: 2 文章 :: 150 評論 :: 0 Trackbacks

          microsoft office web 組件(owc11)的編程(.net)

          owc控件是microsoft office 圖表控件(owc10為ofiiceXP的組件、owc11為office2003的組件,組件的路徑為C:\Program Files\Common Files\Microsoft Shared\Web Components\11\owc11,幫助文件的路徑為C:\Program Files\Common Files\Microsoft Shared\Web Components\11\2052),它可以生成三維圖、柱狀圖、餅狀圖、趨勢圖和誤差圖,下面以生成三維圖web應(yīng)用程序為例:
          1,添加引用:在“com選項卡”中選擇“misrosoft office 11.0 object library”
          2,具體代碼如下:
            1using System;
            2
            3using System.Collections;
            4
            5using System.ComponentModel;
            6
            7using System.Data;
            8
            9using System.Drawing;
           10
           11using System.Web;
           12
           13using System.Web.UI;
           14
           15using Microsoft.Office.Interop;
           16
           17
           18namespace WebApplication2
           19{
           20    /// <summary>
           21    /// WebForm1 的摘要說明。
           22    /// </summary>

           23    public class WebForm1 : System.Web.UI.Page
           24    {
           25    
           26        private void Page_Load(object sender, System.EventArgs e)
           27        {
           28            string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t'+"4" + '\t' + "5" + '\t' + "6" + '\t';
           29            string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t'+"10" + '\t' + "12" + '\t' + "6" + '\t';
           30
           31            //聲明對象
           32            Microsoft.Office.Interop.Owc11.ChartSpace ThisChart = new  Microsoft.Office.Interop.Owc11.ChartSpaceClass();
           33            Microsoft.Office.Interop.Owc11.ChChart ThisChChart  = ThisChart.Charts.Add(0);
           34            Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0);
           35
           36            //顯示圖例
           37            ThisChChart.HasLegend = true;
           38            //標(biāo)題
           39            ThisChChart.HasTitle = true;
           40            ThisChChart.Title.Caption = "統(tǒng)計圖";
           41
           42            //給定x,y軸圖示說明
           43            ThisChChart.Axes[0].HasTitle = true;
           44            ThisChChart.Axes[1].HasTitle = true;
           45            ThisChChart.Axes[0].Title.Caption = "月份";
           46            ThisChChart.Axes[1].Title.Caption = "數(shù)量";
           47
           48            //圖表類型
           49            ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D;
           50            //旋轉(zhuǎn)
           51            ThisChChart.Rotation  = 360;
           52            ThisChChart.Inclination = 10;
           53            //背景顏色
           54            ThisChChart.PlotArea.Interior.Color = "red";
           55            //底色
           56            ThisChChart.PlotArea.Floor.Interior.Color = "green";
           57
           58            ThisChChart.Overlap = 50;
           59
           60            ////給定series的名字
           61            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),"日期");
           62            //給定分類
           63            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
           64            //給定值
           65            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);
           66            //導(dǎo)出圖像文件
           67            try
           68            {
           69                
           70                ThisChart.ExportPicture(Server.MapPath("chart.gif"),"gif",600,350);
           71                Response.Write( "<IMG SRC='" + Server.MapPath("chart.gif")  + "'/>");
           72            }

           73            catch(Exception ee)
           74            {
           75            
           76            }

           77            
           78//            object [] objarr=new object[3];
           79//            objarr[0]=12;
           80//            objarr[1]=13;
           81//            objarr[2]=14;
           82//            DataTable dt=new DataTable();
           83//            dt.Columns.Add("id");
           84//            dt.Columns.Add("wei");
           85//            dt.Columns.Add("hei");
           86//            dt.Rows.Add(objarr);
           87//            DataSet ds=new DataSet();
           88//            ds.Tables.Add(dt);
           89//            Response.Write(this.toChartLine3(ds,"100","","adasd","sdasad","sadsadsa"));
           90        }

           91
           92        #region Web 窗體設(shè)計器生成的代碼
           93        override protected void OnInit(EventArgs e)
           94        {
           95            //
           96            // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。
           97            //
           98            InitializeComponent();
           99            base.OnInit(e);
          100        }

          101        
          102        /// <summary>
          103        /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
          104        /// 此方法的內(nèi)容。
          105        /// </summary>

          106        private void InitializeComponent()
          107        {    
          108            this.Load += new System.EventHandler(this.Page_Load);
          109
          110        }

          111        #endregion

          112        
          113    }

          114}
          里面的注釋很詳細(xì),如有疑問請發(fā)郵件ycguo@nmdsy.com;其余的圖表生成,請看幫助OWCDCH11.CHM
          posted on 2008-08-16 09:52 渠上月 閱讀(876) 評論(0)  編輯  收藏 所屬分類: OLAP
          主站蜘蛛池模板: 乌鲁木齐县| 无锡市| 根河市| 瑞安市| 卓尼县| 旌德县| 城口县| 邯郸市| 屏山县| 香格里拉县| 重庆市| 郴州市| 彭州市| 华安县| 阿拉善右旗| 淮安市| 天祝| 石首市| 奉新县| 通道| 平罗县| 乌拉特后旗| 襄垣县| 会宁县| 瑞金市| 孝义市| 紫金县| 社会| 开鲁县| 临高县| 铜梁县| 北川| 化隆| 竹北市| 襄垣县| 阿勒泰市| 赤峰市| 都兰县| 正安县| 清镇市| 醴陵市|