使用owc11制作图表又一实例

本文介绍了一种通过ASP.NET Web应用程序生成员工职称分析图表的方法。该应用从数据库获取部门及职称数据,动态创建柱状图,并将其输出为GIF文件。文章详细展示了如何设置图表属性、填充数据以及导出图表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


/**////<copyright>英网资讯技术有限公司1999-2007</copyright>
///<version>1.0</version>
///<author>zhangl</author>
///<email>zhangl@hrbanlv.com</email>
///<logdate="2007-07-20">创建</log>
///


usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingData;
usingSQL;
usingBusiness;
usingMicrosoft.Office.Interop.Owc11;
usingSystem.IO;
usingEHR.Base;

publicpartialclassReport_Chart_zhutu_ChartPost:BasePage
...{
protectedDataTabledt;
protectedDataTableDeptTable;
protectedDepartDTdetail=newDepartDT();
protectedDataSetds;

protectedvoidPage_Load(objectsender,EventArgse)
...{
Initial();
}


初始化数据#region初始化数据
privatevoidInitial()
...{

if(this.Request.QueryString["deptno"]!=null)
...{
detail.DeptNo
=this.Request.QueryString["deptno"].ToString();//部门no参数
}

else
...{
detail.DeptNo
="";
}

if(this.Request.QueryString["deptname"]!=null)
...{
detail.depname
=this.Request.QueryString["deptname"].ToString();//部门名称参数
}

else
...{
detail.depname
="";
}


using(ChartBNbn=newChartBN())
...{
ds
=bn.GetChartPost(detail);
dt
=ds.Tables[0];
bn.Dispose();
DeptTable
=ds.Tables[1];

}


将表中一列数据填充到数组--动态得到横坐标的文字#region 将表中一列数据填充到数组--动态得到横坐标的文字
string[]column=newstring[DeptTable.Rows.Count];
for(inti=0;i<DeptTable.Rows.Count;i++)
...{
column[i]
=DeptTable.Rows[i]["postname"].ToString();
}

#endregion


string[]categoryArr=column;
stringcategoryStr=string.Join(" ",categoryArr);
stringvalueStr="";

动态得到对应横坐标上的纵坐标上的文字#region动态得到对应横坐标上的纵坐标上的文字

string[]column1=newstring[DeptTable.Rows.Count];
stringvalue;
for(intm=0;m<DeptTable.Rows.Count;m++)
...{
value
=dt.Rows[dt.Rows.Count-1][m+1].ToString()==""?"0":dt.Rows[dt.Rows.Count-1][m+1].ToString();
column1[m]
=value;
}

string[]valueArrs=column1;
#endregion



valueStr
=string.Join(" ",valueArrs);

string[]valueArr=newstring[]...{valueStr};
stringtitle=this.Request.QueryString["deptname"]==null?"全体员工":this.Request.QueryString["deptname"].ToString();//得到图表右边的名称

string[]titleArr=newstring[]...{title};

string[]colorArr=newstring[]...{"#9999FF"};

ToPrint(categoryStr,valueArr,titleArr,colorArr);
}

#endregion


ToPrint方法#regionToPrint方法
privatevoidToPrint(stringcategoryStr,string[]valueArr,string[]titleArr,string[]colorArr)
...{
//新建一个绘图空间
ChartSpaceobjCSpace=newChartSpace();


//在绘图空间中新建一个图表
ChChartobjChart=objCSpace.Charts.Add(0);
//objChart.Type=ChartChartTypeEnum.chChartTypeColumnClustered3D;//指定图表的类型为3D柱状
objChart.Type=ChartChartTypeEnum.chChartTypeColumnClustered;//平面柱状
objChart.HasLegend=true;//指定图表是否需要图例

//标题
objChart.HasTitle=true;
objChart.Title.Caption
="员工职称分析图表";//得到部门名称
objChart.Title.Font.Size=9;
objChart.Title.Font.Name
="宋体";
objChart.Title.Font.Bold
=true;

objChart.PlotArea.Interior.Color
="#C0C0C0";//绘图区的背景颜色
objChart.PlotArea.Floor.Interior.Color="#888888";//绘图区的底色

objChart.Legend.Font.Size
=9;//图例的字体

for(inti=0;i<valueArr.Length;i++)
...{
//在图表中添加一个数据系列
ChSeriesobjSeries=objChart.SeriesCollection.Add(i);
objSeries.SetData(ChartDimensionsEnum.chDimSeriesNames,ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),titleArr[i]);
objSeries.SetData(ChartDimensionsEnum.chDimCategories,ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),categoryStr);
objSeries.SetData(ChartDimensionsEnum.chDimValues,ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),valueArr[i]);
objSeries.Interior.Color
=colorArr[i];//柱子内部的颜色
objSeries.GapWidth=300;//柱子之间的间隙

ChDataLabelsobjDataLabels
=objChart.SeriesCollection[i].DataLabelsCollection.Add();
objDataLabels.HasValue
=true;//柱子上面的数字是否显示
objDataLabels.Font.Color="Red";//柱子上面的数字颜色是黑色的
}


stringfilename="zhicheng.gif";
stringstrAbsolutePath=HttpContext.Current.Server.MapPath(".")+"/chartimg";
if(!Directory.Exists(strAbsolutePath))
...{
Directory.CreateDirectory(strAbsolutePath);
}

strAbsolutePath
=HttpContext.Current.Server.MapPath(".")+"/chartimg"+"/"+filename;
objCSpace.ExportPicture(strAbsolutePath,
"GIF",700,300);//输出成GIF文件.
this.Image1.ImageUrl="chartimg/"+filename;

喷出图片#region喷出图片
//objectobjPic=objCSpace.GetPicture("GIF",700,300);

//Response.Buffer=true;
//Response.ContentType="image/gif";
//Response.BinaryWrite((byte[])objPic);
//Response.End();
#endregion

}


#endregion

}

Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154. 收藏 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [COMException (0x80040154): Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154.] GraphPage.Page_Load(Object sender, EventArgs e) +1097 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 请大家帮忙 谢谢 Server Error in '/' Application. -------------------------------------------------------------------------------- Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值