I have a barchart, and at first I bind a datatable to this chart, it shows properly. Then when I click on a button, I would like the bar chart to show nothing (not clear series, because later on I need this chart to show another datatable), so I set Chart1.DataSource = null; Chart1.Databind();
But this is not working. The data on the chart keeps showing even if I set a null as its datasource. What's wrong? Please help! Thanks.
I am glad that you have found a solution by binding the chart to am empty datatable.
On a side note, I am getting identical results with:
<telerik:RadHtmlChart runat="server" ID="BarChart1" Width="800" Height="500" Transitions="true" Skin="Silk"> <PlotArea> <Series> <telerik:BarSeries DataFieldY="Value" Name="Quarter 1"> </telerik:BarSeries> <telerik:BarSeries DataFieldY="Value" Name="Quarter 2"> </telerik:BarSeries> <telerik:BarSeries DataFieldY="Value" Name="Quarter 3"> </telerik:BarSeries> </Series> </PlotArea> </telerik:RadHtmlChart>
if I set the DataSource to null
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BarChart1.DataSource = null; BarChart1.DataBind(); } }
or to an empty datatable:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dataTable = new DataTable(); dataTable.Columns.Add("Category", typeof(string)); dataTable.Columns.Add("Value", typeof(int)); dataTable.Rows.Add("Category 1", 0); dataTable.Rows.Add("Category 2", 0); dataTable.Rows.Add("Category 3", 0); BarChart1.DataSource = dataTable; BarChart1.DataBind(); } }
Hello Rumen! Thanks for helping me again!
Well, my problem is I first bind the chart to a datatable with data, and then I bind the chart to null, and after I bind the chart to null, the chart keeps showing the former datatable. So I try to bind the chart to an empty datatable, and it works.