0

我尝试在 ext 7 的笛卡尔图表上使用直接代理加载 json 数据,如下所示: https ://fiddle.sencha.com/#view/editor&fiddle/3bae

在此示例中,我从 ajax 加载数据,但返回数据是相同的。(它实际上是从我的直接 api 复制粘贴的)。我的测试系统上的结果相同:我可以加载硬编码数据,但不能从代理加载。

如何格式化数据以填充我的图表?

4

1 回答 1

1
  1. JSON 的根属性必须是“result.data”
  2. 数据是对象,而不是数组

对于您的自定义 JSON,您可以编写阅读器转换器,如下所示:

    ...
    ...
    proxy: {
        type: 'ajax',
        url: 'test.json',
        reader: {
            type: 'json',
            rootProperty: 'data',
            fields: ['month', 'value'], // What is it? 
            transform: {
                fn: function (data) {
                    return Object.values(data.result.data);
                },
                scope: this
            }
        }
    },
    autoLoad: true
});

或者您可以更改后端以生成标准的 extjs json,示例:

{
    "users": [
       {
           "id": 1,
           "name": "Ed Spencer",
           "email": "ed@sencha.com"
       },
       {
           "id": 2,
           "name": "Abe Elias",
           "email": "abe@sencha.com"
       }
    ]
}
于 2021-01-16T22:09:57.760 回答