Can't get jSon dataStore into ExtJS (Sencha Touch) chart: displays error “cannot read property 'length' of undefined”

前端 未结 2 529
一个人的身影
一个人的身影 2020-12-22 02:53

EDITED I am using Sencha touch charts sample provided for column charts. The code is as below

new Ext.chart.Panel({
    fullscreen: true,
           


        
相关标签:
2条回答
  • 2020-12-22 03:41

    I solved this issue with the help of a Sencha folk. Thanks Dan. Here is the solution:

    1. run the sample on a web server as loading JSON files from the file system can sometimes cause problems.
    2. Structure the json data as below

      {
          "data": [
              {
                  "School": "Dukes",
                  "wins": "3"
              },
              {
                  "School": "Emmaus",
                  "wins": "10"
              },
              {
                  "School": "Maryland",
                  "wins": "5"
              },
              {
                  "School": "Virginia",
                  "wins": "2"
              }
          ]
      }
      
    3. Use the below data store

      window.store1 = new Ext.data.Store({
          model: 'Details',
          proxy: {
              type: 'ajax',
              url: 'GetDataset.json',
              reader: {
                  root: 'data',
                  type: 'json'
              }
          },
          autoLoad: true
      });
      
    0 讨论(0)
  • 2020-12-22 03:43

    I'm guessing here, but it seems like a problem I've had before. I believe the problem is with the proxy. Try:

    proxy: {
        type: 'rest',
        url: 'http://localhost:2650/AjaxWCFService.svc/GetDataset', 
        reader: {
            root: 'data'
        }
    
    },
    

    Now, you need to define the callback function for the proxy. There's an elegant way with some config, but I honsetly don't know how to do that, so I found out a different solution at the time, the hard way, which is to wrap the JSON which your service returns inside of(like they do here):

    Ext.data.JsonP.callback1();
    

    If none of that works, also consider adding the following to your proxy, and emitting a 'total' as part of your JSON response.

    totalProperty: 'total'
    

    But keep in mind that I really don't think this will help much at all and that I'm just throwing these ideas out based on a working sample I have.

    Try reading this and this. And most of all good luck, that's all of the top of my head mate. Also have a look at this post.

    I hope that points you in the right direction. Like I said, I'm not sure, this is my best guess. I'm probably wrong.

    Cheers rivanov

    0 讨论(0)
提交回复
热议问题