Skip to content

Metric

The Metric object represents the measure object. One or more Metric objects can be passed as parameters to the .metrics() function. Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
let provider = cf.provider("Aktiun Elastic");
let source = provider.source('ticket_sales');
// The count metric
let metric0 = cf.Metric();
// commission sum
let metric1 = cf.Metric("commission", "sum").hideFunction();
// price paid sum
let metric2 = cf.Metric("pricepaid", "sum").hideFunction();
// Define attributes to group by
let group = cf.Attribute("eventname.keyword")
    .limit(10)
    .sort("desc", metric1);
// Add metrics and groups to data source
let myData = source.groupby(group)
    .metrics(metric0, metric1, metric2);

The first metric in the example above is the count metric which is returned by default when no field and function is specified. The other metrics specify the measurement field and the aggregation function (operation) that the returned value represents. Example of aggregation functions are sum, avg, min, max, unique. You can see sample returned data here.

Hiding the aggreagation function

By default the metric aggregation function is displayed along with the metric label in the chart axis, legend, and tooltips. To only render the metric label and hide the aggregation function we can use the hideFunction() method as shown below:

1
cf.Metric('pricepaid', 'sum').hideFunction()

The picture below shows how metric functions are rendered by default:

image

The picture below shows how different chart elements render when the metric function is hidden:

image