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

Problem binding JSON data with Kendo Pie Chart

2 Answers 259 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Waseem
Top achievements
Rank 1
Waseem asked on 26 Mar 2012, 02:52 PM
Hi,
I have a problem in binding JSON data with Kendo Pie Chart.
I have data source where I have supplied the url of my service with method name, that is getting me the data from server. I can see the data is returning from the server when I paste that url in my firefox  browser. I am also supplying the field name to the grid but not getting my chart displayed. It works fine when i supply hard coded array to it.
Could please anyone help me? Following is the code

    <div id= "kendoChart" style="width:50%; float:right; height:450px; margin-top:-20"></div>
    <script type="text/javascript">
        //var rtData = [3, 15, 30, 45, 92];
        var chartDataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "/DomainService/ContactedChartDomainService.svc/json/GetContactedChartViews",
                    dataType: "json"
                },
                schema:
                        {
                            data: "GetContactedChartViewsResult.RootResults"
                        }
            }
                });

        $(function () {
            $("#kendoChart").kendoChart({
                dataSource: chartDataSource,
                title: { text: "Stats" },
                seriesDefault: {
                    type: "pie"
                },
                series: [
                {
                    field: "Occurances",
                    categoryField: "ContactedName"
                    //type: "pie"
                }],

                tooltip: {
                    visible: true
                }
            });
        });
    </script>
    </div>

my JSON out put is as follow
{"GetContactedChartViewsResult":{"TotalCount":3,"RootResults":[
{"ContactedID":1,"ContactedName":"No","Occurances":5},
{"ContactedID":2,"ContactedName":"Under Consideration","Occurances":1},
{"ContactedID":3,"ContactedName":"Follow Up","Occurances":11}]}}

Kind Regards,
Waseem

2 Answers, 1 is accepted

Sort by
0
Gergo
Top achievements
Rank 1
answered on 02 Apr 2012, 06:00 PM
Hi Waseem,

It seems to me that your are not returning the correct data with JSON.
I think you should only return the following JSON:
[
{"ContactedID":1,"ContactedName":"No","Occurances":5},
{"ContactedID":2,"ContactedName":"Under Consideration","Occurances":1},
{"ContactedID":3,"ContactedName":"Follow Up","Occurances":11}
]

The rest of the JSON you've posted to PieChart it confuses it.
You can try to build up sample data of type RootResults in Javascript for your datasource this way you can figure out rapidly what the problem is.

Hope I could help,
Gergő

0
Eloy
Top achievements
Rank 1
answered on 19 Apr 2012, 10:48 AM
You can try to do this:

$(function () {
    $("#kendoChart").kendoChart({
dataSource: {
transport: {
read: {
url: "/DomainService/ContactedChartDomainService.svc/json/GetContactedChartViews",
dataType: "json"
},
schema:
model: {
fields: {
Occurances: { type: "number" },
ContactedName: { type: "string" }
}
 }
}
}
},
title: {
text: "Stats"
},
seriesDefault: {
type: "pie"
},
series: [
{
field: "Occurances",
categoryField: "ContactedName"
//type: "pie"
}],
tooltip: {
visible: true
}
});
});

Tags
Charts
Asked by
Waseem
Top achievements
Rank 1
Answers by
Gergo
Top achievements
Rank 1
Eloy
Top achievements
Rank 1
Share this question
or