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

7 posts, 0 answers
  1. Goran
    Goran avatar
    10 posts
    Member since:
    Jun 2015

    Posted 09 Jan Link to this post

    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

  2. Vessy
    Admin
    Vessy avatar
    1380 posts

    Posted 13 Jan Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Goran
    Goran avatar
    10 posts
    Member since:
    Jun 2015

    Posted 14 Jan Link to this post

    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

  5. Vessy
    Admin
    Vessy avatar
    1380 posts

    Posted 15 Jan Link to this post

    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
  6. Goran
    Goran avatar
    10 posts
    Member since:
    Jun 2015

    Posted 16 Jan in reply to Vessy Link to this post

    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>

  7. Goran
    Goran avatar
    10 posts
    Member since:
    Jun 2015

    Posted 17 Jan in reply to Goran Link to this post

    Hi, 

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

     

  8. Vessy
    Admin
    Vessy avatar
    1380 posts

    Posted 18 Jan Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017