填充商店时出现 extjs 错误

extjs error on filling store

我有一张 java 地图。我将它转换为 json 字符串,并得到类似这样的内容:

{"NEW ZEALAND":"111111111111111","CHAD":"1","MOROCCO":"111","LATVIA":"11"}

现在我想在商店中使用它,然后像下面的代码一样使用图表,但它不起作用。我没有错误只是没有显示。

var obj = Ext.Ajax.request({
  url: App.rootPath + '/controller/home/dashboard/test.json',
  method:'GET',
  success: function(response) {          
    return Ext.JSON.decode(response.responseText);
  }
});

var store2 = Ext.create('Ext.data.Store', {
  model: 'PopulationPoint',
  data: obj
});

Ext.create('Ext.chart.Chart', {
  renderTo: 'infos2',
  width: 500,
  height: 300,
  store: store2,
  series: [
    {
      type: 'pie',
      field: 'population',
      label: {
        field: 'state',
        display: 'rotate',
        font: '12px Arial'
      }
    }
  ]
});

AJAX 请求是异步的。因此,用于初始化数据的 obj 变量还不会包含您的数据。

一种选择是创建 store2 变量并直接在 AJAX 请求的成功回调中创建图表。

更简洁的选择是使用代理配置商店以加载 url,并在回调中创建图表。

编辑

JSON 响应不包含在您的模型中声明的字段(在评论中发送)。将 JSON 更新为 return 格式正确的模型,图表应该如 this fiddle 中所示工作。 JSON 应该类似于

[
    {
      "state" : "New Zealand",
      "population" : 111111111
    },
    {
      "state" : "Chad",
      "population" : 1
    }
]