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.
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 database. limit() is the max number of result for that attribute to be retrieved .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 in the database. 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 express only monthly events for example, there is no point in using DAY but MONTH or YEAR.
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 type of operation that the returned value represents, which can be sum, avg, min or max. You can see how is this returned as data here.
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 (if no operation is specified it will use 'IN') and the value, which expects an array of values, which can be strings if the field is an attribute or numbers if is a measurement field.
The field object is used only when we need to obtain raw data or display a Raw Data Table, and even though is not required.
var field1 = cf.Field('eventname', 'Event Name')
As we can see here, we use Fields only if we need to display a different label for it. This is explained in detail in the Raw Data Table section.