查询一句SQL语句,返回值怎么样和OWC的图表绑定?有没有实例?
解决方案 »
- asp.net自动播放动画效果?
- 如何修改“DataBinding:“System.Data.DataRowView”不包含名为“TypeID”的属性”的错误?
- asp.net fals问题,向大侠求救
- 如何在网站上显示指定新浪微博列表的更新?
- asp.net(C#)开发的网站,在winServer2008 IIS上发布后其中的发送邮件功能失效,怎么解决?
- asp.net站点上,是如何实现现场直播?
- 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败
- 如何在datagrid控件中加入下拉列表框
- 关于连接access路径问题
- 郁闷呀,Timer不执行指定代码。。。
- //-------------------------------------------XML显示的问题
- asp.net 2.0当中还有WebUIValidation.js吗?
{
// 在此处放置用户代码以初始化页面
string strCategory = null;
string strValue = null;
using (SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString()))
{
try
{
DataTable dt = SqlHelper.ExecuteDataset(cn,CommandType.Text,"select top 1 * from un_tbl_VoteQuestion where isopen=1").Tables[0];
if (dt.Rows.Count>0)
{
lbltitle.Text = dt.Rows[0]["QuestionTitle"].ToString();
dt = SqlHelper.ExecuteDataset(cn,CommandType.Text,"select * from un_tbl_VoteItem where questionid ="+dt.Rows[0]["questionid"].ToString()).Tables[0];
if (!Page.IsPostBack)
{
rbl.DataTextField = "ItemTitle";
rbl.DataValueField = "ItemId";
rbl.DataSource = dt.DefaultView;
rbl.DataBind();
}
foreach(DataRow dr in dt.Rows)
{
strCategory += dr["ItemTitle"].ToString()+'\t';
strValue += dr["ItemCount"].ToString()+'\t';
}
if (strCategory.Length>0)
{
strCategory = strCategory.Substring(0,strCategory.Length-1);
strValue = strValue.Substring(0,strValue.Length-1);
}
}
dt.Dispose();
}
catch(Exception ex)
{
cn.Close();
throw new Exception(ex.Message);
}
}
//声明对象
OWC11.ChartSpace ThisChart = new OWC11.ChartSpaceClass();
OWC11.ChChart ThisChChart = ThisChart.Charts.Add(0);
OWC11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0); //饼图百分比
ThisChChart.SeriesCollection[0].DataLabelsCollection.Add();
ThisChChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
ThisChChart.SeriesCollection[0].DataLabelsCollection[0].HasCategoryName = false;
ThisChChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
ThisChChart.SeriesCollection[0].DataLabelsCollection[0].Interior.Color = "white";
ThisChChart.SeriesCollection[0].DataLabelsCollection[0].Font.Name = "Verdana";
//显示图例
ThisChChart.HasLegend = true;
//标题
// ThisChChart.HasTitle = true;
// ThisChChart.Title.Caption = "统计图";
//
// //给定x,y轴图示说明
// ThisChChart.Axes[0].HasTitle = true;
// ThisChChart.Axes[1].HasTitle = true;
// ThisChChart.Axes[0].Title.Caption = "选项";
// ThisChChart.Axes[1].Title.Caption = "数量";
// ThisChChart.Axes[1].NumberFormat="0.0%"; //图表类型
ThisChChart.Type = OWC11.ChartChartTypeEnum.chChartTypePieExploded3D;//.chChartTypePie3D;//chChartTypeColumnClustered3D;
//旋转
ThisChChart.Rotation = 360;
ThisChChart.Inclination = 10;
//背景颜色
ThisChChart.PlotArea.Interior.Color = "red";
//底色
ThisChChart.PlotArea.Floor.Interior.Color = "green"; //ThisChChart.Overlap = 50; //给定series的名字
ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames,OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),"统计");
//给定分类
ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimCategories,OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
//给定值
ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimValues,OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);
//导出图像文件
try
{
DirectoryInfo di = new DirectoryInfo(Server.MapPath("tempimages"));
if (!di.Exists)
di.Create();
if (File.Exists(Server.MapPath("tempimages/"+filename+".gif")))
File.Delete(Server.MapPath("tempimages/"+filename+".gif"));
filename = Guid.NewGuid().ToString();
ThisChart.ExportPicture(Server.MapPath("tempimages/"+filename+".gif"),"gif",270,180);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
Microsoft.Office.Interop.Owc11.SpreadsheetClass oExcelSheet = new Microsoft.Office.Interop.Owc11.SpreadsheetClass();
string filepaht = "d:\test.xls";
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)//点buttion1按钮是写数据
{
oExcelSheet.ActiveSheet.Cells[2, 2] = "test";
oExcelSheet.Export(filepaht, Microsoft.Office.Interop.Owc11.SheetExportActionEnum.ssExportActionNone, Microsoft.Office.Interop.Owc11.SheetExportFormat.ssExportXMLSpreadsheet); }
}我已经在项目中引用了owc1.dll,但每次,点按钮都出现异常{"异常来自 HRESULT:0xE004002A"}
饭碗尤关,恳请高手协助,万分感激!
foreach(DataRow dr in dt.Rows)
{
strCategory += dr["ItemTitle"].ToString()+'\t';
strValue += dr["ItemCount"].ToString()+'\t';
}
也可以定义数组来实现