Hi ,
I am trying to display line chart dynamically and get displayed in my panel. I don't understand what I am doing wrong. Please help.
I have this in my .aspx file
<asp:Panel ID="Panel3" runat="server" style="float:left;width:45%;">
<telerik:RadHtmlChart ID="RadHtmlChart3" runat="server" ChartTitle-Text="Dynamic Line Series">
</telerik:RadHtmlChart>
</asp:Panel>
and the following code in aspx.cs file
if (DropDownList1.SelectedValue == "Line")
{
SqlConnection sqlConn3 = new SqlConnection(ConfigurationManager.ConnectionStrings["xxxx"].ConnectionString);
SqlCommand SqlCmd3 = new SqlCommand("Select ST as state, count(*) as no_of_cust FROM CUSTOMER group by ST", sqlConn3);
SqlCmd3.Connection.Open();
SqlDataReader reader3 = SqlCmd3.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("State_col");
dt.Columns.Add("No_Customers");
if (reader3.HasRows)
{
while (reader3.Read())
{
dt.Rows.Add(reader3.GetValue(0).ToString(), reader3.GetInt32(1));
}
}
var columns = new List<string>();
for (int i = 0; i < reader3.FieldCount; i++)
{
columns.Add(reader3.GetName(i));
}
RadHtmlChart3.ChartTitle.Text = "My dynamic Line Chart";
RadHtmlChart3.ChartTitle.Appearance.Align = Telerik.Web.UI.HtmlChart.ChartTitleAlign.Center;
RadHtmlChart3.ChartTitle.Appearance.Position = Telerik.Web.UI.HtmlChart.ChartTitlePosition.Top;
RadHtmlChart3.Legend.Appearance.BackgroundColor = System.Drawing.Color.White;
RadHtmlChart3.Legend.Appearance.Position = Telerik.Web.UI.HtmlChart.ChartLegendPosition.Bottom;
RadHtmlChart3.PlotArea.Appearance.FillStyle.BackgroundColor = System.Drawing.Color.White;
// RadHtmlChart3.PlotArea.XAxis.Color = System.Drawing.Color.Azure;
RadHtmlChart3.PlotArea.XAxis.MajorTickType = Telerik.Web.UI.HtmlChart.TickType.Outside;
RadHtmlChart3.PlotArea.XAxis.MinorTickType = Telerik.Web.UI.HtmlChart.TickType.Outside;
RadHtmlChart3.PlotArea.XAxis.Reversed = false;
RadHtmlChart3.PlotArea.XAxis.DataLabelsField = columns[0];
RadHtmlChart3.Appearance.FillStyle.BackgroundColor = System.Drawing.Color.White;
RadHtmlChart3.PlotArea.YAxis.LabelsAppearance.DataFormatString = "{0}";
RadHtmlChart3.PlotArea.YAxis.LabelsAppearance.RotationAngle = 0;
RadHtmlChart3.PlotArea.YAxis.LabelsAppearance.Color = System.Drawing.ColorTranslator.FromHtml("#000000");
RadHtmlChart3.PlotArea.YAxis.MajorGridLines.Color = System.Drawing.ColorTranslator.FromHtml("#EFEFEF");
RadHtmlChart3.PlotArea.YAxis.MinorGridLines.Color = System.Drawing.ColorTranslator.FromHtml("#F7F7F7");
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.Position = Telerik.Web.UI.HtmlChart.AxisTitlePosition.Center;
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.RotationAngle = 0;
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.Text = columns[1];
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.TextStyle.Color = System.Drawing.ColorTranslator.FromHtml("#000000");
RadHtmlChart3.PlotArea.XAxis.TitleAppearance.Text = columns[0];
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.Text = columns[1];
ScatterLineSeries slineSeries = new ScatterLineSeries();
slineSeries.LabelsAppearance.Visible = false;
slineSeries.LabelsAppearance.Position = Telerik.Web.UI.HtmlChart.LineAndScatterLabelsPosition.Below;
slineSeries.LabelsAppearance.DataFormatString = "{0}%";
slineSeries.TooltipsAppearance.DataFormatString = "{0}%";
slineSeries.DataFieldX = columns[0];
slineSeries.DataFieldY = columns[1];
RadHtmlChart3.PlotArea.Series.Add(slineSeries);
RadHtmlChart3.DataSource = reader3;
RadHtmlChart3.DataBind();
}
}
Thank you
I am trying to display line chart dynamically and get displayed in my panel. I don't understand what I am doing wrong. Please help.
I have this in my .aspx file
<asp:Panel ID="Panel3" runat="server" style="float:left;width:45%;">
<telerik:RadHtmlChart ID="RadHtmlChart3" runat="server" ChartTitle-Text="Dynamic Line Series">
</telerik:RadHtmlChart>
</asp:Panel>
and the following code in aspx.cs file
if (DropDownList1.SelectedValue == "Line")
{
SqlConnection sqlConn3 = new SqlConnection(ConfigurationManager.ConnectionStrings["xxxx"].ConnectionString);
SqlCommand SqlCmd3 = new SqlCommand("Select ST as state, count(*) as no_of_cust FROM CUSTOMER group by ST", sqlConn3);
SqlCmd3.Connection.Open();
SqlDataReader reader3 = SqlCmd3.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("State_col");
dt.Columns.Add("No_Customers");
if (reader3.HasRows)
{
while (reader3.Read())
{
dt.Rows.Add(reader3.GetValue(0).ToString(), reader3.GetInt32(1));
}
}
var columns = new List<string>();
for (int i = 0; i < reader3.FieldCount; i++)
{
columns.Add(reader3.GetName(i));
}
RadHtmlChart3.ChartTitle.Text = "My dynamic Line Chart";
RadHtmlChart3.ChartTitle.Appearance.Align = Telerik.Web.UI.HtmlChart.ChartTitleAlign.Center;
RadHtmlChart3.ChartTitle.Appearance.Position = Telerik.Web.UI.HtmlChart.ChartTitlePosition.Top;
RadHtmlChart3.Legend.Appearance.BackgroundColor = System.Drawing.Color.White;
RadHtmlChart3.Legend.Appearance.Position = Telerik.Web.UI.HtmlChart.ChartLegendPosition.Bottom;
RadHtmlChart3.PlotArea.Appearance.FillStyle.BackgroundColor = System.Drawing.Color.White;
// RadHtmlChart3.PlotArea.XAxis.Color = System.Drawing.Color.Azure;
RadHtmlChart3.PlotArea.XAxis.MajorTickType = Telerik.Web.UI.HtmlChart.TickType.Outside;
RadHtmlChart3.PlotArea.XAxis.MinorTickType = Telerik.Web.UI.HtmlChart.TickType.Outside;
RadHtmlChart3.PlotArea.XAxis.Reversed = false;
RadHtmlChart3.PlotArea.XAxis.DataLabelsField = columns[0];
RadHtmlChart3.Appearance.FillStyle.BackgroundColor = System.Drawing.Color.White;
RadHtmlChart3.PlotArea.YAxis.LabelsAppearance.DataFormatString = "{0}";
RadHtmlChart3.PlotArea.YAxis.LabelsAppearance.RotationAngle = 0;
RadHtmlChart3.PlotArea.YAxis.LabelsAppearance.Color = System.Drawing.ColorTranslator.FromHtml("#000000");
RadHtmlChart3.PlotArea.YAxis.MajorGridLines.Color = System.Drawing.ColorTranslator.FromHtml("#EFEFEF");
RadHtmlChart3.PlotArea.YAxis.MinorGridLines.Color = System.Drawing.ColorTranslator.FromHtml("#F7F7F7");
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.Position = Telerik.Web.UI.HtmlChart.AxisTitlePosition.Center;
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.RotationAngle = 0;
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.Text = columns[1];
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.TextStyle.Color = System.Drawing.ColorTranslator.FromHtml("#000000");
RadHtmlChart3.PlotArea.XAxis.TitleAppearance.Text = columns[0];
RadHtmlChart3.PlotArea.YAxis.TitleAppearance.Text = columns[1];
ScatterLineSeries slineSeries = new ScatterLineSeries();
slineSeries.LabelsAppearance.Visible = false;
slineSeries.LabelsAppearance.Position = Telerik.Web.UI.HtmlChart.LineAndScatterLabelsPosition.Below;
slineSeries.LabelsAppearance.DataFormatString = "{0}%";
slineSeries.TooltipsAppearance.DataFormatString = "{0}%";
slineSeries.DataFieldX = columns[0];
slineSeries.DataFieldY = columns[1];
RadHtmlChart3.PlotArea.Series.Add(slineSeries);
RadHtmlChart3.DataSource = reader3;
RadHtmlChart3.DataBind();
}
}
Thank you