我要用ASP.NET(C#)调用OWC组件创建动态图表,但不知用哪个类?

zxn1979125 2003-03-23 10:15:09
我要用ASP.NET(C#)调用OWC组件创建动态图表,但不知用哪个类?

有的说用OWC.ChartSpace
有的说用OWC.Chart
到底是哪个
.NET里面OWC.ChartSpace只是个接口,OWC.Chart根本就不存在啊,怎么回事?
在线等待,马上给分!
...全文
46 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
online 2003-03-24
  • 打赏
  • 举报
回复
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 System.IO;
using System.Data.SqlClient;
using OWC10;
using System.Xml;



namespace OWCChart
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnChart;
protected System.Web.UI.WebControls.Image Image1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnChart.Click += new System.EventHandler(this.btnChart_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnChart_Click(object sender, System.EventArgs e)
{
SqlConnection cn =
new SqlConnection("Server=(local);DataBase=Northwind;user id=sa;password=;");

cn.Open();
DataSet ds = new DataSet("Chart");
SqlDataAdapter da = new SqlDataAdapter("CustorderHist 'ALFKI'", cn);
da.Fill(ds);
OWC10.ChartSpaceClass oChartSpace = new OWC10.ChartSpaceClass();
System.IO.StringWriter sw = new System.IO.StringWriter();
XmlDocument xDoc = new XmlDocument();
ds.WriteXml(sw);
// clean up
cn.Close();
da.Dispose();
ds.Dispose();
xDoc.LoadXml(sw.ToString());
sw.Close();
System.Xml.XmlNodeList nodes;
nodes = xDoc.ChildNodes.Item(0).ChildNodes;
int nCount = nodes.Count;
string[] aNames = new string[nCount];
string[] aTotals = new string[nCount];
string names=String.Empty;
string totals =String.Empty;
int i = 0;
for(i=1;i<nCount;i++)
{
aNames[i]= nodes.Item(i-1).ChildNodes.Item(0).InnerText;
aTotals[i]= nodes.Item(i-1).ChildNodes.Item(1).InnerText;
}

names= String.Join("\t", aNames); //Chart control accepts tab-delimited string of values
totals= String.Join("\t", aTotals);
oChartSpace.Charts.Add(0);
oChartSpace.Charts[0].SeriesCollection.Add(0);
oChartSpace.Charts[0].SeriesCollection[0].SetData(OWC10.ChartDimensionsEnum.chDimCategories,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),names );
oChartSpace.Charts[0].SeriesCollection[0].SetData(OWC10.ChartDimensionsEnum.chDimValues,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),totals );
string strFullPathAndName=Server.MapPath(System.DateTime.Now.Ticks.ToString() +".gif");
oChartSpace.ExportPicture( strFullPathAndName, "gif", 800, 600);
Image1.ImageUrl=strFullPathAndName;
Image1.Visible =true;
RemoveFiles(Server.MapPath("."));
}


private void RemoveFiles(string strPath)
{
System.IO.DirectoryInfo di = new DirectoryInfo(strPath);
FileInfo[] fiArr = di.GetFiles();
foreach (FileInfo fi in fiArr)
{
if(fi.Extension.ToString() ==".gif" )
{
// if file is older than 2 minutes, we'll clean it up
TimeSpan min = new TimeSpan(0,0,0,2,0);
if(fi.CreationTime < DateTime.Now.Subtract(min))
{
fi.Delete();
}
}
}


}

}

}
supnet 2003-03-24
  • 打赏
  • 举报
回复
转贴:
没有用OWC,直接用Excel.DLL
给一段代码你看看

Excel.Sheets sheets =book.Worksheets;
Excel._Worksheet worksheet =(Excel._Worksheet)sheets.get_Item(1);

Excel.Range range;
range =worksheet.get_Range(worksheet.Cells[1,1],worksheet.Cells[1,14]);
range.MergeCells =true;//合并
range.HorizontalAlignment =Excel.XlHAlign.xlHAlignCenter;//居中
range.Font.Bold =true;
range.Font.Size =14;

//画线
Excel.Range range1;
range1 =worksheet.get_Range(worksheet.Cells[2,1],worksheet.Cells[rowIndex,colIndex]);
range1.Borders[Excel.XlBordersIndex.xlDiagonalDown].LineStyle =Excel.XlLineStyle.xlLineStyleNone;
range1.Borders[Excel.XlBordersIndex.xlDiagonalUp].LineStyle =Excel.XlLineStyle.xlLineStyleNone;
range1.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle =Excel.XlLineStyle.xlContinuous;
range1.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle =Excel.XlLineStyle.xlContinuous;
range1.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle =Excel.XlLineStyle.xlContinuous;
range1.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle =Excel.XlLineStyle.xlContinuous;
range1.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle =Excel.XlLineStyle.xlContinuous;
range1.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle =Excel.XlLineStyle.xlContinuous;

//拉宽表格
Excel.Range range2;
range2 =worksheet.get_Range(worksheet.Cells[1,1],worksheet.Cells[1,1]);
range2.ColumnWidth =25.8;

zxn1979125 2003-03-24
  • 打赏
  • 举报
回复
不是很明白
……
smiletosky 2003-03-23
  • 打赏
  • 举报
回复
你用全文搜索,我用的是mschart,我做的时候,见过这样的好象

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