All Products
Search
Document Center

Simple Log Service:Create a line chart with multiple y-axes

Last Updated:Oct 28, 2024

If you want to display different types of data or different scales of data in a line chart, you can add multiple y-axes to the line chart. This topic describes how to create a line chart with multiple y-axes.

Prerequisites

Background information

If data scales significantly differ, a line chart with a single y-axis cannot display data trends as expected. In this case, you can use a line chart with multiple y-axes. In this topic, the website access logs of Company A are used as an example. The following list describes the resource information and sample log:

  • Resource information

    • Project: test-demo

    • Logstore: website_log

    • Dashboard: website

  • Sample log日志样例

Create a line chart with multiple y-axes for a query statement

In this example, the number of requests that are sent from the China (Shanghai) region and the number of requests that are sent from the China (Hangzhou) region are displayed in a line chart. The blue line indicates the trend of requests that are sent from the China (Shanghai) region and the green line indicates the trend of requests that are sent from the China (Hangzhou) region.

1. Add a chart

In the upper-right corner of the dashboard page, click Edit. In edit mode, choose Add > Add Chart.

image

2. Configure a chart

  1. Configure parameters on the General Configurations tab: On the right side of the Edit Chart page, select Line Chart Pro in the Chart Types section and configure the parameters in the Query and Analysis Configurations section based on the following figure. On the left side of the Edit Chart page, configure the query time range, Logstore, and query statement for the chart. Then, click Apply in the upper part of the page to view the configuration effects of 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

    image

  2. Add and configure a second y-axis: The number of requests sent from the China (Shanghai) region and the number of requests sent from the China (Hangzhou) region significantly differ. If the two trends share the same y-axis in a line chart, the trend of requests that are sent from the China (Hangzhou) region is not obvious. In this case, you can configure the parameters on the Field Configuration tab to add a second y-axis to the right of the line chart. The second y-axis indicates the number of requests that are sent from the China (Hangzhou) region.

    image

  3. Preview configuration effects: The line chart displays two y-axes that have different scales. The left y-axis indicates the number of requests that are sent from the China (Shanghai) region and the right y-axis indicates the number of requests that are sent from the China (Hangzhou) region.

    双Y轴线图

  4. Save the chart and the dashboard: In the upper-right corner of the Edit Chat page, click OK to save the chart. In the upper-right corner of the dashboard page, click Save to save the dashboard.

Create a line chart with multiple y-axes for multiple query statements

Specify two query statements

In this example. the number of successful requests per minute and the number of failed requests per minute are displayed in a line chart. The blue line indicates the number of successful requests and the green line indicates the number of failed requests.

1. Add a chart

In the upper-right corner of the dashboard page, click Edit. In edit mode, choose Add > Add Chart.

2. Configure the chart

  1. Configure parameters on the General Configurations tab: On the right side of the Edit Chart page, select Line Chart Pro in the Chart Types section. On the left side of the Edit Chart page, configure the query time range, Logstore, and query statement for the chart. Then, click Apply in the upper part of the page to view the configuration effects of the chart.

    多Y轴线图

    • Query Statement A: Count 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 1000
    • Query Statement B: Count 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
  2. Add and configure a second y-axis: The numbers of successful and failed requests significantly differ. If the two trends share the same y-axis in a line chart, the trend of failed requests is not obvious. In this case, you can configure the parameters on the Field Configuration tab to add a second y-axis to right of the line chart. The second y-axis indicates the number of failed requests.

    多Y轴线图

  3. Preview configuration effects: The line chart displays two y-axes that have different scales. The left y-axis indicates the number of successful requests and the right y-axis indicates the number of failed requests.

    多Y轴线图

  4. Save the chart and the dashboard: In the upper-right corner of the Edit Chat page, click OK to save the chart. In the upper-right corner of the dashboard page, click Save to save the dashboard.

Specify three query statements

In this example, the numbers of requests by request duration within a minute are displayed in a line chart. The blue line indicates the trend of requests whose duration ranges from 10 to 50 seconds, the green line indicates the trend of requests whose duration ranges from 50 to 100 seconds, and the yellow line indicates the trend of requests whose duration is longer than 100 seconds.

1. Add a chart

In the upper-right corner of the dashboard page, click Edit. In edit mode, choose Add > Add Chart.

2. Configure the chart

  1. Configure parameters on the General Configurations tab: On the right side of the Edit Chart page, select Line Chart Pro in the Chart Types section. On the left side of the Edit Chart page, configure the query time range, Logstore, and query statement for the chart. Then, click Apply in the upper part of the page to view the configuration effects of the chart. 多Y轴线图

    • Query Statement A: Count the number of requests whose duration ranges from 10 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 Statement B: Count the number of requests whose duration ranges from 50 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 Statement C: Count the number of requests whose duration is longer than 100 seconds.

      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
  2. Add and configure two y-axes: The numbers of requests by request duration significantly differ. If the three trends share the same y-axis in a line chart, the trends of count2 and count3 are not obvious. In this case, you can configure parameters on the Field Configuration tab to add a y-axis for the results of Query Statement B and add a y-axis for the results of Query Statement C.

    Important

    If you add two or more y-axes on the same side, you must configure an ID for each y-axis to differentiate the y-axes.

    多Y轴线图

  3. Preview configuration effects: The line chart displays three y-axes that have different scales. The three y-axes correspond to count1, count2, and count3.多Y轴线图

  4. Save the chart and the dashboard: In the upper-right corner of the Edit Chat page, click OK to save the chart. In the upper-right corner of the dashboard page, click Save to save the dashboard.

References