Field statistics

Feedback


The data resource and its child resources provide the capabilities of data query and data operation. This example illustrates how to do statistics on a field of a dataset.

Statistics on a field is performed by implementing the GET request on the statistic resource. Please refer to statistic .

This example illustrate how to perform statistics on the POP_1994 filed of the Countries dataset in the World datasource. Implement GET request on the URI below:

http://localhost:8090/iserver/services/components-rest/rest/data/datasources/name/World/datasets/name/Countries/fields/POP_1994/{statisticMode}.json

The result varies for different values for {statisticMode}. To get the maximum, sum, or average value of a field, set {statisticMode} to MAX, SUM, and AVERAGE respectively.

Sample code:

//Statistics on the population in 1994

function FieldStatistic()

{

        var commit=getcommit();

        var baseuri="http://localhost:8090/iserver/services/components-rest/rest/data/datasources/name/World/datasets/name/Countries/fields/POP_1994";

        //Get the MAX of the values for this field

        commit.open("GET",encodeURI(baseuri+"/MAX.json"),false,"","");

        commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

        commit.send(null);

        //Parse the json string returned from the server to a JavaScript object

        var response = json_parse(commit.responseText, null);  

        var max=response.result;

        //Get the SUM of the values for this field

        commit.open("GET",encodeURI(baseuri+"/SUM.json"),false,"","");

        commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

        commit.send(null);

        //Parse the json string returned from the server to a JavaScript object

        response = json_parse(commit.responseText, null);  

        var sum=response.result;

        //Get the AVERAGE of the values for this field

        commit.open("GET",encodeURI(baseuri+"/AVERAGE.json"),false,"","");

        commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

        commit.send(null);

        //Parse the json string returned from the server to a JavaScript object

        response = json_parse(commit.responseText, null);  

        var average=response.result;

        var str="In 1994, the population in the world is "+sum+". The population of the country with the most population is "+max+", and the average population in the world is "+average+"." ;

        //Get the Div container for display

        var container = document.getElementById('container');

        container.innerHTML+='<p>'+str+'</p>';

}

The statistical result is as follows: