owc11生成柱状统计图

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 OWC11;
using System.IO  ;




namespace WebApplication1
{
    
/// <summary>
    
/// WebForm1 的摘要说明。
    
/// </summary>

    public class WebForm1 : System.Web.UI.Page
    
{
            
protected System.Web.UI.WebControls.PlaceHolder ChartHolder;

        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面

            
// 在此处放置用户代码以初始化页面
            
//创建ChartSpace对象来放置图表

            
            
string[] files = System.IO.Directory.GetFiles(Server.MapPath("."+ "\\Images_Temp\\");
            
            
foreach(string file in files)
            
{
                
                
if(File.GetCreationTime(file).Day != System.DateTime.Now.Day)
                
{
                    File.Delete(file);

                 
                
                    
                    
                }



            }




            OWC11.ChartSpace objCSpace 
= new OWC11.ChartSpaceClass (); 
                      
            OWC11.ChChart  objChart
=objCSpace.Charts.Add(0);
                
             
            
//在ChartSpace对象中添加图表,Add方法返回chart对象
            
           

            
//指定图表的类型。类型由OWC11.ChartChartTypeEnum枚举值得到
            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeColumnClustered ;

            
//指定图表是否需要图例
            objChart.HasLegend = true;

            
//给定标题
            objChart.HasTitle = true;
            objChart.Title.Caption
= "上半年分布图";

            
//给定x,y轴的图示说明
            objChart.Axes[0].HasTitle = true;
            objChart.Axes[
0].Title.Caption = "Y : 数量";
            objChart.Axes[
1].HasTitle = true;
            objChart.Axes[
1].Title.Caption = "X : 月份";

            
//计算数据
            /*categories 和 values 可以用tab分割的字符串来表示*/
            
string strSeriesName = "图例 1";
            
string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t'+"4" + '\t' + "5" + '\t' + "6" + '\t';
            
string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t'+"10" + '\t' + "12" + '\t' + "6" + '\t';

            
//添加一个series
            objChart.SeriesCollection.Add(0);
            objChart.SeriesCollection.Add(
1);

            
//给定series的名字
            objChart.SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimSeriesNames,
                 (
int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);
            objChart.SeriesCollection[
1].SetData (OWC11.ChartDimensionsEnum.chDimSeriesNames,
                 (
int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);
     
            
//给定分类
            objChart.SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimCategories,
                 (
int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);
            objChart.SeriesCollection[
1].SetData (OWC11.ChartDimensionsEnum.chDimCategories,
                (
int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);
            
//给定值
            objChart.SeriesCollection[0].SetData
                (OWC11.ChartDimensionsEnum.chDimValues,
                (
int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue); 
            
            objChart.SeriesCollection[
1].SetData
                (OWC11.ChartDimensionsEnum.chDimValues,
                (
int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue); 
            
            OWC11.ChDataLabels dls 
= objChart.SeriesCollection[0].DataLabelsCollection.Add();
            dls.HasValue 
= true;
        
            
            dls.Font .Name
="宋体";

            OWC11.ChDataLabels  dls1 
= objChart.SeriesCollection[1].DataLabelsCollection.Add();
            dls1.HasValue 
= true;
            
//输出成GIF文件.
            string temp=System.DateTime.Now.ToString ("yyyy-MM-dd-hh-mm-ss");
        
string strAbsolutePath = (Server.MapPath(".")) + "\\Images_Temp\\"+temp+".gif";
        
            
            objCSpace.ExportPicture(strAbsolutePath, 
"GIF"600450);

            
//创建GIF文件的相对路径.
            string strRelativePath = "./test1.gif";

            
//把图片添加到placeholder.
            string strImageTag = "<IMG SRC='"+strRelativePath+"'/>";
            ChartHolder.Controls.Add(
new LiteralControl(strImageTag));
        
         
                   
        }


        
Web 窗体设计器生成的代码

    




        

    }

}

posted on 2005-10-27 09:34  gwazy  阅读(1573)  评论(0编辑  收藏  举报

导航