Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • In this example we will create a dataProvider object that can be used with amCharts. We will assume that we have a collection named "test" and a view named "view" with a variable named "var" that has the values 1, 2, and 3. In this example we will run a tabulation that will count the frequencies of each of these values that could be used to create a chart.
  • Running the tabulation would normally look something like this:

    Code Block
    titleTabulation
    {host}/rds/test/view/tabulate?dims=var
    Code Block
    titleTabulation Output
    collapsetrue
     {
        "records": [
            [
                1,
                182
            ],
            [
                2,
                354
            ],
            [
                3,
                126
            ]
        ],
        "info": {
            "colCount": 2,
            "format": "MTNA",
            "includeMetadata": false,
            "limit": 20,
            "offset": 0,
            "moreRows": false
        }
    }
  • We can add the format parameter to specify we want this to be output in a way that amCharts expects to see it. 

    Code Block
    titleTabulation amCharts
     {host}/rds/test/view/tabulate?dims=var&format=amcharts
    Code Block
    titleTabulation amCharts Output
    collapsetrue
    {
        "dataProvider": [
            {
                "var": 1,
                "count": 182
            },
            {
                "var": 2,
                "count": 354
            },
            {
                "var": 3,
                "count": 126
            }
        ]
    } 
  • In addition to formatting the values in a dataProvider, we can also substitute the numeric values for the categories they represent if the variable has a classification associated with it. In this example we will assume that var has the following classification:

    1METROPOLITAN AREA
    2TOWN OR CITY
    3OPEN COUNTRY

    With this in mind, all we have to do is ask for the metadata to be returned along with our previous tabulation and the output will have the categories instead of the numeric values.

    Code Block
    titleTabulation amCharts With Metadata
     {host}/rds/test/view/tabulate?dims=var&format=amcharts&metadata 
    Code Block
    titleTabulation amCharts Output With Categories
    collapsetrue
     {
        "dataProvider": [
            {
                "var": "METROPOLITAN AREA",
                "count": 182
            },
            {
                "var": "TOWN OR CITY",
                "count": 354
            },
            {
                "var": "OPEN COUNTRY",
                "count": 126
            }
        ]
    }