docs-v2/content/v2.0/visualize-data/variables/create-variable.md

73 lines
2.7 KiB
Markdown
Raw Normal View History

2019-03-28 22:31:27 +00:00
---
title: Create a variable
seotitle: Create a dashboard variable
description: Create dashboard variables in the Data Explorer, from the Organization page, or import a variable.
menu:
v2_0:
parent: Use and manage variables
weight: 201
"v2.0/tags": [variables]
---
2019-07-22 19:03:48 +00:00
Create dashboard variables in the Data Explorer, from the Settings section, or import a variable.
**Variable names must be unique.**
2019-03-28 22:31:27 +00:00
2019-07-22 19:03:48 +00:00
There are multiple variable types that provide different means of populating your list of variable values.
2019-03-28 23:32:26 +00:00
_For information about variable types, see [Variable types](/v2.0/visualize-data/variables/variable-types/)._
{{% note %}}
##### Reserved keywords
The following names cannot be used as dashboard variables because they are reserved keywords in Flux:
`and`, `import`, `not`, `return`, `option`, `test`, `empty`, `in`, `or`, `package`, and `builtin`.
{{% /note %}}
2019-07-22 19:03:48 +00:00
## Create a variable in the Data Explorer
2019-03-28 22:31:27 +00:00
{{% note %}}
2019-07-22 19:03:48 +00:00
InfluxData recommends using the Data Explorer to create
[Query dashboard variables](/v2.0/visualize-data/variables/variable-types/#query).
2019-07-22 19:03:48 +00:00
The [Table visualization type](/v2.0/visualize-data/visualization-types/table/) and
2019-11-20 19:44:41 +00:00
**View Raw Data** option to provide human-readable query results.
{{% /note %}}
2019-03-28 22:31:27 +00:00
1. Click the **Data Explorer** icon in the sidebar.
{{< nav-icon "data-explorer" >}}
2019-03-28 22:31:27 +00:00
2019-07-22 19:03:48 +00:00
2. Use the **Query Builder** or **Script Editor** to build a query.
3. Use the [Table visualization type](/v2.0/visualize-data/visualization-types/table/)
or enable the **View Raw Data** option to view human-readable query results.
2019-03-28 22:31:27 +00:00
4. Click **Save As** in the upper right.
5. In the window that appears, select **Variable**.
6. Enter a name for your variable in the **Name** field.
7. Click **Create**.
2019-07-22 19:03:48 +00:00
_For information about common Query variables, see [Common variable queries](/v2.0/visualize-data/variables/common-variables/)._
## Create a variable in the Settings section
2019-03-28 22:31:27 +00:00
2019-04-10 18:39:14 +00:00
1. Click the **Settings** icon in the navigation bar.
2019-03-28 22:31:27 +00:00
{{< nav-icon "settings" >}}
2019-04-10 18:39:14 +00:00
2. Select the **Variables** tab.
2019-11-20 19:44:41 +00:00
3. Enter a name for your variable.
4. Select your variable type. For details on each type, see [Variable types](/v2.0/visualize-data/variables/variable-types/).
5. Enter the appropriate variable information.
6. Click **Create**.
2019-03-28 22:31:27 +00:00
## Import a variable
2019-07-22 19:03:48 +00:00
InfluxDB lets you import variables exported from InfluxDB in JSON format.
2019-03-28 22:31:27 +00:00
2019-07-22 19:03:48 +00:00
1. Click the **Settings** icon in the navigation bar.
2019-03-28 22:31:27 +00:00
2019-07-22 19:03:48 +00:00
{{< nav-icon "settings" >}}
2019-03-28 22:31:27 +00:00
2019-07-22 19:03:48 +00:00
2. Select the **Variables** tab.
3. Click the **{{< icon "plus" >}} Create Variable** drop-down menu and select **Import Variable**.
2019-07-22 19:03:48 +00:00
4. In the window that appears:
- Select **Upload File** to drag and drop or select a file.
2019-07-22 19:03:48 +00:00
- Select **Paste JSON** to paste in JSON.
6. Click **Import JSON as Variable**.