OWC使用技巧(C#)(本帖来源于网上和本人的整理)

 
 1 using  System;
  2
  3 using System.Collections;
  4
  5 using System.ComponentModel;
  6
  7 using System.Data;
  8
  9 using System.Drawing;
 10
 11 using System.Web;
 12
 13 using System.Web.UI;
 14
 15 using Microsoft.Office.Interop;
 16
 17
 18 namespace 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             //
标题
 39             ThisChChart.HasTitle = true;
 40             ThisChChart.Title.Caption = "
统计图 ";
 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 = "
数量 ";
 47
 48             //
图表类型
 49             ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D;
 50             //
旋转
 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             //
导出图像文件
 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         Web 
窗体设计器生成的代码 #region  Web  窗体设计器生成的代码
 93         override protected void OnInit(EventArgs e)
 94         {
 95             //
 96             // CODEGEN: 
该调用是  ASP.NET Web  窗体设计器所必需的。
 97             //
 98             InitializeComponent();
 99             base.OnInit(e);
100         }
101         
102         /**//// <summary>
103         /// 
设计器支持所需的方法  -  不要使用代码编辑器修改
104          ///  此方法的内容。
105          ///  </summary>
106         private void InitializeComponent()
107         {    
108             this.Load += new System.EventHandler(this.Page_Load);
109
110         }
111         #endregion
112         
113     }
114 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值