C#编写OWC11组件源代码(2)


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop;

namespace FishPro
{
 ///


 /// 利用OWC组件生成柱状图示例
 ///

 public class TestOWC : System.Web.UI.Page
 {
  private void Page_Load(object sender, System.EventArgs e)
  {

   string strCategory = "1" + '/t' + "2" + '/t' + "3" + '/t'+"4" + '/t' + "5" + '/t' + "6" + '/t'+"7" + '/t' + "8" + '/t' + "9" + '/t'+"10" + '/t' + "11" + '/t' + "12" + '/t';
   string strValue = "9000" + '/t' + "8000" + '/t' + "4007" + '/t'+"10" + '/t' + "12760" + '/t' + "6678" + '/t'+"10000" + '/t' + "20999" + '/t' + "3567" + '/t'+"456" + '/t' + "125" + '/t' + "66765" + '/t';
   string mTitle="建科院月报表分析图";
   string xTitle="月份";
   string yTitle="工作量";
   int imgWidth=780;
   int imgHeight=600;
   int chartType=0;
   //this.CreateChartSmoothLine(strCategory,strValue,mTitle,xTitle,yTitle,imgWidth,imgHeight,chartType);
   FishPro.OWCChart11 chart = new OWCChart11(Server.MapPath("."),"费用",mTitle,1,xTitle,yTitle,imgWidth,imgHeight);
   chart.OCategory=strCategory;
   chart.OValue=strValue;
   if(chart.Create())
   {
    Response.Write( "");
   }
   else
   {
    Response.Write("shibai");
   }
   
//   // 在此处放置用户代码以初始化页面
//   string strCategory = "1" + '/t' + "2" + '/t' + "3" + '/t'+"4" + '/t' + "5" + '/t' + "6" + '/t'+"7" + '/t' + "8" + '/t' + "9" + '/t'+"10" + '/t' + "11" + '/t' + "12" + '/t';
//   string strValue = "9" + '/t' + "8" + '/t' + "4" + '/t'+"10" + '/t' + "12" + '/t' + "6" + '/t'+"1" + '/t' + "2" + '/t' + "3" + '/t'+"4" + '/t' + "12" + '/t' + "6" + '/t';
//
//   //声明对象
//   Microsoft.Office.Interop.Owc11.ChartSpace ThisChart = new  Microsoft.Office.Interop.Owc11.ChartSpaceClass();
//   Microsoft.Office.Interop.Owc11.ChChart ThisChChart  = ThisChart.Charts.Add(0);
//   Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0);
//   
//
//   //显示图例
//   ThisChChart.HasLegend = true;
//   //标题
//   ThisChChart.HasTitle = true;
//   ThisChChart.Title.Caption = "统计图";
//   //给定x,y轴图示说明
//   ThisChChart.Axes[0].HasTitle = true;
//   ThisChChart.Axes[1].HasTitle = true;
//   ThisChChart.Axes[0].Title.Caption = "月份";
//   ThisChChart.Axes[1].Title.Caption = "数量";
//
//   //图表类型
//   //ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D;//3D 柱状图
//   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine;//平滑曲线图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeArea; //折线面积图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeArea3D;//折线3D面积图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaOverlapped3D;//折线3D面积图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked;//折线面积图加边框
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked100;//折线面积图加边框百分比图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked1003D;//折线3D面积图加边框百分比图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked3D;//折线3D面积图加边框
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBar3D;//横道图3D
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarClustered;//横道图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarClustered3D;//横道图3D
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked;//横道图3D
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked100;//横道图3D百分比图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked1003D;//横道图3D百分比图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBubble; //测试不通过
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBubbleLine;//测试不通过
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumn3D;//柱状图3D
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered;//柱状图3D
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D;//柱状图3D
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked;//柱状图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked100;//柱状图3D 百分比图
   ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked1003D;//柱状图3D百分比图
//   //ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartLegendPositionEnum.chLegendPositionBottom;
//   //旋转
//   ThisChChart.Rotation  = 360;
//   ThisChChart.Inclination = 10;
//   //背景颜色
//   ThisChChart.PlotArea.Interior.Color = "red";
//   ThisChChart.PlotArea.Floor.Interior.Color = "green";
//   
//   ThisChChart.Overlap = 50;
//
//   /给定series的名字
//   ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),"日期");
//   //给定分类
//   ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
//   //给定值
//   ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);
//
//   //导出图像文件
//   try
//   {
//                  
//    ThisChart.ExportPicture(Server.MapPath("chart.gif"),"gif",600,350);
//    Response.Write( "");
//   }
//        
//   catch(Exception ee)
//                
//   {
//                    
//   }

   

  }

  //平滑曲线图
  //ChartType 0 默认柱状图 1 横道图 2 平滑曲线图
  public  void  CreateChartSmoothLine(string strCategory,string strValue,string mTitle,string xTitle,string yTitle,int imgWidth,int imgHeight,int chartType)
  {
   //声明对象
   Microsoft.Office.Interop.Owc11.ChartSpace ThisChart = new  Microsoft.Office.Interop.Owc11.ChartSpaceClass();
   Microsoft.Office.Interop.Owc11.ChChart ThisChChart  = ThisChart.Charts.Add(0);
   Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0);
   
   //显示图例
   ThisChChart.HasLegend = true;

   //显示标题选项
   ThisChChart.HasTitle = true;
   ThisChChart.Title.Font.Name="黑体";
   ThisChChart.Title.Font.Size=14;
   ThisChChart.Title.Caption = mTitle;//from

   //x,y轴说明
   //x
   ThisChChart.Axes[0].HasTitle=true;
   ThisChChart.Axes[0].Title.Font.Name="黑体";
   ThisChChart.Axes[0].Title.Font.Size=12;
   ThisChChart.Axes[0].Title.Caption=xTitle;

   ThisChChart.Axes[1].HasTitle=true;
   ThisChChart.Axes[1].Title.Font.Name="黑体";
   ThisChChart.Axes[1].Title.Font.Size=12;
   ThisChChart.Axes[1].Title.Caption=yTitle;

   //图表类型
   switch(chartType)
   {
    case 0: 
     ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumn3D;//柱状图3D
     break;
    case 1:
     ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBar3D;//横道图3D
     break;
    case 2:
     ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine;//平滑曲线图
     break;
    case 3:
     ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie;//圆饼图
     break;
   }
   //ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine;//平滑曲线图
   //旋转
   ThisChChart.Rotation  = 360;
   ThisChChart.Inclination = 10;
   //背景颜色
   ThisChChart.PlotArea.Interior.Color = "red";
   ThisChChart.PlotArea.Floor.Interior.Color = "green";
   
   //ThisChChart.Overlap = 50;

   /给定series的名字
   ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),"日期");
   //给定分类
   ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
   //给定值
   ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);

   //导出图像文件
   try
   {
                  
    ThisChart.ExportPicture(Server.MapPath("chart.gif"),"gif",imgWidth,imgHeight);
    Response.Write( "");
   }
        
   catch(Exception ee)
                
   {
                    
   }

   

   
  }


  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  ///


  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  ///

  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion
 }
}

 

你可能感兴趣的:(C#编写OWC11组件源代码(2))