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

Local shared data source issue

5 Answers 88 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 06 Feb 2012, 11:44 AM
Your documentation implies that this should work, but it doesn't. How do I use a local shared data source that allows multiple charts and grids to sort the same data?

If I get the data source from an XML file, it works, but not from a local JS array.



var salesData = [{
    employee: "Joe Smith",
    sales: 2000
}, {
    employee: "Jane Smith",
    sales: 2250
}, {
    employee: "Will Roberts",
    sales: 1550
}];


var localDataSource = new kendo.data.DataSource({ data: salesData });


$(document).ready(function () {
    $("#test").kendoChart({
        title: {
            text: "Employee Sales"
        },
        dataSource: {
            data: localDataSource
        },
        series: [{
            type: "line",
            field: "sales",
            name: "Sales in Units"
        }],
        categoryAxis: {
            field: "employee"
        }
    });
});

5 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 06 Feb 2012, 05:04 PM
Does this work for anyone else? It seems like I may be missing something obvious. Any help would be really appreciated.
0
John
Top achievements
Rank 1
answered on 06 Feb 2012, 05:22 PM
I was being absent minded.

I was defining data source like this:

dataSource: {
            data: localDataSource
        },



When really I was trying to do this:

dataSource: localDataSource,


That will teach me to copy and paste example code without looking it over!
0
Accepted
Alexander Valchev
Telerik team
answered on 07 Feb 2012, 09:29 AM
Hello John,

Indeed, in order to get the data from a local JavaScript array, you have to use dataSource: { data: salesData } .

If you prefer to use Kendo DataSource component, the right syntax is dataSource: localDataSource .
Please check the following example:

var salesData = [{ employee: "Joe Smith", sales: 2000},
    { employee: "Jane Smith", sales: 2250},
    { employee: "Will Roberts", sales: 1550 }];
             
var localDataSource = new kendo.data.DataSource({data: salesData});
 
$(document).ready(function() {
    $("#chart").kendoChart({
        title: { text: "Employee Sales" },
        dataSource: localDataSource,
        series: [{
            type: "line",
            field: "sales",
            name: "Sales in Units"
        }],
        categoryAxis: { field: "employee" }
    });
});


 
Regards,

Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Robert
Top achievements
Rank 1
answered on 30 Mar 2013, 04:51 AM
This is great. So what would I do if I needed to give the dataSource a totally new set of data? Would I do another localDataSource = new kendo.data.DataSource({data: newSalesData}); or something else?

Thanks!
0
Alexander Valchev
Telerik team
answered on 03 Apr 2013, 11:45 AM
Hello Robert,

You can replace the existing data with a new one via data method of the DataSource. 
dataSource.data([{foo: "bar"}, {foo: "baz"}]);


Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Alexander Valchev
Telerik team
Robert
Top achievements
Rank 1
Share this question
or