2003 .net owc11简单用法!

View Code
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 OWCTable;

namespace OWCTable
{
/**//// <summary>
/// Show 的摘要说明。
/// </summary>
public class Show : System.Web.UI.Page
{

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

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

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public void ShowChart()
  {
string[] chartCategories = {"3","4","5","6","7","8","9"};
string[] chartValues = {"4","5","8","2","5","9","8"};
ChartFactory chartfactory
= new ChartFactory();
string chartType = "弧线统计图";

  
//初始化赋值
  chartfactory.chartCategoriesArrValue =chartCategories;
    chartfactory.chartValuesArrValue
= chartValues;
//  chartfactory.chartTitleValue = chartTitle;
  chartfactory.chartTypeValue = chartType;

  OWC11.ChartSpaceClass oChartSpace
= chartfactory.BuildCharts();

oChartSpace.ExportPicture(Server.MapPath(
"chart.gif"),"gif",600,350);
Response.Write(
"<IMG SRC='" + Server.MapPath("chart.gif") + "'/>");
//  Image1.ImageUrl = path; // 显示统计图
  }

}
}

View Code
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;
namespace OWCChart
{
/**//// <summary>
/// ChartFactory 的摘要说明。
/// </summary>
public class ChartFactory
  {
  
public ChartFactory()
  {
  InitTypeMap();
  
//
  
// TODO: 在此处添加构造函数逻辑
  
//
  }
  
protected System.Web.UI.WebControls.Image imgHondaLineup;
  
private string[] chartCategoriesArr;
  
private string[] chartValuesArr;
  
private OWC11.ChartChartTypeEnum chartType = OWC11.ChartChartTypeEnum.chChartTypeColumnClustered;//默认值
  private static Hashtable chartMap = new Hashtable();
  
private static string chartTypeCh = "垂直柱状统计图" ;
  
private static string chartTitle = "";

  
private void InitTypeMap()
  {
  chartMap.Clear();
  OWC11.ChartChartTypeEnum[] chartTypes
= new OWC11.ChartChartTypeEnum[]{
ChartChartTypeEnum.chChartTypeColumnClustered,
//垂直柱状统计图
  ChartChartTypeEnum.chChartTypeColumn3D, //3D垂直柱状统计图
  ChartChartTypeEnum.chChartTypeBarClustered, //水平柱状统计图
  ChartChartTypeEnum.chChartTypeBar3D, //3D水平柱状统计图
  ChartChartTypeEnum.chChartTypeArea, //"区域统计图 //折线面积图
  ChartChartTypeEnum.chChartTypeArea3D, //3D区域统计图
  ChartChartTypeEnum.chChartTypeDoughnut, //中空饼图
  ChartChartTypeEnum.chChartTypeLineStacked, //折线统计图
  ChartChartTypeEnum.chChartTypeLine3D, //3D折线统计图
  ChartChartTypeEnum.chChartTypeLineMarkers, //折线带点统计图
  ChartChartTypeEnum.chChartTypePie, //饼图
  ChartChartTypeEnum.chChartTypePie3D, //3D饼图
  ChartChartTypeEnum.chChartTypeRadarSmoothLine,//网状统计图
  ChartChartTypeEnum.chChartTypeSmoothLine}; //弧线统计图


  
string[] chartTypesCh = new string [] {"垂直柱状统计图","3D垂直柱状统计图","水平柱状统计图","3D水平柱状统计图","区域统计图","3D区域统计图","中空饼图","折线统计图","3D折线统计图","折线带点统计图","饼图","3D饼图","网状统计图","弧线统计图"};



  
for(int i=0;i<chartTypes.Length;i++) //向chartMap添加图表类型
   {
   cchartMap.Add(chartTypesCh[i],chartTypes[i]);
   }

  }

  
public ChartSpaceClass BuildCharts ()
  {
  
string chartCategoriesStr = String.Join(" ", chartCategoriesArr);
  
string chartValuesStr = String.Join (" ", chartValuesArr);

//  OWC11.ChartSpaceClass oChartSpace = new OWC11.ChartSpaceClass ();

OWC11.ChartSpaceClass oChartSpace
= new ChartSpaceClass();

  
// ————————————————————————
  
// Give pie and doughnut charts a legend on the bottom. For the rest of
  
// them let the control figure it out on its own.
  
// ————————————————————————

  chartType
= (ChartChartTypeEnum)chartMap[chartTypeCh]; //要选择的图形的类型



  
if (chartType == ChartChartTypeEnum.chChartTypePie || chartType == ChartChartTypeEnum.chChartTypePie3D ||
   chartType
== ChartChartTypeEnum.chChartTypeDoughnut)
  {
   oChartSpace.HasChartSpaceLegend
= true;
  oChartSpace.ChartSpaceLegend.Position
= ChartLegendPositionEnum.chLegendPositionBottom;
  }

  oChartSpace.Border.Color
= "blue";
  oChartSpace.Charts.Add(
0);
  oChartSpace.Charts[
0].HasTitle = true;
  oChartSpace.Charts[
0].Type = chartType;
  oChartSpace.Charts[
0].ChartDepth = 125;
  oChartSpace.Charts[
0].AspectRatio = 80;
  oChartSpace.Charts[
0].Title.Caption = chartTitle;
  oChartSpace.Charts[
0].Title.Font.Bold = true;
oChartSpace.Charts[
0].Title.Caption = "统计表";

oChartSpace.Charts[
0].Axes[0].HasTitle = true;
oChartSpace.Charts[
0].Axes[1].HasTitle = true;
oChartSpace.Charts[
0].Axes[0].Title.Caption = "月份";
oChartSpace.Charts[
0].Axes[1].Title.Caption = "数量";

  oChartSpace.Charts[
0].SeriesCollection.Add(0);
  oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection.Add ();

  
// ————————————————————————
  
// If you’re charting a pie or a variation thereof percentages make a lot
  
// more sense than values…
  
// ————————————————————————




  
if (chartType == ChartChartTypeEnum.chChartTypePie ||
    chartType
== ChartChartTypeEnum.chChartTypePie3D ||
    chartType
== ChartChartTypeEnum.chChartTypeDoughnut)
  {
    oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
    oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
  }
  
// ————————————————————————
  
// Not so for other chart types where values have more meaning than
  
// percentages.
  
// ————————————————————————
  else
  {
   oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = false;
   oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].HasValue = true;
  }
  
  
// ————————————————————————
  
// Plug your own visual bells and whistles here
  
// ————————————————————————
  oChartSpace.Charts[0].SeriesCollection[0].Caption = String.Empty;
  oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].Font.Name = "verdana";
  oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].Font.Size = 10;
  oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].Font.Bold = true;
  oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].Font.Color = "red";
  oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionCenter;
  
  
