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

Cannot call method 'slice' of undefined

4 Answers 103 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 19 May 2014, 07:44 PM
I am trying to bind a kendoChart to a datasource and get the following error: "Uncaught TypeError: Cannot call method 'slice' of undefined".
I used the bar chart example from the Telerik demo's and changed the json to add some metadata for the chart.

My json looks like this:

[
    {
        "chartitems": [
            {
                "high": 50,
                "index": 0,
                "low": 180,
                "medium": -34,
                "name": "Building 0"
            },
            {
                "high": 45,
                "index": 1,
                "low": 145,
                "medium": 22,
                "name": "Building 1"
            },
        "Title": "test",
        "LegendPosition": "top"
    }
]



My datasource looks like this:

var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: "data/chart.json",
            dataType: "json"
        }
    },
    schema: {
        data: "chartitems"
    }
});

and I'm creating the chart like this:
            var bar = $("#chart").kendoChart({
                dataSource: dataSource,
                categoryAxis: {
                    field: "name"
                },
                series: [{
                    name: "Medium",
                    field: "medium"
                },
                {
                    name: "Low",
                    field: "low"
                }]
});
...

I got this to work using the Kendo example with the "flat" json file but I'm trying to add some metadata to the json so the bar chart can be formatted with title, legend position, etc.

4 Answers, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 21 May 2014, 10:10 AM
Hi Erik,

The problem in your case is that you have array with object. If you specify a schema.data the datasource will require an object instead of array. In other words your data should look like this:
{
    "chartitems": [
        {
            "high": 50,
            "index": 0,
            "low": 180,
            "medium": -34,
            "name": "Building 0"
        },
        {
            "high": 45,
            "index": 1,
            "low": 145,
            "medium": 22,
            "name": "Building 1"
        }],
    "Title": "test",
    "LegendPosition": "top"
}
In this case I will try to return an readable javascript error but this will be available for the next official release of Kendo UI.

Regards,
Hristo Germanov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Erik
Top achievements
Rank 1
answered on 21 May 2014, 07:01 PM
Ah, ok. I was not aware of this. 
Thanks, that works.
0
Erik
Top achievements
Rank 1
answered on 03 Jun 2014, 08:11 PM
Hi Hristo,

I'm now getting data from a webservice in jsonp format.
The graph IS displayed but I see this 'slice' of undefined error again in my console log. 
What can this be and how can I figure out what is going on?
0
Hristo Germanov
Telerik team
answered on 05 Jun 2014, 02:00 PM
Hi Erik,

I am not sure what could be the problem. Could you please give me a sample project or the output of your data? Thus I will be able to help you.

Regards,
Hristo Germanov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Charts
Asked by
Erik
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
Erik
Top achievements
Rank 1
Share this question
or