1

示例 XML 文件:

<BrowserInformation>
      <Value>
            <Year>2011</Year>
            <Name>Firefox</Name>
            <Count>4952</Count>
        </Value>
            <Year>2011</Year>
            <Name>MSIE</Name>
            <Count>4613</Count>
        <Value>
            <Year>2011</Year>
            <Name>Chrome</Name>
            <Count>1401</Count>
        </Value>
        <Value>
            <Year>2011</Year>
            <Name>Safari</Name>
            <Count>1111</Count>
        </Value>
        <Value>
            <Year>2011</Year>
            <Name>Unknown</Name>
            <Count>1119</Count>
        </Value>
        <Value>
            <Year>2011</Year>
            <Name>Opera</Name>
            <Count>9</Count>
        </Value>
        <Value>
            <Year>2012</Year>
            <Name>Firefox</Name>
            <Count>3544</Count>
        </Value>
            ...
</BrowserInformation>

柱形图制作: 在此处输入图像描述

目前,对于 XML 文件中的每条记录,图表中都有一个条形图。我想获得每个浏览器的汇总计数(即对于 Firefox,它将是 4952 + 3544)。数据和存储类的配置选项 idProperty 和 groupers 似乎只是将具有相同名称的条在图表中彼此相邻,但似乎没有将它们组合起来。假设文件中的数据不能改变。我将如何做到这一点?我可以在模型、商店或图表中设置特定的配置属性吗?如果有,是哪个?还是有其他方法?

4

1 回答 1

2

I would suggest to use a new field in the model, say "total", and use a convert function.

From the Ext JS API documentation

"If a more complex value extraction strategy is required, then configure the Field with a convert function. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to return the desired data."

Your convert function then could be something like this

function convert2Total(v, record){
    return record.data.firefox + record.data.chrome;
}

Your fields array in your model would then look like this:

fields: [ { name: "firefox" },
          { name: "chrome" },
          { name: "total", convert: convert2Total }]
于 2013-06-11T15:32:50.670 回答