if (chartType == ChartChartTypeEnum.chChartTypeBarClustered ||
  chartType
== ChartChartTypeEnum.chChartTypeBar3D ||
  chartType
== ChartChartTypeEnum.chChartTypeColumnClustered ||
  chartType
== ChartChartTypeEnum.chChartTypeColumn3D)
  {
    oChartSpace.Charts[
0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;
  }
  
  oChartSpace.Charts[
0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimCategories,
  Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartCategoriesStr);



  oChartSpace.Charts[
0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimValues,
  Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartValuesStr);



  
return oChartSpace;

  }


  属性设置
#region 属性设置
  
public string[] chartCategoriesArrValue
  {
  
get
  {
  
return chartCategoriesArr;
  }
  
set
  {
  chartCategoriesArr
= value;
  }
  }

  
public string[] chartValuesArrValue
  {
  
get
  {
  
return chartValuesArr;
  }
  
set
  {
  chartValuesArr
= value;
  }
  }

  
public string chartTypeValue
  {
  
get
  {
  
return chartTypeCh;
  }
  
set
  {
  chartTypeCh
= value;
  }
  }
  
public string chartTitleValue
  {
  
get
  {
  
return chartTitle;
  }
  
set
  {
   chartTitle
= value;
  }
  }

  
#endregion
  }

}

http://blog.csdn.net/pkkfaii/article/details/1384276

你可能感兴趣的:(.net)