Retrieve data as JSON

7 posts, 1 answers
  1. Teena
    Teena avatar
    16 posts
    Member since:
    Feb 2013

    Posted 11 Mar 2013 Link to this post

    Hi,

    From client side code, Is it possible to retrieve data from the current datasource of the HtmlChart to an array of JSON objects and store it in a variable?

    Thanks,
    Teena.
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Mar 2013 Link to this post

    Hello Teena,

    Please have a look into the following sample client side code I tried at my end.

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked1() {
            var RadHtmlChart1 = $find('<%=RadHtmlChart1.ClientID %>');
            //Parsing the current datasource to an array of JSON objects and storing it a variable
            var oldDataSource = $telerik.$.parseJSON(RadHtmlChart1.get_dataSourceJSON());
            //Retaining the first Item of the datasource
            var newDataSource[0] = oldDataSource[0];  
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Axel
    Axel avatar
    6 posts
    Member since:
    Mar 2013

    Posted 09 May 2013 Link to this post

    Hi Princy,
    I'm getting a null value when trying to do the:
     
    RadHtmlChart1.get_dataSourceJSON()

    I'm databinding the htmlchart programmaticly and wanted to change the datasource from client-side on another chart clientseriesclick event.


  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1493 posts

    Posted 14 May 2013 Link to this post

    Hi Axel,

    I have tried to reproduce to described issue but to no avail. You can find a short video with the test as well as a VS sample that I have used for the test in the attached archive and then notify me if I am missing something.

    The used sample is a modified version of the example in the Client-side API help article. You can helpful that example as well as the HtmlChart - Client-side Binding online demo in resolving the unexpected behavior.

    It may also be possible that you are using an older version of RadControls that do not support the client-side databinding functionality yet. If that is the case we strongly recommend to update your version of RadControls to the latest one. This help article will shed more light on how to do that.

    If the above information, however, is not helpful could you please amend my VS example, so that it reproduces your issue and then tell us what changes you have made, so that we can proceed further with the investigation?


    Greetings,
    Danail Vasilev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Axel
    Axel avatar
    6 posts
    Member since:
    Mar 2013

    Posted 17 May 2013 Link to this post

    Hi Danail,
    My case is different from the demo.
    Im generating different type of charts, sometimes its a pie, others columns, etc...
    I create series programmaticly thats why on the .aspx file i only declare the
    <telerik:RadHtmlChart ID="chartId" runat="server"></telerik:RadHtmlChart>.
    The rest is on the server side. 

    Thanks for your help.
    Axel

  7. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1493 posts

    Posted 22 May 2013 Link to this post

    Hello Axel,

    Thank you for the additional clarification.

    Note that you can get the datasource of the RadHtmlChart on the client-side only for a databound chart (if SeriesItems are created and added programmatically then you cannot access them on the client).

    You can, however, set a particular datasource to the chart on the client without the need to initially databound it on the server. The only requirement is to set the DataFieldY property of the particular series. More information on the matter is available in this demo.

    I can suggest you that instead of creating SeriesItems programmatically, to create a sample datasource programmatically and databound it. Then you will have the ability to access and modify it on the client. You can also find attached a VS example that demonstrates how to switch the series type and modify the datasource of the chart on the client.

     
    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  8. Axel
    Axel avatar
    6 posts
    Member since:
    Mar 2013

    Posted 22 May 2013 Link to this post

    Hi Danail,
    Thanks for your reply, that was a really good idea! I'll try it.
    Thanks again, 
    Greetings,
    Axel.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017