最近由於一個在VS2003基礎上開發的案例,涉及到了OWC的操作,經過在網上的深入淺出,終於提煉出對報表操作的方法,具體方法如下:(如有不足還請各大高手指教)
private void map()
{
try
{
string[] strArrValue ;
strArrValue = new string[4];string[] strArrLegCHL ;
strArrLegCHL = new string[4];
for(int i=0;i<XXX.GetLength(0);i++)
{
strArrValue[0] += XXX[i].ToString() + '\t';
strArrValue[1] += XXX[i].ToString() + '\t';
strArrValue[2] += XXX[i].ToString() + '\t';
strArrValue[3] += XXX[i].ToString() + '\t';
}
strArrLegCHL[1] = "XXX";
strArrLegCHL[2] = "XXX";
strArrLegCHL[3] = "XXX";
ChartSpace owcChartSpace = new ChartSpace();//創建ChartSpace對象來放置圖表
ChChart chart = owcChartSpace.Charts.Add(0);//在ChartSpace對象中添加圖表,Add方法返回chart對象
chart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;//指定圖表的類型。
//指定圖表是否需要圖例
chart.HasLegend = true;
//標題
chart.HasTitle = true;
chart.Title.Caption = "統計柱形圖";
//x,y軸的圖示說明
chart.Axes[0].HasTitle = true;
chart.Axes[0].Title.Caption = "X:" + "XXX";
chart.Axes[1].HasTitle = true;chart.Axes[1].Title.Caption = "Y:" + "YYY";
for(int a = 0;a<strArrValue.Length-1;a++)
{
chart.SeriesCollection.Add(a); //添加一個series//給定series的名字
chart.SeriesCollection[a].SetData(ChartDimensionsEnum.chDimSeriesNames,+
(int)ChartSpecialDataSourcesEnum.chDataLiteral, strArrLegCHL[a+1]);
//給定分類chart.SeriesCollection[a].SetData(ChartDimensionsEnum.chDimCategories,+
(int)ChartSpecialDataSourcesEnum.chDataLiteral,strArrValue[0]);
//給定值chart.SeriesCollection[a].SetData(ChartDimensionsEnum.chDimValues,+(int)ChartSpecialDataSourcesEnum.chDataLiteral, strArrValue[a+1]);
} string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif";
string strAbsolutePath = (Server.MapPath(".")) + @"\image\"+ filename + "_" +".gif";
owcChartSpace.ExportPicture(strAbsolutePath, "GIF",1000 ,240); //輸出圖表 /
/創建GIF文件的相對路徑
string strRelativePath = "image/"+ filename + "_" +".gif";
//把圖片添加到Image imgChart.ImageUrl = strRelativePath+ "?tmp=" + DateTime.Now.ToLongTimeString();
}
catch(OracleException)
{
Page.RegisterStartupScript("","<script> alert('訪問數據庫時發生了異常!')</script>");
}
catch(Exception)
{
Page.RegisterStartupScript("","<script> alert('執行時發生異常,操作失敗。')</script>");
}
}
搭好環境之後該方法複製調用即可運行。