C#编写OWC11组件源代码[2]

using System;
using System.Data;
using System.Text;

namespace FishPro
{
    
/// <summary>
    
/// 使用 OWCChart11 生成各种图表
    
/// 作者 焦军康
    
/// 日期 2006-7-5
    
/// </summary>

    public class OWCChart11
    
{
        
属性

        
枚举类型

        
构造函数

        
public bool Create()
        
{
            
//声明对象
            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 
= m_Title;//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=m_AxesXTitle;

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

            
//图表类型
            ThisChChart.Type=(Microsoft.Office.Interop.Owc11.ChartChartTypeEnum) m_Type;
//            switch(m_Type)
//            {
//                case 0:    
//                    ThisChChart.Type =(Microsoft.Office.Interop.Owc11.ChartChartTypeEnum) m_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.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(),m_SeriesName);
            
//给定分类
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),m_Category);
            
//给定值
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),m_Value);

            Microsoft.Office.Interop.Owc11.ChDataLabels dl
=ThisChChart.SeriesCollection[0].DataLabelsCollection.Add();   
            dl.HasValue
=true;
            
//dl.HasPercentage=true;   
            
//导出图像文件
            try
            
{       
                
if(m_FileName==null||m_FileName=="")
                
{
                    m_FileName
=DateTime.Now.ToString("yyyyMMddHHmmssff")+".gif";//生成图片名称
                }

                ThisChart.ExportPicture(m_SavePath
+"\\"+m_FileName,"gif",m_PicWidth,m_PicHeight);
                
return true;
            }
            
            
catch(Exception ee)                   
            
{
                
return false;                              
            }

            
return false;
        }

        
    }

}


上篇是一事例
posted @ 2006-09-16 19:56  拒绝潜水的鱼  阅读(4998)  评论(5编辑  收藏  举报