Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 5 Next »

Overview

Google Charts is a Javascript library developed by Google to visualize data. Similar to amCharts, it has a specific way it expects the data to be provided to the API in order for the charts to work. RDS provides a way to format the results in the way Google Charts expects to receive them.

Step By Step

  • In this example we will create an object that can be used with Google Charts. 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:

    Tabulation
    {host}/rds/test/view/tabulate?dims=var
    Tabulation Output
     {
        "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 Google Charts expects to see it. 

    Tabulation amCharts
     {host}/rds/test/view/tabulate?dims=var&format=gcharts
    Tabulation amCharts Output
    {
        "cols": [
            {
                "id": "var",
                "type": "number"
            },
            {
                "id": "count",
                "type": "number"
            }
        ],
        "rows": [
            {
                "c": [
                    {
                        "v": 1
                    },
                    {
                        "v": 182
                    }
                ]
            },
            {
                "c": [
                    {
                        "v": 2
                    },
                    {
                        "v": 354
                    }
                ]
            },
            {
                "c": [
                    {
                        "v": 3
                    },
                    {
                        "v": 126
                    }
                ]
            }
        ]
    } 
  • In addition to formatting the values into a Google Charts compliant format, 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.

    Tabulation amCharts With Metadata
     {host}/rds/test/view/tabulate?dims=var&format=gcharts&metadata 
    Tabulation amCharts Output With Categories
    {
        "cols": [
            {
                "id": "var",
                "type": "string"
            },
            {
                "id": "count",
                "type": "number"
            }
        ],
        "rows": [
            {
                "c": [
                    {
                        "v": "METROPOLITAN AREA"
                    },
                    {
                        "v": 182
                    }
                ]
            },
            {
                "c": [
                    {
                        "v": "TOWN OR CITY"
                    },
                    {
                        "v": 354
                    }
                ]
            },
            {
                "c": [
                    {
                        "v": "OPEN COUNTRY"
                    },
                    {
                        "v": 126
                    }
                ]
            }
        ]
    }
  • No labels