Time series analysis with Lensedit

The tutorial uses sample data from the perspective of a shop owner looking at sales trends, but this type of dashboard works on any type of data. To create dashboard panels of the data, open the Lens visualization builder, then create the visualization panels that best display the data. Before using this tutorial, you should be familiar with the Kibana concepts.

Dashboard view

Add the data and create the dashboardedit

If you are working with your own data, you should already have an index pattern. To install the sample sales data:

  1. From the Kibana Home page, click Try our sample data.
  2. From Sample eCommerce orders, click Add data.

Then create a new dashboard:

  1. Open the main menu, then click Dashboard.
  2. On the Dashboards page, click Create dashboard.
  3. Set the time filter to Last 30 days.

Open and set up Lensedit

Lens is designed to help you quickly build visualizations for your dashboard, as shown in Build your first dashboard, while providing support for advanced usage as well.

Open the Lens editor, then make sure the correct fields appear.

  1. From the dashboard, click Create visualization.
  2. Make sure the kibana_sample_data_ecommerce index appears.

View a date histogram with a custom time intervaledit

It is common to use the automatic date histogram interval, but sometimes you want a larger or smaller interval. Lens only lets you choose the minimum time interval, not the exact time interval, for performance reasons. The performance limit is controlled by the histogram:maxBars advanced setting and the overall time range. To see hourly sales over a 30 day time period, choose one of these options:

  • View less than 30 days at a time, then use the time picker to select each day separately.
  • Increase histogram:maxBars from 100 to at least 720, which the number of hours in 30 days. This affects all visualizations and can reduce performance.
  • If approximation is okay, use the Normalize unit option. This can convert Average sales per 12 hours into Average sales per 12 hours (per hour) by dividing the number of hours.

For the sample data, approximation is okay. To use the Normalize unit option:

  1. Set the time filter to Last 30 days.
  2. From the Available fields list, drag and drop Records to the visualization builder.

    Added records to the workspace
  3. Change the Vertical axis title and display the number of orders per day.

    1. In the editor, click Count of Records.
    2. In the Display name field, enter Number of orders.
    3. Click Add advanced options > Normalize by unit.
    4. From the Normalize by unit dropdown, select per hour, then click Close.
  4. To hide the Horizontal axis label, open the Bottom Axis menu, then deselect Show.

    Bottom axis menu

    You have a bar chart that shows you how many orders were made at your store every hour.

    Orders per day
  5. Click Save and return.

Monitor multiple series within a date histogramedit

It is often required to monitor multiple series within a time interval. These series can be have similar configurations with few changes between one and another. Lens copies a function when you drag and drop it to the Drop a field or click to add field within the same group, or when you drag and drop to the Duplicate field on a different group. You can also drag and drop using your keyboard. For more information, refer to Create visualization panels with keyboard navigation.

To quickly create many copies of a percentile metric that shows distribution of price over time:

  1. From the Chart Type dropdown, select Line.

    Chart type menu with Line selected
  2. From the Available fields list, drag and drop products.price to the visualization builder.
  3. Create the 95th percentile.

    1. In the editor, click Median of products.price.
    2. From Select a function, click Percentile.
    3. In the Display name field, enter 95th, then click Close.
  4. To create the 90th percentile, duplicate the 95th percentile.

    1. Drag and drop 95th to Drop a field or click to add.
    2. Click 95th [1], then enter 90 in the Percentile field.
    3. In the Display name field enter 90th, then click Close.

      Easily duplicate the items with drag and drop
    4. Repeat the duplication steps to create the 50th and 10th percentile, naming them accordingly.
  5. To change the left axis label, open the Left Axis menu, then enter Percentiles for product prices in the Axis name field.

    Left Axis menu

    You have a line chart that shows you the price distribution of products sold over time.

    Percentiles for product prices chart
  6. Add the filter for the redirect codes.

Multiple chart types or index patterns in one visualizationedit

You can add multiple metrics to a single chart type, but if you want to overlay multiple chart types or index patterns, use a second layer. When building layered charts, it is important to match the data on the horizontal axis so that it uses the same scale. To add a line chart layer on top of an existing chart:

To compare product prices with customers traffic:

  1. From the Available fields list, drag and drop products.price to the visualization builder.

    1. In the KQL field, enter response.keyword>=500 AND response.keyword<600.
    2. From Select a function, click Average.
    3. In the Display name field, enter Average of prices, then click Close.
  2. From the Chart Type dropdown, select Area.
  3. Create a new layer to overlay with custom traffic.
  4. In the editor, click +.

    Add new layer button
  5. From the Available fields list, drag and drop customer_id to the Vertical Axis of the newly created layer.

    1. In the editor, click Unique count of customer_id.
    2. In the Display name field, enter Unique customers, then click Close.
  6. In the Series color field, enter #D36086, then click Close.
  7. For Axis side, click Right, then click Close.
  8. From the Available fields list, drag and drop order_date to the Horizontal Axis of the newly created layer.
  9. From the new layer editor, click the Chart type dropdown, then click the line chart.

    Change layer type

