OWC11 实例(经典文章值得一读)

项目中的工程模块需要用到图表来显示数据,后来选中了“OWC11”,效果如下:



CS代码:
void ToPrint( string categoryStr, 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;//图例的字体




//X,Y轴的图示属性
//objChart.Axes[0].HasTitle=true;
//objChart.Axes[0].Title.Caption="X:月";
//objChart.Axes[0].Title.Font.Size=9;
//objChart.Axes[1].HasTitle=true;
//objChart.Axes[1].Title.Caption="Y:量";
//objChart.Axes[1].Title.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
=false;//柱子上面的数字是否显示
objDataLabels.Font.Color="Black";//柱子上面的数字颜色是黑色的
}


objectobjPic=objCSpace.GetPicture("GIF",700,300);

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



调用:

string []categoryArr = new string [] {"1月份","2月份","3月份","4月份","5月份","6月份"} ;
string categoryStr = string .Join( " /t " ,categoryArr);

string []valueArr1 = new string [] {"3832","3167","3575","3816","2651","3494"} ;
string []valueArr2 = new string [] {"17627.2","14568.2","12194.6","16445","17553.6","16072.4"} ;
string []valueArr3 = new string [] {"5748","4750.5","3976.5","5362.5","5724","5241"} ;
string []valueArr4 = new string [] {"23375.2","19318.7","16171.1","21807.5","23277.6","21313.4"} ;
string valueStr1 = string .Join( " /t " ,valueArr1);
string valueStr2 = string .Join( " /t " ,valueArr2);
string valueStr3 = string .Join( " /t " ,valueArr3);
string valueStr4 = string .Join( " /t " ,valueArr4);
string []valueArr = new string [] {valueStr1,valueStr2,valueStr3,valueStr4} ;

string []titleArr = new string [] {"消耗量m3","水费(元)","污水费(元)","合计(元)"} ;

string []colorArr = new string [] {"#9999FF","#993366","#FFFFCC","#CCFFFF"} ;

ToPrint(categoryStr,valueArr,titleArr,colorArr);
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、付费专栏及课程。

余额充值