Skip to content

Helper Objects

ChartFactor provides with some helper objects that are used mainly to build specific configurations. These may be Attribute, Metric, Filter, Legend, Color and others. Here we explain the objects related with the query configuration. Those related with the visualization options are treated here.

Attribute

This is the object that the .groupby() function expects as parameters. It represents the field used to aggregate a query.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// A normal attribute
var event = cf.Attribute('eventname')
                .limit(20)
                .sort('desc',metricObject)

// A time attribute
var saletime = cf.Attribute('saletime')
                    .sort('asc', 'saletime')
                    .func('DAY')
                    .limit(1000)

The Attribute constructor takes the name of the field existing in the data engine. limit() is the max number of results to be retrieved for that attribute. sort() takes two parameters, the first one is the sort order ('asc' or 'desc'), and the second is based on what is going to be sorted. It can be a Metric object or the string with the name of the same field, which will mean then that is going to be alphabetically sorted (or reverse alphabetically if is 'desc'). For the second case we also have .func(). This only applies to time attributes. And it depends on the minimum granularity of the data. The possible values for this are: SECOND, MINUTE, HOUR, DAY, WEEK, MONTH and YEAR. If the data is in date format for example, we can not tell the object to use SECOND or MINUTE, this will be possible only it is in datetime format. If the data represents monthly events for example, there is no point in using DAY but MONTH or YEAR.

Metric

Metrics represent the measure object and is passed as parameters to the .metrics() function.

1
2
3
4
5
// The count metric
var count = cf.Metric()

// Any other
var pricepaid = cf.Metric('pricepaid', 'sum')

The first metric is the count which is returned as default in most of the providers. The other is any measurement field and the operation that the returned value represents, which can be sum, avg, min, max, or unique. You can see an example of the returned data here.

Filter

With this object we can build filters to narrow our queries.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
// Filter by attribute
var event = cf.Filter('venuecity')
                .value(['New York','LA'])

// Filter by time attribute
var event = cf.Filter('saletime')
                .operation('BETWEEN')
                .value([
                '2008-01-12 00:00:00.000',
                '2008-02-12 00:00:00.000',
            ])

// Filter by a metric
var event = cf.Filter('pricepaid')
                .operation('BETWEEN')
                .value([ 1, 10])
Filters expect the name of the field to filter by, the operation and the value, which expects an array of values. These can be strings if the field is an attribute or numbers if is a measurement field.

Filters support three types of operations: IN, NOT IN and BETWEEN. The last one is used as the examples above for numeric and date fields. If no operation is specified then IN will be used as default.

It also supports the label property which is useful when filters are applied across sources with different field names but common field labels. Refer to Interaction Manager for advanced interactions across visualizations.

Field

The field object is used when we need to obtain raw data or display a Raw Data Table.

1
var field1 = cf.Field('eventname', 'Event Name')

As we can see here, we use Fields if we need to display a different label. This is explained in detail in the Raw Data Table section.