Skip to content

Data Format

The data managed by ChartFactor, whether is the data returned by a query, or the one that is injected to a visualization to be rendered later, has a specific format, which is a JSON object structured as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
var data = [
{
    "group":["Peugeot"],
    "current":{
        "metrics":{
            "Price":8000
        }
    }
},
{
    "group":["Renault"],
    "current":{
        "metrics":{
        "Price": 9000
        }
    }
}
]

The "data" variable is an array. Each item in the array is an object that includes groups and metrics.

Groups

The group attribute is an array of strings.  The number of elements within this array depends on the number of attributes that have been grouped. The previous example includes only one element, so it can be used with visualizations like Bars, Pie, Donut... When we have two values in the group array, we can visualize this data using "Multi-Group visualizations" like Stacked Bars, Grouped Bars, and Heat Map for example.

1
{ group: ["Peugeot", "France"], ... }

The number of elements in the group array must be consistent, so if one data object has 2 elements, the rest should also have 2 elements. If there is no value for some of them, they should be completed with null.

Metrics

Metrics should be specified within the current -> metrics object. There can be as many metrics as we want. Each metric should have an entry within the metrics attribute with the name of the metric and the value for that metric for the current item. There is a difference between the data that is obtained in queries, and the one that is injected to a non-queried visual for the metrics. The initial example represents the one that is injected and the following the one that is queried:  

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
var data = [
{
    "group":["Peugeot"],
    "current":{
        "count": 1,
        "metrics":{
            "Price":{ sum: 1000, avg: 1000}
        }
    }
},
{
    "group":["Renault"],
    "current":{
        "count":4,
        "metrics":{
        "Price":{ sum: 36000, avg: 9000}
        }
    }
}
]

Notice that the differences are in the presence of the "count" attribute, which shows the number of items represented by the group value (1 Peugeot and 4 Renaults) and the other one is that the metric "Price" is not a value but an object, that in this case contains different values depending on the requested function for that metric (sum, avg, min, max).

Fields

Fields is the only type of data that is different. When using the .fields() function to query data, ChartFactor understands that we are querying raw data, so it won't return an aggregated structure. Instead it will return an array of objects where each object will be a JSON representation for the rows of the table.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var data = [
    {birthdate: "1988-3-1", name: "Barry", rating: Array(2), sport: "Baseball"},
    {birthdate: "1988-3-1", name: "Wayne", rating: Array(2), sport: "Hockey"},
    {birthdate: "1988-3-1", name: "Brady", rating: Array(2), sport: "Football"},
    {birthdate: "1992-5-20", name: "Joe", rating: Array(2), sport: "Baseball"},
    {birthdate: "1992-5-20", name: "Ping", rating: Array(2), sport: "Baseball"},
    {birthdate: "1990-9-9", name: "Hal", rating: Array(2), sport: "Baseball"},
    {birthdate: "1990-9-9", name: "Alfred", rating: Array(2), sport: "Baseball"},
    {birthdate: "1989-10-1", name: "Mick", rating: Array(2), sport: "Baseball"}
]