Local shared data source issue

6 posts, 1 answers
  1. John
    John avatar
    3 posts
    Member since:
    Nov 2011

    Posted 06 Feb 2012 Link to this post

    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"
            }
        });
    });

  2. John
    John avatar
    3 posts
    Member since:
    Nov 2011

    Posted 06 Feb 2012 Link to this post

    Does this work for anyone else? It seems like I may be missing something obvious. Any help would be really appreciated.
  3. Kendo UI is VS 2017 Ready
  4. John
    John avatar
    3 posts
    Member since:
    Nov 2011

    Posted 06 Feb 2012 Link to this post

    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!
  5. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 07 Feb 2012 Link to this post

    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!
  6. Robert
    Robert avatar
    38 posts
    Member since:
    Feb 2012

    Posted 29 Mar 2013 Link to this post

    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!
  7. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 03 Apr 2013 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready