Chart SQL query results

Preview

This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

This document describes how to chart the results ofSQL queries thatyou run on theLog Analytics page. Charts can help you identify patterns andtrends in your data. This document also describes how to save your chart to acustom dashboard.

The following screenshot displays the results of anexample query, which is described later in this document.The screenshot displays the status reported by spans, after aggregating theresponses by time and by theservice_name:

Example chart illustrating a breakdown by service name.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Observability API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Observability API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  8. To get the permissions that you need to load theLog Analytics page, write and run queries onyour trace data, and to save charts on custom dashboards, ask your administrator to grant you the following IAM roles:

    • Observability View Accessor (roles/observability.viewAccessor) on the observability views that you want to query. This role supports IAM conditions, which let you restrict the grant to a specific view. If you don't attach a condition to the role grant, then the principal can access all observability views.
    • Logs Viewer (roles/logging.viewer) on your project.
    • Monitoring Editor (roles/monitoring.editor) on your project.

    For more information about granting roles, seeManage access to projects, folders, and organizations.

    You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Select the data to chart

To configure what data to display on a chart, build a query by usingSQL.When you select theChart tab, a chart displays your queryresults. After the query has been run and a chart has been generated, you cancustomize the chart configuration by changing the chart type, and selectingcolumns to view different data.

To view your query results as a chart, run a query by doing the following:

  1. In the Google Cloud console, go to theLog Analytics page:

    Go toLog Analytics

    If you use the search bar to find this page, then select the result whose subheading isLogging.

  2. In theQuery pane, enter a query and then clickRun.

  3. After the query has completed, in theResults tab, select how you want to view your query results:

    • Table: Tabular format only.

    • Chart: Chart format only

    • Both: Chart and tabular format.

      After you select how to view your query results, you can configure anyfields for the selected visualization, and then save the query and resultsto a custom dashboard. The saved format is tabular when you've selectedtheTable option. Otherwise, the format is a chart.

      For charts, the visualization options let you select the chart type,and select which rows and columns are charted. For more informationabout the chart configuration, seeCustomize chart configuration.

Customize chart configuration

You can customize the chart configuration by changing the chart type, selectingthe dimension and measure to chart, and by applying a breakdown. TheDimension is used to group or categorize rows and is the X-axis value. TheMeasure, or the Y-axis value, is a data series that is plotted against theY-axis.

Change chart type

You can select from the following chart types, depending on what kind of rowsand columns you selected as the dimension and measure, and how you want thatdata to be visualized.

  • Bar chart (default) :Bar charts plot data on two axes. If your chart uses a category or stringas the dimension, then you can set the chart configuration for a bar chart tohorizontal or vertical, where the dimension and measure axes are swapped.

  • Line chart:Line charts can be used to show data changes over time. When you use a linechart, each time series is shown by a different line that corresponds tothe measure(s) you have selected.

    If your X-axis is time-based, each data point is placed at the beginning ofa time interval. Each data point is connected by linear interpolation.

  • Stacked area chart:An area chart is based on a line chart, and the area below each line isshaded. In area charts, the data series are stacked. For example, if you havetwo identical series, the series overlaps in a line chart, but theshaded area is stacked in an area chart.

  • Pie or donut chart:A pie chart shows how categories in a dataset relate to the whole dataset,by using a circle to represent the whole dataset and wedges in the circleto represent the categories in the dataset. The size of a wedgeindicates how much, often as a percentage, the category contributes tothe whole.

  • Table:A table shows one row for each row in the query result. The columns in thetable are defined by theSELECT clause. If you plan to display datain tabular form on a dashboard, then use aLIMIT clause to restrict thenumber of rows in the result be less than a few hundred.

  • Gauge or scorecard:Gauges and scorecards provide you with the most recent value along witha green, amber, or red indicationbased on how that value compares to a set of thresholds.Unlike gauges, which only shows information about the most recentvalue, scorecards can also include information about past values.

    Gauges and scorecards can only display the query result when the queryresult contains at least one row, and that row contains a column with atimestamp and a column with numeric data. The query result can containmultiple rows and more than two columns.

    If you want to perform the time-based aggregation as part of your query,then do the following:

    • Configure your query to aggregate data over a time interval, to orderthe results by descending timestamps, and to limit the number ofrows in the results. You can use theLIMIT clause or use thetime range selector to limit the number of rows in the query result.

      For example, the following queries your trace data, and it aggregatesthe data over one-hour intervals, applies a limit, and sorts theresults:

      SELECTTIMESTAMP_TRUNC(start_time,HOUR)AShour,COALESCE(JSON_VALUE(resource.attributes,'$."service.name"'),JSON_VALUE(attributes,'$."service.name"'),JSON_VALUE(attributes,'$."g.co/gae/app/module"'))ASservice_name,status.codeASstatus,COUNT(*)AScountFROM`PROJECT_ID.LOCATION._Trace.Spans._AllSpans`GROUPBYhour,service_name,statusORDERBYhourDESCLIMIT1000

      The following describes the meaning of the fields in the previousexpression:

      • PROJECT_ID: The identifier of the project.
      • LOCATION: The location of the observability bucket. Youmust use theus location.

      The previous query was used to generate the figure shown at thebeginning of this document. That figure also shows the chartconfiguration.

    • Set theDimension to match the column that reports the time-unit.For example, if your query aggregates data by one hour and creates acolumn namedhour, then set theDimension menu tohour.

    • SelectDisable interval because your query already specifies theaggregation interval. In the example, this interval is one hour.

    • Set theMeasure to the numeric column, and set the function tonone.

      Note: If your query performs time-based aggregation, then make sure thatyou follow the previous guidance. Other settings result in both your queryand Log Analytics performing aggregation operations, which results in thegauge or scorecard displaying unexpected values.

    If you want to rely on Log Analytics to perform the time-based aggregation foryou, then do the following:

