kibana/docs/user/dashboard/lens.asciidoc
amyjtechwriter 5e8414779a
[DOCS] Inline editing in Lens (#170649)
## Summary

With the arrival of inline editing to Lens panels the [Create
visualizations](https://www.elastic.co/guide/en/kibana/current/lens.html#create-the-visualization-panel)
'Edit and delete' section has been updated. Users can now use the option
**Edit visualization** to make edits to Lens visualizations using a
flyout panel, without having to leave the dashboard and go into the Lens
application.

The [Edit
panels](https://www.elastic.co/guide/en/kibana/current/dashboard.html#edit-panels)
section on the 'Dashboards and visualizations' page has been edited as
the **Edit Lens** option has been removed from the UI.

Relates to: #166169 &
[#243](https://github.com/elastic/platform-docs-team/issues/243)
2023-11-06 15:25:03 +00:00

619 lines
23 KiB
Text

[[lens]]
=== Create visualizations with Lens
++++
<titleabbrev>Lens</titleabbrev>
++++
To create a visualization, drag the data fields you want to visualize to the workspace, then *Lens* uses visualization best practices to apply the fields and create a visualization that best displays the data.
With *Lens*, you can:
* Create area, line, and bar charts with layers to display multiple indices and chart types.
* Change the aggregation function to change the data in the visualization.
* Create custom tables.
* Perform math on aggregations using *Formula*.
* Use time shifts to compare the data in two time intervals, such as month over month.
* Add annotations and reference lines.
[float]
[[create-the-visualization-panel]]
==== Create visualizations
If you're unsure about the visualization type you want to use, or how you want to display the data, drag the fields you want to visualize onto the workspace, then let *Lens* choose for you.
If you already know the visualization type you want to use, and how you want to display the data, use the following process.
Choose the visualization type.
. Before you drag fields to the workspace, open the *Visualization type* dropdown, then select the visualization you want to use.
. To view more visualizations that *Lens* automatically created for the fields, click *Suggestions*. If one of the *Suggestions* meets your visualization needs, click *Save and return* to add it to the dashboard.
Choose the data you want to visualize.
. Drag the fields directly to the layer pane. *Lens* automatically selects the aggregation function.
. If you want to learn more about the data a field contains, click the field.
. To visualize more than one {data-source}, click *Add layer*, select the layer type, then select the {data-source}.
Edit and delete.
. Click image:dashboard/images/lens_layerActions_8.5.0.png[Actions menu to clear Lens visualization layers] on the panel, then **Edit visualization**.
. To change the aggregation *Quick function* and, click the field in the flyout.
. To delete a field, click image:dashboard/images/trash_can.png[Actions menu icon to delete a field, width=5%] next to the field.
. To duplicate a layer, click image:dashboard/images/lens_layerActions_8.5.0.png[Actions menu to duplicate Lens visualization layers] in the flyout, then select *Duplicate layer*.
. To clear the layer configuration, click image:dashboard/images/lens_layerActions_8.5.0.png[Actions menu to clear Lens visualization layers] in the flyout, then select *Clear layer*.
. Click **Apply and close**.
TIP: Use the **Edit visualization** flyout to make edits without having to leave the dashboard, or click **Edit in Lens** to make edits using the Lens application.
[float]
[[change-the-fields]]
==== Change the fields list
Change the fields list to display a different {data-source}, different time range, or add your own fields.
* To create a visualization with fields in a different {data-source}, open the {data-source} dropdown, then select the {data-source}.
+
For more information about {data-sources}, refer to <<data-views>>.
* If the fields list is empty, change the <<set-time-filter,time filter>>.
* To add fields, open the {data-source} dropdown, then select *Add a field to this {data-source}*.
+
[role="screenshot"]
image:images/lens_dataViewDropDown_8.4.0.png[Dropdown menu located next to {data-source} field with items for adding and managing fields]
+
For more information about adding fields to {data-sources} and examples, refer to <<runtime-fields>>.
[float]
[[create-custom-tables]]
==== Create custom tables
Tables are highly customizable, and provide you with text alignment, value formatting, coloring options, and more.
. From the *Visualization type* dropdown, select *Table*.
. Drag the fields you want to visualize to the workspace.
. To sort or hide the columns, click the arrow next to the column heading, then select an option.
+
All columns that belong to the same layer pane group are sorted in the table.
. To change the display options, click a *Metrics* field in the layer pane, then configure the following options:
* *Name* &mdash; Specifies the field display name.
* *Collapse by* &mdash; Aggregates all metric values with the same value into a single number.
* *Value format* &mdash; Specifies how the field value displays in the table.
* *Text alignment* &mdash; Aligns the values in the cell to the *Left*, *Center*, or *Right*.
* *Hide column* &mdash; Hides the column for the field.
* *Directly filter on click* &mdash; Turns column values into clickable links that allow you to filter or drill down into the data.
* *Summary row* &mdash; Adds a row that displays the summary value. When specified, allows you to enter a *Summary label*.
* *Color by value* &mdash; Applies color to the cell or text values. To change the color, click *Edit*.
[float]
[[drag-and-drop-keyboard-navigation]]
==== Create visualizations with keyboard navigation
To use a keyboard instead of a mouse, use the *Lens* fully accessible and continuously improved drag system.
. Select the field in the fields list or layer pane. Most fields have an inner and outer select state. The inner state opens a panel with detailed information or options.
The outer state allows you to drag the field. Tab through the fields until you get the outer state on the field.
+
[role="screenshot"]
image::images/lens_drag_drop_2.png[Lens drag and drop focus state]
. Complete the following actions:
* To select a field, press Space bar.
* To select where you want to drop the field, use the Left and Right arrows.
* To reorder the fields on the layer pane, use the Up and Down arrows.
* To duplicate an action, use the Left and Right arrows, then select the *Drop a field or click to add* field you want to use.
+
[role="screenshot"]
image::images/lens_drag_drop_3.gif[Using drag and drop to reorder]
. To confirm the action, press Space bar. To cancel, press Esc.
[float]
[[lens-formulas]]
==== Use formulas to perform math
Formulas allow you to perform math on aggregated data. The most common formulas divide two values to produce a percent.
. In the layer pane, click a field.
. Click *Formula*, then enter the formula.
+
Filter ratio example:: To filter a document set, use `kql=''`, then compare to other documents within the same grouping:
+
```
count(kql='response.status_code > 400') / count()
```
+
Week over week example:: To get the value for each grouping from the previous week, use `shift='1w'`.
+
```
percentile(system.network.in.bytes, percentile=99) /
percentile(system.network.in.bytes, percentile=99, shift='1w')
```
You are unable to combine different time shifts, such as `count(shift="1w") - count()` and `count(shift="1w") - count(shift="1m")`, with the *Top values* function.
+
Percent of total example:: To convert each grouping into a percent of the total, formulas calculate `overall_sum` for all groupings:
+
```
sum(products.base_price) / overall_sum(sum(products.base_price))
```
TIP: For detailed information on formulas, click image:dashboard/images/formula_reference.png[Formula reference icon].
. To accurately display the formula, select *Percent* from the *Value format* dropdown.
[float]
[[compare-data-with-time-offsets]]
==== Compare differences over time
Compare your real-time data to the results that are offset by a time increment. For example, you can compare the real-time percentage of a user CPU time spent to the results offset by one hour.
. In the layer pane, click the field you want to offset.
. Click *Advanced*.
. In the *Time shift* field, enter the time offset increment.
For a time shift example, refer to <<compare-time-ranges>>.
[float]
[[create-partition-charts-with-multiple-metrics]]
==== Create partition charts with multiple metrics
To create partition charts, such as pie charts, configure one or more *Slice by* dimensions to define the partitions, and a *Metric* dimension to define the size.
To create partition charts with multiple metrics, use the layer settings. Multiple metrics are unsupported for mosaic visualizations.
. In the layer pane, click image:dashboard/images/lens_layerActions_8.5.0.png[Actions menu for the partition visualization layer], then select *Layer settings*.
. Select *Multiple metrics*.
. Click *X*.
[float]
[[improve-visualization-loading-time]]
==== Improve visualization loading time
preview::[]
Data sampling allows you to improve the visualization loading time. To decrease the loading time, use a lower sampling percentage, which also decreases the accuracy.
Use low sampling percentages on large datasets.
. In the **Edit visualization** flyout, click image:dashboard/images/lens_layerActions_8.5.0.png[Actions menu for the partition visualization layer], then select *Layer settings*.
. To select the *Sampling* percentage, use the slider.
. Click *Apply and close*.
. Click **Save**.
[float]
[[add-annotations]]
==== Add annotations
preview::[]
Annotations allow you to call out specific points in your visualizations that are important, such as significant changes in the data. You can add annotations for any {data-source}, add text and icons, specify the line format and color, and more.
[role="screenshot"]
image::images/lens_annotations_8.2.0.png[Lens annotations]
Annotations support two placement types:
* *Static date* &mdash; Displays annotations for specific times or time ranges.
* *Custom query* &mdash; Displays annotations based on custom {es} queries. For detailed information about queries, check <<semi-structured-search>>.
Any annotation layer can be saved as an annotation group to the *Visualize Library* in order to reuse it in other visualizations. Any changes made to the annotation group will be reflected in all visualizations to which it is added.
Create a new annotation layer.
. In the layer pane, click *Add layer > Annotations > New annotation*.
. Select the {data-source} for the annotation.
. From the fields list, drag a field to the *Add an annotation* field.
. To use global filters in the annotation, click image:dashboard/images/lens_layerActions_8.5.0.png[Actions menu for the annotations layer], then select *Keep global filters* from the dropdown.
+
When you add the visualization to dashboards, image:dashboard/images/lens_visualizationModifierPopup_8.8.0.png[Visualization modifier popup] appears,
which allows you to view settings changes to the visualization.
Create static annotations.
. Select *Static date*.
. In the *Annotation date* field, click image:images/lens_annotationDateIcon_8.6.0.png[Annodation date icon in Lens], then select the date.
. To display the annotation as a time range, select *Apply as range*, then specify the *From* and *To* dates.
Create custom query annotations.
. Select *Custom query*.
. Enter the *Annotation query* for the data you want to display.
+
For detailed information about queries and examples, check <<semi-structured-search>>.
. Select the *Target date field*.
Specify the annotation appearance.
. Enter the annotation *Name*.
. Change the *Appearance* options for how you want the annotation to display on the visualization.
. If you created a custom query annotation, click *Add field* to add a field to the annotation tooltip.
. To close, click *X*.
Save the annotation group to the library.
. In the layer pane, on your annotation layer, click image:images/lens_saveAnnotationLayerButton_8.9.0.png[Save button on annotations layer].
. Enter the *Title*, *Description*, and add any applicable <<managing-tags,*Tags*>>.
. Click *Save group*.
Add a library annotation group to a visualization.
. In the layer pane, click *Add layer > Annotations > Load from library*.
. Select the annotation group you want to use.
[float]
[[add-reference-lines]]
==== Add reference lines
With reference lines, you can identify specific values in your visualizations with icons, colors, and other display options. You can add reference lines to any visualization type that displays axes.
For example, to track the number of bytes in the 75th percentile, add a shaded *Percentile* reference line to your time series visualization.
[role="screenshot"]
image::images/lens_referenceLine_7.16.png[Lens drag and drop focus state]
. In the layer pane, click *Add layer > Reference lines*.
. Click the reference line value, then specify the reference line you want to use:
* To add a static reference line, click *Static*, then enter the reference line value you want to use.
* To add a dynamic reference line, click *Quick functions*, then click and configure the functions you want to use.
* To calculate the reference line value with math, click *Formula*, then enter the formula.
. Specify the display options, such as *Display name* and *Icon*, then click *Close*.
[float]
[[filter-the-data]]
==== Apply filters
You can use the <<semi-structured-search, query bar>> to create queries that filter all the data in a visualization, or use the layer pane and legend filters to apply filters based on field values.
[float]
[[filter-with-the-function]]
===== Apply multiple KQL filters
With the *Filters* function, you can apply more than one KQL filter, and apply a KQL filter to a single layer so you can visualize filtered and unfiltered data at the same time.
. In the layer pane, click a field.
. Click the *Filters* function.
. Click *Add a filter*, then enter the KQL filter you want to apply.
+
To try the *Filters* function on your own, refer to <<custom-ranges,Compare a subset of documents to all documents>>.
[float]
[[filter-with-the-advanced-option]]
===== Apply a single KQL filter
With the *Filter by* advanced option, you can assign a color to each filter group in *Bar* and *Line and area* visualizations, and build complex tables. For example, to display failure rate and the overall data.
. In the layer pane, click a field.
. Click *Add advanced options*, then select *Filter by*.
. Enter the KQL filter you want to apply.
[float]
[[filter-with-legend-filters]]
===== Apply legend filters
Apply filters to visualizations directly from the values in the legend. *Bar*, *Line and area*, and *Proportion* visualizations support legend filters.
In the legend, click the field, then choose one of the following options:
* *Filter for value* &mdash; Applies a filter that displays only the field data in the visualization.
* *Filter out value* &mdash; Applies a filter that removes the field data from the visualization.
[float]
[[configure-the-visualization-components]]
==== Configure the visualization components
Each visualization type comes with a set of components that you access from the editor toolbar.
The following component menus are available:
* *Visual options* &mdash; Specifies how to display area, line, and bar chart options. For example, you can specify how to display the labels in bar charts.
* *Labels* &mdash; Specifies how to display the labels for donut charts, pie charts, and treemaps.
* *Legend* &mdash; Specifies how to display the legend. For example, you can display the legend inside the visualization and truncate the legend values.
* *Left axis*, *Bottom axis*, and *Right axis* &mdash; Specify how you want to display the chart axes. For example, add axis labels and change the orientation and bounds.
[float]
[[explore-lens-data-in-discover]]
=== Explore the data in Discover
When your visualization includes one data view, you can open and explore the visualization data in *Discover*.
To get started, click *Explore data in Discover* in the toolbar.
For more information about exploring your data with *Discover*, check out <<discover,Discover>>.
[float]
[[view-data-and-requests]]
==== View the visualization data and requests
To view the data included in the visualization and the requests that collected the data, use the *Inspector*.
. In the toolbar, click *Inspect*.
. Open the *View* dropdown, then click *Data*.
.. From the dropdown, select the table that contains the data you want to view.
.. To download the data, click *Download CSV*, then select the format type.
. Open the *View* dropdown, then click *Requests*.
.. From the dropdown, select the requests you want to view.
.. To view the requests in *Console*, click *Request*, then click *Open in Console*.
[float]
[[save-the-lens-panel]]
==== Save and add the panel
Save the panel to the *Visualize Library* and add it to the dashboard, or add it to the dashboard without saving.
To save the panel to the *Visualize Library*:
. Click *Save to library*.
. Enter the *Title* and add any applicable <<managing-tags,*Tags*>>.
. Make sure that *Add to Dashboard after saving* is selected.
. Click *Save and return*.
To save the panel to the dashboard:
. Click *Save and return*.
. Add an optional title to the panel.
.. In the panel header, click *No Title*.
.. On the *Panel settings* window, select *Show title*.
.. Enter the *Title*, then click *Save*.
[float]
[[lens-faq]]
=== Frequently asked questions
For answers to common *Lens* questions, review the following.
[discrete]
[[when-should-i-normalize-the-data-by-unit-or-use-a-custom-interval]]
.*When should I normalize the data by unit or use a custom interval?*
[%collapsible]
====
* *Normalize by unit* &mdash; Calculates the average for the interval. When you normalize the data by unit, the data appears less granular, but *Lens* is able to calculate the data faster.
* *Customize time interval* &mdash; Creates a bucket for each interval. When you customize the time interval, you can use a large time range, but *Lens* calculates the data slower.
To normalize the interval:
. In the layer pane, click a field.
. Click *Add advanced options > Normalize by unit*.
. From the *Normalize by unit* dropdown, select an option, then click *Close*.
To create a custom interval:
. In the layer pane, click a field.
. Select *Customize time interval*.
. Change the *Minimum interval*, then click *Close*.
====
[discrete]
[[what-is-the-other-category]]
.*What data is categorized as Other?*
[%collapsible]
====
The *Other* category contains all of the documents that do not match the specified criteria or filters.
Use *Other* when you want to compare a value, or multiple values, to a whole.
By default, *Group other values as "Other"* is enabled when you use the *Top values* function.
To disable *Group other values as "Other"*, click a field in the layer pane, click *Advanced*, then deselect *Group other values as "Other"*.
====
[discrete]
[[how-can-i-include-documents-without-the-field-in-the-operation]]
.*How do I add documents without a field?*
[%collapsible]
====
By default, *Lens* retrieves only the documents from the fields.
For bucket aggregations, such as *Top values*, you can add documents that do not contain the fields,
which is helpful when you want to make a comparison to the whole documentation set.
. In the layer pane, click a field.
. Click *Advanced*, then select *Include documents without this field*.
====
[discrete]
[[when-do-i-use-runtime-fields-vs-formula]]
.*When do I use runtime fields vs. formula?*
[%collapsible]
====
Use runtime fields to format, concatenate, and extract document-level fields. Runtime fields work across all of {kib} and are best used for smaller computations without compromising performance.
Use formulas to compare multiple {es} aggregations that can be filtered or shifted in time. Formulas apply only to *Lens* panels and are computationally intensive.
====
[discrete]
[[is-it-possible-to-have-more-than-one-Y-axis-scale]]
.*Can I add more than one y-axis scale?*
[%collapsible]
====
For each y-axis, you can select *Left* and *Right*, and configure a different scale.
====
[discrete]
[[why-is-my-value-with-the-right-color-using-value-based-coloring]]
.*Why is my value the incorrect color when I use value-based coloring?*
[%collapsible]
====
Here's a short list of few different aspects to check:
* Make sure the value falls within the desired color stop value defined in the panel. Color stop values are "inclusive".
* Make sure you have the correct value precision setup. Value formatters could round the numeric values up or down.
* Make sure the correct color continuity option is selected. If the number is below the first color stop value, a continuity of type `Below` or `Above and below range` is required.
* The default values set by the Value type are based on the current data range displayed in the data table.
** If a custom `Number` configuration is used, check that the color stop values are covering the current data range.
** If a `Percent` configuration is used, and the data range changes, the colors displayed are affected.
====
[discrete]
[[can-i-sort-by-multiple-columns]]
.*How do I sort by multiple columns?*
[%collapsible]
====
Multiple column sorting is unsupported, but is supported in *Discover*. For information on how to sort multiple columns in *Discover*,
refer to <<explore-fields-in-your-data,Explore the fields in your data>>.
====
[float]
[[why-my-field-is-missing-from-the-fields-list]]
.*Why is my field missing from the fields list?*
[%collapsible]
====
The following field types do not appear in the *Available fields* list:
* Full-text
* geo_point
* flattened
* object
Verify if the field appears in the *Empty fields* list. *Lens* uses heuristics to determine if the fields contain values. For sparse data sets, the heuristics are less precise.
====
[float]
[[how-to-handle-gaps-in-time-series-visualizations]]
.*What do I do with gaps in time series visualizations?*
[%collapsible]
====
When you create *Area* and *Line* charts with sparse time series data, open *Visual options* in the editor toolbar, then select a *Missing values* option.
====
[discrete]
[[is-it-possible-to-change-the-scale-of-Y-axis]]
.*Can I statically define the y-axis scale?*
[%collapsible]
====
You can set the scale, or _bounds_, for area, bar, and line charts. You can configure the bounds for all functions, except *Percentile*. Logarithmic scales are unsupported.
To configure the bounds, use the menus in the editor toolbar. Bar and area charts required 0 in the scale between *Lower bound* and *Upper bound*.
====
[discrete]
[[is-it-possible-to-show-icons-in-datatable]]
.*Is it possible to display icons in data tables?*
[%collapsible]
====
You can display icons with <<managing-data-views, field formatters>> in data tables.
====
[discrete]
[[is-it-possible-to-inspect-the-elasticsearch-queries-in-Lens]]
.*How do I inspect {es} queries in visualizations?*
[%collapsible]
====
You can inspect the requests sent by the visualization to {es} using the Inspector. It can be accessed within the editor or in the dashboard.
====
[discrete]
[[how-to-isolate-a-single-series-in-a-chart]]
.*How do I isolate a single series in a chart?*
[%collapsible]
====
For area, line, and bar charts, press Shift, then click the series in the legend. All other series are automatically deselected.
====
[discrete]
[[is-it-possible-to-use-saved-serches-in-lens]]
.*How do I visualize saved searches?*
[%collapsible]
====
Visualizing saved searches in unsupported.
====
[discrete]
[[is-it-possible-to-decrease-or-increase-the-number-of-suggestions]]
.*How do I change the number of suggestions?*
[%collapsible]
====
Configuring the *Suggestions* is unsupported.
====
[discrete]
[[is-it-possible-to-have-pagination-for-datatable]]
.*Is it possible to have pagination in a data table?*
[%collapsible]
====
Pagination in a data table is unsupported. To use pagination in data tables, create an <<types-of-visualizations,aggregation-based data table>>.
====
[discrete]
[[is-it-possible-to-select-color-for-specific-bar-or-point]]
.*How do I change the color for a single data point?*
[%collapsible]
====
Specifying the color for a single data point, such as a single bar or line, is unsupported.
====