From 8248d2254295878e89d5ba1e15b659bf61f7b189 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 28 Mar 2019 17:04:30 -0600 Subject: [PATCH] added info about using dashboard variables, resolves #9 --- .../v2.0/visualize-data/variables/_index.md | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/content/v2.0/visualize-data/variables/_index.md b/content/v2.0/visualize-data/variables/_index.md index 2889b558a..211240158 100644 --- a/content/v2.0/visualize-data/variables/_index.md +++ b/content/v2.0/visualize-data/variables/_index.md @@ -17,21 +17,47 @@ without having to edit the queries, making it easy to interact with your dashboa Variables are scoped by organization. ## Use dashboard variables -- Variables are stored in a `v` object associated with each dashboard. - Variables are references using dot-notation (`v.variableName`). -- In the Cell Editor and Data explorer, available variables are listed in the variables tab. - Must use the script builder. Click on a variable to input into your script. - Hover over the variable in the variables tab to select a value for the current query. - +Both [custom dashboard variables](#manage-custom-variables) and [predefined dashboard variables](#predefined-dashboard-variables) +are stored in a `v` object associated with each dashboard. +Reference each variable using dot-notation (e.g. `v.variableName`). -## Predefined dashboard variables - -##### v.timeRangeStart - -##### v.timeRangeStop - -##### v.windowPeriod +```js +from(bucket: v.bucket) + |> range(start: v.timeRangeStart, stop: v.timeRangeStart) + |> filter(fn (r) => r._measurement == v.measurement and r._field == v.field) + |> aggregateWindow(every: v.windowPeriod, fn: mean) +``` ## Manage custom variables +As you build queries, In the Cell Editor and Data explorer, available variables are listed in the variables tab. +Must use the script builder. Click on a variable to input into your script. +Hover over the variable in the variables tab to select a value for the current query. {{< children >}} + +## Predefined dashboard variables +The InfluxDB provides the following predefined dashboard variables: + +#### v.timeRangeStart +Specifies the beginning of the queried time range. +This variable is typically used to define the [`start` parameter](/v2.0/reference/flux/functions/built-in/transformations/range#start) +of the `range()` function. + +The **Time Range** selector defines the value of this variable. + +#### v.timeRangeStop +Specifies the end of the queried time range. +This variable is typically used to define the [`stop` parameter](/v2.0/reference/flux/functions/built-in/transformations/range#stop) +of the `range()` function. + +The **Time Range** selector defines the value of this variable. +It defaults to `now`. + +#### v.windowPeriod +Specifies the period of windowed data. +This variable is typically used to define the `every` or `period` parameter of the +[`window()` function](/v2.0/reference/flux/functions/built-in/transformations/window) +in data aggregation operations. + +The value of this variable is calculated by dividing the total time within the displayed +time range by the dashboard refresh interval (defined by the **Refresh** dropdown).