|
| 1 | +--- |
| 2 | +navigation_title: Line charts |
| 3 | +applies_to: |
| 4 | + stack: ga |
| 5 | + serverless: ga |
| 6 | +description: Instructions and best practices for building line charts with Kibana Lens in Elastic. |
| 7 | +--- |
| 8 | + |
| 9 | +# Build line charts with {{kib}} |
| 10 | + |
| 11 | +Line charts are ideal for visualizing how metrics evolve over time, spotting seasonal patterns, and detecting spikes or regressions at a glance. Use them for KPIs like response time, error rate, throughput, or utilization, and compare multiple series or previous periods on the same chart. |
| 12 | + |
| 13 | +You can create line charts from any numeric data using aggregations (for example, `Average`, `Percentile`, `Counter rate`) or with custom [formulas](../lens.md#lens-formulas). Line charts typically use a date histogram on the x-axis, but they can also plot over numeric or ordinal buckets. |
| 14 | + |
| 15 | +You can create line charts in {{kib}} using [**Lens**](../lens.md). |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## Build a line chart |
| 20 | + |
| 21 | +To build a line chart: |
| 22 | + |
| 23 | +::::::{stepper} |
| 24 | + |
| 25 | +:::::{step} Access Lens |
| 26 | +**Lens** is {{kib}}'s main visualization editor. You can access it: |
| 27 | +- From a dashboard: On the **Dashboards** page, open or create the dashboard where you want to add a line chart, then add a new visualization. |
| 28 | +- From the **Visualize library** page by creating a new visualization. |
| 29 | +::::: |
| 30 | + |
| 31 | +:::::{step} Set the visualization to Line |
| 32 | +New visualizations default to **Bar**. |
| 33 | + |
| 34 | +Using the visualization type dropdown, select **Line**. |
| 35 | +::::: |
| 36 | + |
| 37 | +:::::{step} Define the data to show |
| 38 | +1. Select the {{data-source}} that contains your data. |
| 39 | +2. Drag a time field (for example, `@timestamp`) to the **X-axis** to create a `Date histogram` (recommended for time series). |
| 40 | +3. Drag a numeric field (for example, `response_time`) to the **Y-axis**. {{kib}} suggests a function like `Average`, `Count`, or `Counter rate`. You can change it or use a [formula](../lens.md#lens-formulas). |
| 41 | +4. Optionally: |
| 42 | + - Add more numeric fields to create additional series, or drag a categorical field (for example, `geo.country`) to **Break down by** to split the series. |
| 43 | + - Add a [reference line](../lens.md#reference-lines) to mark targets or SLOs. |
| 44 | + - Adjust axes, legends, and series styles from the chart settings. |
| 45 | + |
| 46 | +Refer to [](#settings) for line chart configuration options. |
| 47 | +::::: |
| 48 | + |
| 49 | +:::::{step} Customize the chart to follow best practices |
| 50 | +Tweak the appearance of the chart to your needs. Consider the following best practices: |
| 51 | + |
| 52 | +**Reduce cognitive load** |
| 53 | +:: Keep the number of concurrent series manageable. If you need many series, use filters, small multiples, or focus on top N. |
| 54 | + |
| 55 | +**Use color consistently** |
| 56 | +:: Use consistent palettes for related series. Prefer EUI visualization palettes for accessibility and consistency. See [Dashboard good practices](https://eui.elastic.co/docs/dataviz/dashboard-good-practices/). |
| 57 | + |
| 58 | +**Label clearly** |
| 59 | +:: Add descriptive axis titles and units. Format values (for example, milliseconds, percent) for readability. |
| 60 | + |
| 61 | +**Structure dashboards for quick scanning** |
| 62 | +:: Place high-level KPIs at the top and detailed breakdowns below. Group related charts in rows and align legends consistently. See [Dashboard good practices](https://eui.elastic.co/docs/dataviz/dashboard-good-practices/). |
| 63 | +::::: |
| 64 | + |
| 65 | +:::::{step} Save the chart |
| 66 | +- If you accessed Lens from a dashboard, select **Save and return** to save the visualization and add it to that dashboard, or select **Save to library** to add the visualization to the Visualize library. |
| 67 | +- If you accessed Lens from the Visualize library, select **Save**. The Save menu lets you also add the visualization to a dashboard and to the Visualize library. |
| 68 | +::::: |
| 69 | + |
| 70 | +:::::: |
| 71 | + |
| 72 | +## Advanced line scenarios |
| 73 | + |
| 74 | +### Compare with a previous period [line-previous-period] |
| 75 | +Compare the current value with a prior time range using time shift to quickly see deltas. |
| 76 | + |
| 77 | +1. Create a line series for the current value, for example: `average(response_time)`. |
| 78 | +2. Add a second series with a time shift, for example: `average(response_time, shift='1w')`. |
| 79 | +3. Use the legend labels to clarify “Current” vs “Previous (1w)”. |
| 80 | + |
| 81 | +| Single series | With previous period | |
| 82 | +|---|---| |
| 83 | +|  |  | |
| 84 | + |
| 85 | +::::{tip} |
| 86 | +You can also compute the relative change as a separate series using a formula, for example: |
| 87 | +`(average(response_time) - average(response_time, shift='1w')) / average(response_time, shift='1w')` |
| 88 | +:::: |
| 89 | + |
| 90 | +### Smooth noisy series with moving average [line-moving-average] |
| 91 | +Noisy metrics (for example, per-minute throughput) can be smoothed: |
| 92 | + |
| 93 | +1. Add a series such as `sum(bytes)`. |
| 94 | +2. Add a second series using `moving_average(sum(bytes), window=5)`. |
| 95 | +3. Keep both series visible (raw vs smoothed) or show only the smoothed one. |
| 96 | + |
| 97 | +### Highlight thresholds with reference lines [line-reference-lines] |
| 98 | +Use reference lines to indicate SLOs or alert thresholds. |
| 99 | + |
| 100 | +1. In the chart settings, add a **Reference line** (for example, `200` ms or `0.95`). |
| 101 | +2. Give it a label (for example, `Target` or `SLO`), choose a color, and optionally a band. |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +### Handle gaps and missing data [line-fit-missing] |
| 106 | +Irregular data or sparse sampling can create breaks. Use “fit missing values” to interpolate or extend: |
| 107 | + |
| 108 | +1. Open the series settings. |
| 109 | +2. Set **Missing values** to `Linear`, `Carry`, or `Zero`, depending on the use case. |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +### Choose the right axis and scale [line-axis] |
| 114 | +For multi-metric charts, make sure the scale communicates intent: |
| 115 | + |
| 116 | +- Use the **Left** axis for primary series, and enable a **Right** axis only when needed for different units. |
| 117 | +- Use **log** scale for heavy-tailed distributions, or **percentage** mode for normalization. |
| 118 | + |
| 119 | +| Left axis | Bottom axis | |
| 120 | +|---|---| |
| 121 | +|  |  | |
| 122 | + |
| 123 | +## Line chart settings [settings] |
| 124 | + |
| 125 | +Customize your line chart to display exactly the information you need, formatted the way you want. |
| 126 | + |
| 127 | +### Y-axis series [y-axis-series] |
| 128 | + |
| 129 | +**Value** |
| 130 | +:: The metric to plot. When you drag a field onto the chart, {{kib}} suggests a function based on the field type. You can change it and use aggregation functions like `Average`, `Sum`, `Percentile`, `Counter rate`, or create custom calculations with formulas. Refer to [](/explore-analyze/visualize/lens.md#lens-formulas) for examples, or to the {icon}`documentation` **Formula reference** available from Lens. |
| 131 | + |
| 132 | + :::{include} ../../_snippets/lens-value-advanced-settings.md |
| 133 | + ::: |
| 134 | + |
| 135 | +**Appearance** |
| 136 | +:: Define the series style, including: |
| 137 | + - **Name**: Customize the legend label with a descriptive name. |
| 138 | + - **Series type**: Line or area variants, with optional stacking for area. |
| 139 | + - **Line/marker style**: Toggle lines, points, or both; adjust line width. |
| 140 | + - **Missing values**: Choose how to display gaps (Off, Linear, Carry, Zero). |
| 141 | + - **Color**: Select a palette or specific color per series. |
| 142 | + |
| 143 | +### X-axis buckets [x-axis-buckets] |
| 144 | + |
| 145 | +**Data** |
| 146 | +:: Buckets define the x-axis. Commonly a `Date histogram` on `@timestamp`, but you can also use numeric histograms or terms (for small category counts). |
| 147 | + |
| 148 | +**Appearance** |
| 149 | +:: Axis title, tick density, and value formatting (for example, time format, numeric precision). |
| 150 | + |
| 151 | +### Breakdown (split series) [breakdown-options] |
| 152 | + |
| 153 | +**Data** |
| 154 | +:: Split the chart into multiple series based on a categorical field. Each unique value creates its own series. You can optionally specify the following options: |
| 155 | + |
| 156 | + - **Number of values**: Limit to top N. |
| 157 | + - **Rank by**: Choose the ranking metric. |
| 158 | + - **Rank direction**: Ascending or descending. |
| 159 | + |
| 160 | + :::{include} ../../_snippets/lens-breakdown-advanced-settings.md |
| 161 | + ::: |
| 162 | + |
| 163 | +**Appearance** |
| 164 | +:: Define how the series are displayed: |
| 165 | + - **Legend position**: Show legend and choose its placement. |
| 166 | + - **Color palette**: Ensure consistent colors across dashboards. |
| 167 | + |
| 168 | +### Reference lines [reference-line-settings] |
| 169 | +Add horizontal or vertical markers for targets, limits, or thresholds. Configure: |
| 170 | +- **Value** (static or formula), **Label**, **Color**, and optional bands. |
| 171 | + |
| 172 | +### General layout [appearance-options] |
| 173 | +When creating or editing a visualization, open the {icon}`brush` panel to adjust: |
| 174 | + |
| 175 | +- **Title and subtitle**: Add context like “Last 24 hours”. |
| 176 | +- **Axes**: Set titles, units, scale (linear/log/percentage), and grid lines. |
| 177 | +- **Legend**: Position and truncation. |
| 178 | +- **Tooltip**: Synchronized tooltips are enabled by default across panels on dashboards. |
| 179 | + |
| 180 | +## Line chart examples |
| 181 | + |
| 182 | +**Website response time (p95) with target** |
| 183 | +:: Monitor user experience and enforce SLO: |
| 184 | + |
| 185 | + * **Title**: "Response time (p95)" |
| 186 | + * **X-axis**: `Date histogram` on `@timestamp` |
| 187 | + * **Y-axis**: `percentile(response_time, percentile=95)` |
| 188 | + * **Format**: `Duration` |
| 189 | + * **Reference line**: `200` ms labeled `SLO` |
| 190 | + |
| 191 | +  |
| 192 | + |
| 193 | +**Requests throughput with moving average** |
| 194 | +:: Smooth per-minute variation while preserving overall trend: |
| 195 | + |
| 196 | + * **Title**: "Requests per minute" |
| 197 | + * **X-axis**: `Date histogram` |
| 198 | + * **Y-axis (raw)**: `counter_rate(requests)` |
| 199 | + * **Y-axis (smoothed)**: `moving_average(counter_rate(requests), window=5)` |
| 200 | + * **Legend**: "Raw", "5-interval MA" |
| 201 | + |
| 202 | +  |
| 203 | + |
| 204 | +**Error rate vs previous week** |
| 205 | +:: Quickly assess regressions: |
| 206 | + |
| 207 | + * **Title**: "Error rate (now vs previous week)" |
| 208 | + * **X-axis**: `Date histogram` |
| 209 | + * **Series A**: `count(kql='response.code >= 500') / count()` |
| 210 | + * **Format**: `Percent` |
| 211 | + * **Series B**: `count(kql='response.code >= 500', shift='1w') / count(shift='1w')` |
| 212 | + * **Format**: `Percent` |
| 213 | + * **Legend**: "Current", "Previous (1w)" |
| 214 | + |
| 215 | +  |
| 216 | + |
| 217 | +**Throughput by top countries** |
| 218 | +:: Break down by top N categories: |
| 219 | + |
| 220 | + * **Title**: "Requests per minute by country" |
| 221 | + * **X-axis**: `Date histogram` |
| 222 | + * **Y-axis**: `counter_rate(requests)` |
| 223 | + * **Break down by**: `geo.country` |
| 224 | + * **Number of values**: `10` |
| 225 | + * **Rank by**: `Custom` > `Count` > `Records` |
| 226 | + |
| 227 | +  |
| 228 | + |
| 229 | +--- |
| 230 | + |
| 231 | +For layout, hierarchy, and color guidance on dashboards, see EUI’s [Dashboard good practices](https://eui.elastic.co/docs/dataviz/dashboard-good-practices/). |
| 232 | + |
| 233 | + |
0 commit comments