This is a migrated thread and some comments may be shown as answers.

How to check if databound chart is empty on server side?

6 Answers 166 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Goran
Top achievements
Rank 1
Goran asked on 09 Jan 2016, 09:34 PM

Hello,

I have a databound chart to sqldatasource. In DataBound event on server-side I want to check if the chart has data and if it does not I want to hide it. I've tried this but without any luck (VB.NET):

 

 Protected Sub RadHtmlChart1_DataBound(sender As Object, e As EventArgs) Handles RadHtmlChart1.DataBound
        If RadHtmlChart1.PlotArea.Series(0).Items.Count = 0 Then
            RadHtmlChart1.Visible = False
        Else
            RadHtmlChart1.Visible = True
        End If
End Sub

6 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 13 Jan 2016, 05:23 PM
Hello,

RadHtmlChart does not implement the server-side OnDataBound event as it uses client-side data binding and rendering. This issue is explained in details in the following article:
RadHtmlChart Known Limitations

Regards,
Vessy
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Goran
Top achievements
Rank 1
answered on 14 Jan 2016, 09:14 AM

Hello

 Thank you for your reply. Can you please guide me how to hide the chart if it's empty on client side? Please note that my chart is databound to sqldatasource control.

 

Thanks

0
Vessy
Telerik team
answered on 15 Jan 2016, 05:41 PM
Hi Goran,

You can get access to the chart's data source on the client through the control's kendo object and hide it depending on the result using its set_visible() method. For example:
var chart = $find("RadHtmlChart1");
if (chart.get_kendoWidget().dataSource.data().length < 1) {
    chart.set_visible(false);
}

You can also find useful information on the matter in the RadHtmlChart Client-side API article.

Regards,
Vessy
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Goran
Top achievements
Rank 1
answered on 16 Jan 2016, 06:35 PM

Hi Vessy,

this method doesn't work - or I'm missing something. I'm getting an javascript error saying: "Cannot read property 'get_kendoWidget' of null", meaning $find function is returning null.

 Here's my code:

01.<%@ Page Language="VB" %>
02.<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
03. 
04.<!DOCTYPE html>
05. 
06.<script runat="server">
07. 
08.</script>
09. 
11.<head runat="server">
12.    <title></title>
13.</head>
14.<body>
15.    <form id="form1" runat="server">
16.    <div>
17.        <asp:ScriptManager runat="server" id="sm1"></asp:ScriptManager>
18.         <telerik:RadHtmlChart RenderAs="Canvas" Transitions="false"   runat="server" Width="540px" Height="200px" ID="RadHtmlChart1"  DataSourceID="SqlPrisutnost">
19.            <PlotArea>
20.                    <Series>
21.                        <telerik:LineSeries DataFieldY="postotak"  Name="Attendance">
22.                            <LineAppearance Width="5" />
23.                            <TooltipsAppearance Visible="False" />
24.                            <Appearance Overlay-Gradient="None"></Appearance>
25.                        </telerik:LineSeries>
26.                    </Series>
27.                    <XAxis DataLabelsField="razdoblje">
28.                    </XAxis>
29.                    <YAxis MaxValue="100" MinValue="0"    Step="20">
30.                        <TitleAppearance Text="%" />
31.                        <MinorGridLines Visible="False" />
32.                    </YAxis>
33.                                     
34.                </PlotArea>
35.                <Legend>
36.                    <Appearance Visible="false" />
37.                </Legend>
38.                <ChartTitle Text=" ">
39.                </ChartTitle>
40.            </telerik:RadHtmlChart>
41. 
42.         <asp:SqlDataSource ID="SqlPrisutnost" runat="server"
43.            ConnectionString="<%$ ConnectionStrings:bazaConn %>"
44.            SelectCommand="p_prisutnost_clan" SelectCommandType="StoredProcedure">
45.        </asp:SqlDataSource>
46.    </div>
47.        <script>
48.            var chart = $find("RadHtmlChart1");
49.            if (chart.get_kendoWidget().dataSource.data().length > 0) {
50.                chart.set_visible(false);
51.            }
52.        </script>   
53.    </form>
54.</body>
55.</html>

0
Goran
Top achievements
Rank 1
answered on 17 Jan 2016, 04:00 PM

Hi, 

I found the solution my self! I was missing pageLoad() function. After I put my javascript code inside that, it worked!

 

0
Vessy
Telerik team
answered on 18 Jan 2016, 07:52 AM
Hi Goran,

I am glad you managed to solve the problem on your own. Feel free to reach us again in case further assistance is needed.

Regards,
Vessy
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart (HTML5)
Asked by
Goran
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Goran
Top achievements
Rank 1
Share this question
or