最近由于一个在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>");
}
}
搭好环境之后该方法复制调用即可运行。