Why cannot bind NULL to BarChart?

0 Answers 78 Views
Chart (HTML5)
yuki
Top achievements
Rank 2
Iron
Iron
Iron
yuki asked on 03 May 2023, 02:57 PM

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.

yuki
Top achievements
Rank 2
Iron
Iron
Iron
commented on 04 May 2023, 07:48 AM

NVM. I bind an empty datatable to the bar chart to realize my goal instead of binding null.
Rumen
Telerik team
commented on 05 May 2023, 12:08 PM

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();
        }
    }

 

yuki
Top achievements
Rank 2
Iron
Iron
Iron
commented on 08 May 2023, 10:07 AM

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.

Rumen
Telerik team
commented on 09 May 2023, 06:23 AM

For nothing, Yuki! Thank you for the clarification and keep up the good work!

No answers yet. Maybe you can help?

Tags
Chart (HTML5)
Asked by
yuki
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or