Cannot provide a number as a key in JSON - get an "Unexpected number" error.

2 posts, 0 answers
  1. AP
    AP avatar
    3 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    Hello, 

    If I provide this simple data to a chart, the chart data shows up correctly.
    var data = [
                    {"state":"NY","abc":12312},
                    {"state":"AZ","abc":12312},
                    {"state":"CA","abc":12312},
                    {"state":"VT","abc":12312}
                ];
    Please note that the above JSON has STRINGS for the keys.

    However, if I provide a number as a key, I get an "Unexpected number at line number 2156" error.

    var data = [
                    {"state":"MH","1":12312},
                    {"state":"MH","1":12312},
                    {"state":"MH","1":12312},
                    {"state":"MH","1":12312}
                ];

    Any help?
  2. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2622 posts

    Posted 24 Jan 2013 Link to this post

    Hello,

    In order to get the desired outcome you can pass an array to the series. I.e.:

    $("#chart").kendoChart({
      //...
      dataSource: {
          data: [
             {"state":"MH","1":12312},
             {"state":"MH","1":12312},
             {"state":"MH","1":12312},
             {"state":"MH","1":12312}]
      },
      series: [{
          field: "['1']"
      }]
    })

    For a working example please check this jsBin example.

    Regards,
    Iliana Nikolova
    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