To visualize data series with different units or magnitudes in a single line chart, add multiple y-axes. This topic describes how.
Prerequisites
-
You have created a dashboard. For more information, see Create a dashboard.
-
You have collected log data to the destination Logstore. For more information, see Overview of data collection.
-
You have configured an index. For more information, see Create an index.
Background
A line chart with multiple y-axes is useful for data series that differ significantly in magnitude. A single y-axis can obscure the trends of smaller-scale data. This example uses the following resource information and log sample:
-
Resource information
-
Project: test-demo
-
Logstore: website_log
-
Dashboard: website
-
-
Log sample

Single query scenario
This scenario visualizes the request volume from two regions: China (Shanghai) and China (Hangzhou). The blue line represents the request count for China (Shanghai), and the green line represents the request count for China (Hangzhou).
1. Add a chart
On your dashboard, click Edit. In edit mode, click .

2. Configure the chart
-
Configure general settings: In the panel on the right, configure Chart Type and query and analysis settings. In the panel on the left, set the time range, select the Logstore, and enter your query and analysis statement. Then, click Apply at the top of the page to preview the chart.
* | select __time__ - __time__ % 60 as time, count_if(region='cn-shanghai') AS count1, count_if(region='cn-hangzhou') AS count2 GROUP BY time order by time
-
Configure the y-axis: Because the request counts for the two regions have very different magnitudes, the trend for China (Hangzhou) is obscured on a single y-axis. To solve this, use the field configuration tab to add a second y-axis on the right side of the chart, scaled for the China (Hangzhou) data.

-
Result: The chart has two y-axes with different scales. The left y-axis corresponds to the request count for China (Shanghai), and the right y-axis corresponds to the request count for China (Hangzhou), as shown in the following figure.

-
Save the chart and dashboard: Click OK in the upper-right corner to save the chart. Then, click Save in the upper-right corner of the dashboard to save it.
Multiple query scenario
Two queries
This example visualizes the number of successful and failed requests per minute. The blue line represents successful requests, and the green line represents failed requests.
1. Add a chart
On your dashboard, click Edit. In edit mode, click .
2. Configure the chart
-
Configure general settings: In the panel on the right, set Chart Type to Line Chart Pro. In the panel on the left, configure the time range, Logstore, and query statements. Then, click Apply at the top of the page to preview the chart.

Query A: Counts the number of successful requests per minute.
status in [200 299] | SELECT __time__-__time__ % 60 AS Time, count(1) AS OK GROUP BY Time ORDER BY Time LIMIT 1000Query B: Counts the number of failed requests per minute.
NOT status in [200 299] | SELECT __time__-__time__ % 60 AS Time, count(1) AS ERROR, status GROUP BY Time, status ORDER BY Time LIMIT 1000 -
Configure the y-axis: Because the number of successful and failed requests differs significantly, the trend for failed requests is hard to discern on a shared y-axis. On the field configuration tab, add a y-axis on the right side of the chart for the failed requests (ERROR) series.

-
Result: The chart has two y-axes with different scales. The left y-axis is for successful requests, and the right y-axis is for failed requests, as shown in the following figure.

-
Save the chart and dashboard: Click OK in the upper-right corner to save the chart. Then, click Save in the upper-right corner of the dashboard to save it.
Three queries
This example visualizes the number of requests per minute, categorized by request duration. The blue line represents requests from 10 up to 50 seconds, the green line from 50 up to 100 seconds, and the yellow line for requests of 100 seconds or longer.
1. Add a chart
On your dashboard, click Edit. In edit mode, click .
2. Configure the chart
-
Configure general settings: In the panel on the right, set Chart Type to Line Chart Pro. In the panel on the left, configure the time range, Logstore, and query statements. Then, click Apply at the top of the page to preview the chart.

-
Query A: Counts the number of requests with a duration from 10 up to 50 seconds.
request_time in [10 50) | SELECT __time__-__time__ % 60 AS Time, count(1) AS count1, request_time GROUP BY Time, request_time ORDER BY Time LIMIT 1000 -
Query B: Counts the number of requests with a duration from 50 up to 100 seconds.
request_time in [50 100) | SELECT __time__-__time__ % 60 AS Time, count(1) AS count2, request_time GROUP BY Time, request_time ORDER BY Time LIMIT 1000 -
Query C: Counts the number of requests with a duration of 100 seconds or longer.
request_time >= 100 | SELECT __time__-__time__ % 60 AS Time, count(1) AS count3, request_time GROUP BY Time, request_time ORDER BY Time LIMIT 1000
-
-
Configure the y-axes: Because the request counts for different durations vary greatly, the trends for
count2andcount3are obscured on a shared axis. On the field configuration tab, add a separate y-axis for the results of Query B and another y-axis for the results of Query C.ImportantWhen you add two or more y-axes to the same side of the chart, you must set the y-axis > ID property to assign a unique ID to each axis.

-
Result: The chart has three y-axes, each with a different scale, corresponding to the three request duration ranges, as shown in the following figure.

-
Save the chart and dashboard: Click OK in the upper-right corner to save the chart. Then, click Save in the upper-right corner of the dashboard to save it.
References
-
You must configure a query and analysis statement to add a chart. For more information, see Query and analysis.
-
For more information about the parameters on the field configuration tab, see Field configuration.