Change dimension and measure

You can choose which rows and columns are charted by selecting the dimensionand measure fields.

Note: If your query results contain a column that has long strings, such aserror messages, and you select that column to be the dimension orbreakdown, then your chart might have errors or unexpected values.

Add a breakdown

Note: If your chart contains more than one measure, then you can't add abreakdown.

To split a single data series into multiple data series based on another column, add a breakdown.

When you select a breakdown, choose columns that contain a smallnumber of short and meaningful labels, likeregion_name, instead of fieldsthat might contain a large number of strings or long strings, liketextPayload.

For example, the following chart displays the number of spans created byeach service, along with the data broken down by the span name:

Example dashboard showing usage of your Cloud Storage buckets.

Save a chart to a custom dashboard

After a chart is generated from your query, you can save that chart to acustom dashboard. Custom dashboards let youdisplay and organize information that is useful to you by using a variety ofwidget types. These dashboards also let you define variables, which aredashboard-level filters that apply only to specific widgets. To apply avariable to a widget, you must modify the query. For more information, seeApply a variable to a widget.

A dashboard displays a warning message for a widget that contains a SQL querywhen the query runs on the BigQuery engine and the queriedresources aren't in the same ownership boundary. Ownership boundaries aredetermined by several factors, one of which is the hierarchy ofthe resources the query uses. To prevent these warnings,Set up a service perimeter.

To save your chart to a dashboard, do the following:

  1. In the Google Cloud console, go to theLog Analytics page:

    Go toLog Analytics

    If you use the search bar to find this page, then select the result whose subheading isLogging.

  2. Run a query to generate a chart, then clickSave chart in theChart tab.

  3. In theSave to dashboard dialog, enter a title for your chart and select the dashboard where you want to save the chart to.

  4. Optional: To view the custom dashboard, in the toast, clickView dashboard.

To view a list of custom dashboards that contain charts generated bySQL queries, go to theSave Chart button and clickMenu.

Edit a chart saved to a custom dashboard

You can modify a chart after it has been saved to a dashboard. For moreinformation, seeModify a widget's configuration.In theConfigure widget dialog, you can do the following:

  • Change the data you query.
  • Edit the query that is used to generate a chart.
  • Customize the chart configuration to visualize different data.

Limitations

  • If your Google Cloud project is in a folder that uses Assured Workloads,then the charts that you generate can't be displayed on a custom dashboard.

  • Dashboard-level filters don't apply to charts generated from a SQL query.

  • Selected columns must have at least one row with a non-null value.

  • If you save a query and customize the chart configuration, then the customchart configuration is not saved.

  • If your query already contains aggregations, then the generated chart mightbe different due to additional aggregation that is automatically appliedby Log Analytics.

  • JSON paths must be cast to strings or numbers in order to be charted.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.