原先将比如保护两字段“日期、金额”的RecordSet绑定(Series.SetData的参数用chDataBound)到OWC9,“日期”为分类,“金额”为值,系列名称随便chDataLiteral一个如“收入”,就绘制了一条收入曲线。当改到OWC10/11后,发现Series.SetData方法不好用了,需改成Chart.SetData,我晕。
这个晕一下没关系,更晕的是这种情况在Chart图的右侧多出了一个“将系列字段拖至此处”的灰色提示,查找了相关属性、方法,似乎都没有去掉的可能。ChartSpace顶上也多出一个“将过滤字段拖至此处”的灰色提示条,也去不掉。注:系列字段若也绑定上,是会去掉的,比如绑定到字段“A”,将显示成粗体的“A”做过的高人肯定知道,望不啬赐教,多谢!
这个晕一下没关系,更晕的是这种情况在Chart图的右侧多出了一个“将系列字段拖至此处”的灰色提示,查找了相关属性、方法,似乎都没有去掉的可能。ChartSpace顶上也多出一个“将过滤字段拖至此处”的灰色提示条,也去不掉。注:系列字段若也绑定上,是会去掉的,比如绑定到字段“A”,将显示成粗体的“A”做过的高人肯定知道,望不啬赐教,多谢!
{
// 在此处放置用户代码以初始化页面
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);
}
}