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 an 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 with two items. Each item will be composed by groups and metrics.

Groups

The group attribute is an array of strings.  The number of values within this array depends on how many aggregations the data has. The previous example has only one,  so it can be used with most of the visualizations  like Bars, Pie, Donut... In this case we have two values, so it means that in order to display them, we need to use "Multi-Group visualizations", like Heat Map for example.

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

The quantity of values must be consistent, so if one group 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 attributes current -> metrics. 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's 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 previous 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 "Speed" 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 in an aggregated structure, instead it will an array of objects, were 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"}
]