Receiving the Chart's Data

To receive the results of queries executed against a Zoomdata data source, chart developers can override the controller.update method with a function that will receive the array of data elements.

Example:

// In visualization.js

/* This function will get called when new data is received from the server */
controller.update = function(data) {
  // code to update the chart with new data
  // the data argument is an array of objects (data elements)
};

Structure of a Data Element in Aggregated Queries

When working with aggregated queries, e.g., those that have Group or Multi-Group variables defined, you can expect to receive data elements with the following structure:

{
  "group": ["Books", "$0 to $25,000"],
  "current": {
    "count": 1267,
    "metrics": {
      "price": {
        "sum": 1077100
      }
    }
  }
}

The above JSON represents the results of a chart query generated by defining a Multi-Group variable and Metric variable. The Multi-Group variable contains two levels of grouping (“Product Group” & “User Income” fields), and the Metric variable has a configuration using the “Price” field and the “SUM” function. The count property represents the total count of records for the grouping combination. This property is always available in all aggregated queries.

Structure of a Data Element in Non-Aggregated Queries

When working with non-aggregated queries, the data elements in the array received from the server represent a row of data in the data source. Each row is made up of an array of values; one for each of the fields requested:

["Male", "Visa", "400"]

The above JSON represents the results of a chart query generated by defining an Ungrouped variable with three fields requested: “Gender”, “Payment Type”, “Price”.