Lens Config Builder API - Mosaic
Understanding LensMosaicConfig in detail
- Type: Fixed value
'mosaic' - Description: Sets the chart type to mosaic, a variation of a stacked bar chart that displays the distribution of data across two categories.
- Type:
string - Description: The title of the visualization.
The dataset configuration within the Lens Config Builder API defines the source of data for a visualization.
- LensESQLDataset (
LensESQLDataset):
- Utilizes the Elasticsearch Query Language (ES|QL) for retrieving data.
- Attributes include:
esql: A string containing the ES|QL query. ES|QL is a powerful query language that allows for complex search and aggregation operations, making this dataset type particularly flexible and powerful for advanced data retrieval scenarios.
- LensDatatableDataset (
LensDatatableDataset):
- Represents data in a tabular format, suitable for direct visualization or further processing.
- This dataset type is typically used when data is already aggregated or processed and just needs to be displayed.
- LensDataviewDataset (
LensDataviewDataset):
- Targets data within a specific Elasticsearch index or data view.
- Attributes include:
index: The ID of the data view or the name of the Elasticsearch index pattern.timeFieldName(optional): The name of the field used for time-based operations, providing context for time range queries and aggregations.
- Type:
LensBreakdownConfig - Description: Configures the primary categorization of data for the mosaic chart. This breakdown specifies the main grouping of data, typically represented along one of the chart's axes. Check breakdown configuration details below.
- Type:
LensBreakdownConfig - Description: Defines the configuration for the X-axis categorization in the mosaic chart. It determines how data points are grouped along the horizontal axis, influencing the chart's layout and the distribution of stacked segments. Check breakdown configuration details below.
The breakdown configuration within the Lens Config Builder API allows developers to define how data should be segmented or aggregated in their visualizations.
The breakdown configuration in case of using ES|QL or Datatable as a datasource just takes in the field name to use as a breakdown.
When using index as a datasource, breakdown can still be a field name, in which case lens will try to choose the most appropriate option, or it could be one of the following:
- Top Values (
LensBreakdownTopValuesConfig):
- Breaks down data based on the top occurring values for a specified field.
- Attributes include
field(the field to break down by) andsize(the number of top values to display). - Ideal for pie charts, tag clouds, or any visualization where highlighting the most common or significant categories is beneficial.
- Date Histogram (
LensBreakdownDateHistogramConfig):
- Segments data over time using a specified date field.
- Attributes include
field(the date field for the histogram), andminimumInterval(the smallest interval to use, e.g.,1Mfor monthly). - Useful for time series data, showing trends over time in line charts, area charts, etc.
- Intervals (
LensBreakdownIntervalsConfig):
- Divides data into intervals based on a numeric field.
- Attributes include
field(the numeric field to create intervals from) andgranularity(the interval size). - Applicable for histograms or any visualization that benefits from numeric range segmentation.
- Filters (
LensBreakdownFiltersConfig):
- Allows for custom segmentation of data based on a collection of Elasticsearch filters.
- Attributes include an array of
filters, each with alabel(optional) and afilterstring defining the filter query. - Offers maximum flexibility in data segmentation, suitable for creating comparative visualizations across custom-defined segments.
const mosaicConfig: LensConfig = {
chartType: 'mosaic',
title: 'Mosaic Chart',
dataset: {
esql: 'from kibana_sample_data_logs | stats bytes = sum(bytes) by geo.src, geo.dest',
},
breakdown: 'geo.src',
xAxis: 'geo.dest',
};
const configBuilder = new LensConfigBuilder(dataViewsAPI, lensFormulaAPI);
const lensConfig = configBuilder.build(mosaicConfig, {
timeRange: { from: 'now-1y', to: 'now', type: 'relative' },
embeddable: true,
});
This example demonstrates configuring a mosaic chart to visualize the distribution of product sales across different regions and categories. The breakdown is set to segment data by the top 5 regions, while the xAxis config segments further by the top 10 product categories. An ESQL query aggregates sales within the specified groupings, enabling the mosaic chart to display the proportional distribution of sales across these dimensions. This type of visualization is particularly useful for identifying patterns or disparities in sales performance across different market segments.