Time Series
Every Metric can be visualized as a Time Series. Unlike Counters, which return a single value for a time range, a Time Series returns values for every time granule over the requested time range. For example, a Time Series could represent
- Monthly sales for the quarter,
- Daily signups for the week, or
- Minute-by-minute error occurrences in the last hour.
Any time you need to visualize a change in Metric over time, consider using a Time Series. If one value will do, consider using a Counter; otherwise, if you need a Metric broken down by Dimension and sorted, consider using a Leaderboard.
Usage​
When building customer-facing analytics, Time Series are essential for understanding how a Metric changes over time. Most customer dashboards are centered around a time series, and any additional visualizations use a time range derived from the Time Series.
There are lots of libraries you can use to visualize Time Series. We've chosen to use Propel's open source UI Kit in the example above, but Propel is compatible with all charting libraries. If you're using React and want some inspiration, check out our blog post, Best React Charting Libraries for Data Visualization and Analytics.
Arguments​
You will pass a TimeSeriesInput
when querying the Time Series. The most
important arguments are
- The
timeRange
to query over, - The time
granularity
to aggregate by, and - The
filters
to use.
Field | Type | Required | Description |
---|---|---|---|
metric | MetricInput | No | The Metric to Query. It can be a pre-created one or it can be inlined here. |
timeRange | TimeRangeInput | No | The time range for calculating the time series. |
timeZone | String | No | The time zone to use. Dates and times are always returned in UTC, but setting the time zone influences relative time ranges and granularities. You can set this to "America/Los_Angeles", "Europe/Berlin", or any other value in the IANA time zone database. Defaults to "UTC". |
granularity | TimeSeriesGranularity | Yes | The time granularity (hour, day, month, etc.) to aggregate the Metric values by. |
filterSql | String | No | The Query Filters to apply before retrieving the time series data, in the form of SQL. If no Query Filters are provided, all data is included. |
groupBy | array of String | No | Columns to group by. |
Returns​
The query returns an array of labels
and an array of values
inside a
TimeSeriesResponse
. There is a label and value for every time granule of the
requested time range.
Each label is a timestamp wrapped in a string, for example, "2023-02-01T00:00:00.000Z".
Each value is a number wrapped in a string. Using a string ensures we can support values greater than 32-bits in the GraphQL API.
Field | Type | Nullable | Description |
---|---|---|---|
labels | array of String | No | The time series labels. |
values | array of String | No | The time series values. |
groups | array of TimeSeriesResponseGroup | Yes | The time series values for each group in |
query | QueryInfo | No | The Query statistics and metadata. |
Example​
Suppose we have a Data Pool syncing from a table of restaurant sales data. The data might look like the following:
Note: this data has essentially the same format as the TacoSoft data we used in our Quickstart.
We can create a Sum Metric named "Revenue" which sums up the sales data. By including "taco_name" and "restaurant_name " as Dimensions, we can answer questions with our Metric. Follow along for worked examples.
1. How much revenue did a particular restaurant generate?​
In this example, we demonstrate how to query the total revenue for a specific restaurant, "El Buen Sabor," over a set period of time from "2023-08-03T07:00:00.000Z" to "2023-08-09T07:00:00.000Z".
- GraphQL Query
Query:
query TimeSeriesExample1($input: TimeSeriesInput!) {
timeSeries(input: $input) {
labels
values
}
}
Variables:
{
"input": {
"metric": {
"sum": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"measure": {
"columnName": "taco_total_price"
}
}
},
"granularity": "DAY",
"timeRange": {
"start": "2023-08-03T07:00:00.000Z",
"stop": "2023-08-09T07:00:00.000Z"
},
"filters": [
"column": "restaurant_name",
"operator": "EQUALS",
"value": "El Buen Sabor"
]
}
}
Variables:
{
"data": {
"timeSeries": {
"labels": [
"2023-08-03T00:00:00.000Z",
"2023-08-04T00:00:00.000Z",
"2023-08-05T00:00:00.000Z",
"2023-08-06T00:00:00.000Z",
"2023-08-07T00:00:00.000Z",
"2023-08-08T00:00:00.000Z",
"2023-08-09T00:00:00.000Z"
],
"values": ["0", "1654.75", "4288.5", "3751", "3994", "4311", "1655.75"]
}
}
}
You can replicate this query on GraphQL Explorer by logging in here.
You can learn more about how to structure a Time Series query here.
2. How much revenue did a particular taco generate?​
In this example, we demonstrate how to query the revenue generated by a specific taco, "Shrimp," using a relative time range for the current month.
- GraphQL Query
- GraphQL Variables
- JSON Response
query TimeSeriesExample2($input: TimeSeriesInput!) {
timeSeries(input: $input) {
labels
values
}
}
{
"input": {
"metricName": "Revenue",
"granularity": "DAY",
"timeRange": {
"relative": "THIS_MONTH",
"n": null
},
"filters": [
{
"column": "taco_name",
"operator": "EQUALS",
"value": "Shrimp"
}
]
}
}
{
"data": {
"timeSeries": {
"labels": [
"2023-08-01T00:00:00.000Z",
"2023-08-02T00:00:00.000Z",
"2023-08-03T00:00:00.000Z",
"2023-08-04T00:00:00.000Z",
"2023-08-05T00:00:00.000Z",
"2023-08-06T00:00:00.000Z",
"2023-08-07T00:00:00.000Z",
"2023-08-08T00:00:00.000Z",
"2023-08-09T00:00:00.000Z",
"2023-08-10T00:00:00.000Z",
"2023-08-11T00:00:00.000Z",
"2023-08-12T00:00:00.000Z",
"2023-08-13T00:00:00.000Z",
"2023-08-14T00:00:00.000Z",
"2023-08-15T00:00:00.000Z",
"2023-08-16T00:00:00.000Z",
"2023-08-17T00:00:00.000Z",
"2023-08-18T00:00:00.000Z",
"2023-08-19T00:00:00.000Z",
"2023-08-20T00:00:00.000Z",
"2023-08-21T00:00:00.000Z",
"2023-08-22T00:00:00.000Z",
"2023-08-23T00:00:00.000Z",
"2023-08-24T00:00:00.000Z",
"2023-08-25T00:00:00.000Z",
"2023-08-26T00:00:00.000Z",
"2023-08-27T00:00:00.000Z",
"2023-08-28T00:00:00.000Z",
"2023-08-29T00:00:00.000Z",
"2023-08-30T00:00:00.000Z",
"2023-08-31T00:00:00.000Z"
],
"values": [
"0",
"0",
"0",
"1654.75",
"4288.5",
"3751",
"3994",
"4311",
"4751.75",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0"
]
}
}
}
Replicate this query in the GraphQL Explorer. More on Time Series queries here.