hi, i tried to create new chart and add this Chart Chart1 = new Chart(); into my Cs file. Then I add the series and chartarea to create the chart dynamically, but strangely, when the codes is executed, no chart is shown. If I do not add that statement in and define Chart ID in Aspx file like this: ( <asp:Chart ID="Chart1" runat="server"> ) then try to create chart dynamically in Cs file, it works. But i want to create new chart every time and do not want to depend on defining Chart ID to produce chart dynamically.
This is my codes of when defining Chart ID in Aspx file to produce chart dynamically, chart can be produced:
(it works)
//Aspx file:
<asp:scriptmanager ID="ScriptManager1" runat="server">
</asp:scriptmanager>
</div>
<asp:updatepanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Chart ID="Chart1" runat="server">
</asp:Chart>
<asp:placeholder ID="PlaceHolder1" runat="server"></asp:placeholder>
</contenttemplate>
</asp:updatepanel>
//Cs file:
Chart1.DataSource = tg;
Chart1.Width = 600;
Chart1.Height = 350;
Chart1.Series.Add(new Series());
Chart1.Series[0].ChartType = SeriesChartType.BoxPlot;
List<object> lst = tg.AsEnumerable().ToList<object>();
foreach (DataRow row in tg.Rows)
Chart1.Series[0].Points.AddXY(row["Status"], new object[] { row["Min"], row["Max"], row["Avg"], row["Percentile25"], row["Percentile50"], row["Percentile75"] });
if(tg.Rows.Count>0)
{
string title = (tg.Rows[2]["Process"].ToString());
}
//create chartareas
ChartArea ca = new ChartArea();
ca.Name = "ChartArea1";
ca.AxisX = new Axis();
ca.AxisY = new Axis();
Chart1.ChartAreas.Add(ca);
//databind
Chart1.DataBind();
Chart1.Visible = true;
This is my codes when I tried to create new chart by adding in this: Chart Chart1 = new Chart() in Cs file and didn't define ChartID in Aspx file;
(does not work)
//Aspx file:
</div>
<asp:updatepanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Chart runat="server">
</asp:Chart>
</br>
<asp:placeholder ID="PlaceHolder1" runat="server"></asp:placeholder>
</contenttemplate>
</asp:updatepanel>
//Cs file:
Chart Chart1 = new Chart();
Chart1.DataSource = tg;
Chart1.Width = 600;
Chart1.Height = 350;
Chart1.Series.Add(new Series());
Chart1.Series[0].ChartType = SeriesChartType.BoxPlot;
List<object> lst = tg.AsEnumerable().ToList<object>();
foreach (DataRow row in tg.Rows)
Chart1.Series[0].Points.AddXY(row["Status"], new object[] { row["Min"], row["Max"], row["Avg"], row["Percentile25"], row["Percentile50"], row["Percentile75"] });
if(tg.Rows.Count>0)
{
string title = (tg.Rows[2]["Process"].ToString());
}
//create chartareas
ChartArea ca = new ChartArea();
ca.Name = "ChartArea1";
ca.AxisX = new Axis();
ca.AxisY = new Axis();
Chart1.ChartAreas.Add(ca);
//databind
Chart1.DataBind();
Chart1.Visible = true;
Question: How to add in this statement:
Chart Chart1 = new Chart(); into
Cs file to create
new chart every time during execution instead of depending on defining
Chart ID in Aspx file (<asp:Chart ID="Chart1" runat="server">) to create the chart dynamically?
I really need help on this. Appreciate if someone can help me on this, thanks a lot!!