The visualization is done, but the legend uses a lot of space. Change the legend position to the top of the chart.

  1. From the Legend dropdown, select the top position.
  2. Click Save and return.

Compare the change in percentage over timeedit

By default, Lens shows date histograms using a stacked chart visualization, which helps understand how distinct sets of documents perform over time. Sometimes it is useful to understand how the distributions of these sets change over time. Combine filters and date histogram functions to see the change over time in specific sets of documents. To view this as a percentage, use a stacked percentage bar or area chart.

To see sales change of product by type over time:

  1. From the Available fields list, drag and drop Records to the visualization builder.
  2. Click Bar vertical stacked, then select Area percentage.

For each category type that you want to break down, create a filter.

  1. In the editor, click the Drop a field or click to add field for Break down by.
  2. From Select a function, click Filters.
  3. Add the filter for the clothing category.

    1. Click All records.
    2. In the KQL field, enter category.keyword : *Clothing.
    3. In the Label field, enter Clothing, then press Return.
  4. Add the filter for the shoes category.

    1. Click Add a filter.
    2. In the KQL field, enter category.keyword : *Shoes.
    3. In the Label field, enter Shoes, then press Return.
  5. Add the filter for the accessories category.

    1. Click Add a filter.
    2. In the KQL field, enter category.keyword : *Accessories.
    3. In the Label field, enter Accessories, then press Return.

Change the legend position to the top of the chart.

  1. From the Legend dropdown, select the top position.

    Prices share by category
    Click *Save and return*.

View the cumulative number of products sold on weekendsedit

To determine the number of orders made only on Saturday and Sunday, create an area chart, then add it to the dashboard.

  1. Open Lens.
  2. From the Chart Type dropdown, select Area.
  3. Configure the cumulative sum of the store orders.

    1. From the Available fields list, drag and drop Records to the visualization builder.
    2. From the editor, click Count of Records.
    3. From Select a function, click Cumulative sum.
    4. In the Display name field, enter Cumulative orders during weekend days, then click Close.
  4. Filter the results to display the data for only Saturday and Sunday.

    1. From the editor, click the Drop a field or click to add field for Break down by.
    2. From Select a function, click Filters.
    3. Click All records.
    4. In the KQL field, enter day_of_week : "Saturday" or day_of_week : "Sunday", then press Return.

      The KQL filter displays all documents where day_of_week matches Saturday or Sunday.

      Filter aggregation to filter weekend days
  5. To hide the legend, open the Legend menu, then click Hide.

    Legend menu

    You have an area chart that shows you how many orders your store received during the weekend.

  6. Click Bar vertical stacked, then select Area.

    Line chart with cumulative sum of orders made on the weekend
  7. Click Save and return.

View table of customers by category over timeedit

Tables are an alternative type of visualization for time series, useful when you want to read the actual values. You can build a date histogram table, and group the customer count metric by category, like the continent registered in their profile.

In Lens you can split the metric in a table leveraging the Columns field, where each data value from the aggregation is used as column of the table and the relative metric value is shown.

To build a date histogram table:

  1. Open Lens.
  2. From the Chart Type dropdown, select Table.

    1. From the Available fields list, drag and drop customer_id to the Metrics field of the editor.
    2. From the editor, click Unique count of customer_id.
    3. In the Display name field, enter Customers, then click Close.
    4. From the Available fields list, drag and drop order_date to the Rows field of the editor.
    5. From the editor Rows, click the order_date field just dropped.
  3. Select Customize time interval.
  4. Change the Minimum interval to 1 days, then click Close.

    1. In the Display name field, enter Sale, then click Close.

To split the customers count by continent:

  1. From the Available fields list, drag and drop geoip.continent_name to the Columns field of the editor.

    Table with daily customers by continent configuration
  2. Click Save and return.

Save the dashboardedit

By default the dashboard attempts to match the palette across panels, but in this case there’s no need for that, so it can be disabled.

Disable palette sync in dashboard

Now that you have a complete overview of your ecommerce sales data, save the dashboard.

  1. In the toolbar, click Save.
  2. On the Save dashboard window, enter Ecommerce sales data, then click Save.