我编程动态 生成的 Chart控件不能显示 Legend
stringconnstring="server=.;uid=sa;pwd=123;database=WebLog";using(SqlConnectionconn=ne...
string connstring = "server=.;uid=sa;pwd=123;database=WebLog";
using (SqlConnection conn = new SqlConnection(connstring))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select sc_status as Status ,COUNT(*) as Num from Backups group by sc_status";
Chart Chart1 = new Chart();
Chart1.Visible = true;
SqlDataReader reader = cmd.ExecuteReader();
this.Controls.Add(Chart1);
Chart1.BackColor = Color.Gray;
Chart1.BackSecondaryColor = Color.WhiteSmoke;
Chart1.BackGradientStyle = GradientStyle.DiagonalRight;
Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
Chart1.BorderlineColor = Color.Gray;
// format the chart area
ChartArea aaa = new ChartArea();
Series ss = new Series();
Chart1.ChartAreas.Add(aaa);
Chart1.ChartAreas[0].BackColor = Color.Wheat;
Chart1.Location = new Point(50, 30);
Chart1.Height = 426;
Chart1.Width = 576;
// add and format the title
Chart1.Titles.Add("响应情况");
Chart1.Series.Add(ss);
Chart1.Titles[0].Font = new Font("Utopia", 16);
Chart1.Series[0].Points.DataBindXY(reader, "Status", reader, "Num");
Chart1.Series[0].ChartType = SeriesChartType.Column;
Chart1.Series[0].IsValueShownAsLabel = true;
Chart1.Series[0].IsVisibleInLegend = true;
Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
Chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
Chart1.Series[0].IsXValueIndexed = true;
reader.Close();
} 展开
using (SqlConnection conn = new SqlConnection(connstring))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select sc_status as Status ,COUNT(*) as Num from Backups group by sc_status";
Chart Chart1 = new Chart();
Chart1.Visible = true;
SqlDataReader reader = cmd.ExecuteReader();
this.Controls.Add(Chart1);
Chart1.BackColor = Color.Gray;
Chart1.BackSecondaryColor = Color.WhiteSmoke;
Chart1.BackGradientStyle = GradientStyle.DiagonalRight;
Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
Chart1.BorderlineColor = Color.Gray;
// format the chart area
ChartArea aaa = new ChartArea();
Series ss = new Series();
Chart1.ChartAreas.Add(aaa);
Chart1.ChartAreas[0].BackColor = Color.Wheat;
Chart1.Location = new Point(50, 30);
Chart1.Height = 426;
Chart1.Width = 576;
// add and format the title
Chart1.Titles.Add("响应情况");
Chart1.Series.Add(ss);
Chart1.Titles[0].Font = new Font("Utopia", 16);
Chart1.Series[0].Points.DataBindXY(reader, "Status", reader, "Num");
Chart1.Series[0].ChartType = SeriesChartType.Column;
Chart1.Series[0].IsValueShownAsLabel = true;
Chart1.Series[0].IsVisibleInLegend = true;
Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
Chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
Chart1.Series[0].IsXValueIndexed = true;
reader.Close();
} 展开
2个回答
2012-03-26
展开全部
貌似是webform的? protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { if (ViewState["hasbt"] != null && (bool)ViewState["hasbt"] == true) { AddBT(); } } } protected void Button1_Click(object sender, EventArgs e) { AddBT(); } private void AddBT() { Button bt = new Button(); bt.Text = "测试"; bt.ID = "bt"; bt.Click += new EventHandler(bt_Click); Panel1.Controls.Add(bt); this.ViewState["hasbt"] = true; } void bt_Click(object sender, EventArgs e) { Response.Write("<scritp>alert('成功了');</script>"); }
~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询