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

Populating Chart

1 Answer 25 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nick Jones
Top achievements
Rank 1
Nick Jones asked on 18 Mar 2014, 11:07 AM
Hi,

Please can someone help me.  I'm trying to populate a bar chart from the code behinddata in a web forms environment.  I've serialized the data to json and put into a hidden field.  Then trying to set that as the datasource but the report keeps coming up blank.  What's wrong?

hdn1.value = JsonArray()    End Sub
    Public Class Sales
        Public Property name As String        Public Property data As String   
    End Class   
    Protected Function JsonArray() As String
        Dim myArray As String
        Dim obj As New Sales With {.name = "Sales", .data = "8067.96, 8099.93, 9175, 8874, 8478"}
        Dim obj2 As New Sales With {.name = "Costs", .data = "8067.96, 8099.93, 9175, 8874, 8478"}       
        Dim objSales As New List(Of Sales)() From {obj, obj2}
        Dim objSerializer As New JavaScriptSerializer()
        myArray = objSerializer.Serialize(objSales)
        Return myArray
    End Function


jQuery(document).ready(function ($) {
            var myTheme = 'blueopal';
            var myds = $('#MainContent_hdn1').val();
            alert(myds);
          
            $("#chart").kendoChart({
                datasource: {
                        data: myds
                },                series: [{
                    field: "data"
                }],
                                               //seriesDefaults: { type: "verticalBullet" },
                chartArea: {
                    height: 250                  
                },
                theme: myTheme,
                tooltip: {
                    visible: true,
                    template: "#= series.name #: #= value #"
                }
            });

1 Answer, 1 is accepted

Sort by
0
Iliana Nikolova
Telerik team
answered on 20 Mar 2014, 10:46 AM
Hi Nick, 

In order to avoid the issue you should: 
  • Modify the nested JSON object - Kendo UI Chart expects flat data. For example: 
    [{
      "name": "Sales",
      "data": 8067.96
    }, {
      "name": "Sales",
      "data": 8099.93
    },
      //....
    }];
  • Correct the dataSource syntax - it must be dataSource, not datasource.
Regards,
Iliana Nikolova
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
General Discussions
Asked by
Nick Jones
Top achievements
Rank 1
Answers by
Iliana Nikolova
Telerik team
Share this question
or