Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Practical guidelines
  • Web service
    • All tutorials
    • Static website in Object Storage
    • Website on LAMP or LEMP stack
    • Fault-tolerant website with load balancing by Network Load Balancer
    • Fault-tolerant website using DNS load balancing
    • Joomla website with PostgreSQL
    • WordPress website
    • WordPress website on a MySQL database
    • Transferring a WordPress website from a different hosting provider to Yandex Cloud
    • 1C-Bitrix website
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment of service versions
  • Online stores
    • All tutorials
    • 1C-Bitrix online store
    • Opencart online store
  • Data archive
    • All tutorials
    • Single-node file server
    • Configuring an SFTP server on Centos 7
    • Backup to Object Storage via Acronis Backup
    • Backup to Object Storage via CloudBerry Desktop Backup
    • Backup to Object Storage via Duplicati
    • Backup to Object Storage via Bacula
    • Backup to Object Storage via Veritas Backup Exec
    • Digitizing archives in Yandex Vision
  • Test environment
    • All tutorials
    • Testing applications with GitLab
    • Creating test VMs using GitLab CI
    • High-performance computing on preemptible VMs
    • Emulating multiple IoT devices
    • gRPC service load testing
    • Using Phantom to run a fixed-load HTTPS test
  • Performing infrastructure management
    • All tutorials
    • Getting started with Terraform
    • Uploading Terraform states to Object Storage
    • Getting started with Packer
    • Automating VM image builds using Jenkins
    • Continuous deployment of containerized applications using GitLab
    • Creating a cluster of 1C:Enterprise Linux servers with a Managed Service for PostgreSQL cluster
    • Creating a cluster of 1C:Enterprise Windows servers with MS SQL Server
    • Migrating to Yandex Cloud using Hystax Acura
    • Emergency recovery in Yandex Cloud using Hystax Acura
    • Configuring a fault-tolerant architecture in Yandex Cloud
  • Building a data platform
    • All tutorials
    • Syncing MySQL data using Yandex DataTransfer
    • Using schema registries with Managed Service for Apache Kafka®
      • Overview
      • Using Managed Schema Registry with Yandex Managed Service for Apache Kafka®
      • Using Confluent Schema Registry with Yandex Managed Service for Apache Kafka®
    • Delivering data using Debezium
    • Migrating databases from Yandex Managed Service for MySQL to MySQL
    • Migrating databases to Managed Service for Microsoft SQL Server
    • Configuring Yandex Cloud DNS for accessing managed database clusters from other cloud networks
    • Configuring Kafka Connect for Yandex Managed Service for Apache Kafka® clusters
  • Windows in Yandex Cloud
    • All tutorials
    • Deploying Active Directory
    • Deploying Microsoft Exchange
    • Deploying Remote Desktop Services
    • Deploying an Always On availability group
    • Deploying an Always On availability group with an internal network load balancer
    • Deploying Remote Desktop Gateway
  • Network routing
    • All tutorials
    • Routing through a NAT instance
    • Creating a VPN tunnel
    • Installing a Cisco CSR1000v virtual router
    • Installing a Mikrotik CHR virtual router
    • Creating a VPN connection using OpenVPN
  • Data visualization and analytics
    • All tutorials
    • Visualizing data from a CSV file
    • Creating and publishing a chart with a map of Moscow from a CSV file
    • Analyzing a store chain's sales based on data from a ClickHouse DB
    • Analyzing open data on road accidents in Russia
    • Analyzing sales and locations of pizzerias based on data from Clickhouse DB and Marketplace
    • Web analytics with a connection to Yandex.Metrica
    • Web analytics with funnels and cohorts calculated based on Yandex.Metrica data
    • Mobile app analytics based on AppMetrica data
    • Analyzing Yandex Music podcast statistics (for podcasters)
    • Visualizing data with a SQL chart
    • Mobile app customer journey analytics based on AppMetrica data
    • Analyzing Object Storage logs in DataLens
  • Internet of things
    • Tutorials for the internet of things
    • Status monitoring of geographically distributed devices
    • Monitoring sensor readings and event notifications
  • Serverless technologies
    • URL shortener
    • Storing application runtime logs
  1. Data visualization and analytics
  2. Visualizing data with a SQL chart

Visualizing data with a QL chart

Written by
Yandex Cloud
  • Before you start
  • Create a connection
  • Create a QL chart
  • Create a dashboard
  • Add the QL chart to the dashboard
  • Add selectors to the dashboard

In this scenario, you will create charts using SQL queries. SQL queries enable you to configure data for visualization in a more flexible way than the standard dataset method does. For example, you can add parameters from dashboards to a SQL query.

We recommend using a QL chart if creating a regular chart from a dataset isn't suitable for your situation or if you wish to experiment with the data.

A direct connection to a demo database will be used as your data source.

To visualize and explore data, set up DataLens, then follow the steps below:

  1. Create a connection.
  2. Create a QL chart.
  3. Create a dashboard.
  4. Add the QL chart to the dashboard.
  5. Add selectors to the dashboard.

Warning

SQL queries only work with databases. CSV, GoogleSheets, Yandex Metrica, and other service connections do not support SQL queries.

Before you start

To get started with DataLens:

New user
I'm already using Yandex Cloud
  1. Log in to your Yandex account. If you don't have an account, create one.
  2. Open the homepage DataLens.
  3. Click Open Datalens.
  4. Click Log in.
  1. Log in to your Yandex account.

  2. Open the homepage DataLens.

  3. Click Open Datalens.

  4. Select one of the options:

    • If you already have an organization, select it from the drop-down menu in the Organizations tab and click Open DataLens.

      Note

      To activate a DataLens instance, the user must have the admin or owner role. For more information about roles, see Granting permissions.

    • If you have a cloud but no organization, click Add new DataLens. In the window that opens, enter your organization's name and description and click Create organization and DataLens. For more information about working with organizations, see Getting started with organizations.

If you have a technical question about the service, please contact support. To ask for advice or discuss the solution to your problem or best service practices, write to the DataLens chat in Telegram.

Create a connection

  1. Go to the connections page.

  2. Click Create connection.

  3. Select the ClickHouse connection.

    1. In the window that opens, specify the connection parameters:

      • Connection type — Specify manually.
      • Host name — rc1a-ckg8nrosr2lim5iz.mdb.yandexcloud.net.
      • HTTP interface port — 8443 (default).
      • Username — samples_ro.
      • Password — MsgfcjEhJk.
    2. Enable the HTTPS option and Allow subqueries in datasets and queries from charts.

    3. Check the connection and click Create connection.

    4. Enter Sample ClickHouse as your connection name.

    5. Click Create.

    create-connection

Wait for the connection to be saved.

Create a QL chart

  1. Go to an existing database connection.

  2. Make sure Raw SQL level → Allow subqueries in datasets and queries from charts is enabled.

  3. In the top right-hand corner, click Create QL chart.

  4. On the Query tab, enter the query code:

    SELECT
       toDate(t1.OrderDatetime) as "Date",
       COUNT(t1.ClientID) as "Number of new customers", t3.ClientStatus as "Status"
    FROM
       samples.MS_SalesFacts t1,
       (SELECT
    	      ClientID,
          MIN(OrderDatetime) as FirstDate
       FROM samples.MS_SalesFacts
       GROUP BY ClientID) as t2,
          samples.MS_Clients t3
    WHERE {{interval_from}} < "Date" and "Date" < {{interval_to}} and t1.ClientID=t2.ClientID and t3.ClientID=t2.ClientID and t3.ClientStatus in {{status}} -- status, interval_from and interval_to - variables associated with parameters affected by selectors
    GROUP BY "Status", "Date"
    ORDER BY "Date"
    
  5. On the Params tab, click Add param and complete the input fields:

    • From the drop-down list, select string (default).

    • In the Name field, enter status.

    • In the Default value field, enter Золотой.

    • Click Add param value below and enter Серебряный.

    • Click Add param value below and enter Базовый.

      sql-chart-parameter

    The added parameter will be associated with the {{status}} variable in the query.

  6. Click Add param and complete the input fields:

    • In the drop-down list, select date-interval.

    • In the Name field, enter interval.

    • Click the field with the interval value and enter:

      • From: 2017-03-01.

      • To: 2017-03-31.

        sql-chart-parameter-data2

      The From: and To: values of the added parameter will be bound to the {{interval_from}} and the {{interval_to}} variables in the SQL query.

      Note

      You can control the parameter values using dashboard selectors.

  7. Go back to the Query tab. In the lower left-hand corner, click Run. Running the query will produce a visualization in the right-hand window.

  8. Configure the visualization:

    • Select Column chart as chart type.

      sql-chart-diagram

    • Make sure that the Date field is in the X section.

    • Make sure that the Number of new clients field is in the Y section.

    • Make sure that the Status field is in the Colors section.

    • Make sure the Available section is empty. This is the section that contains fields not involved in calculations. Otherwise, the visualization will display incorrectly.

      sql-chart-rezult

  9. In the upper right-hand corner, click Save.

  10. Enter New clients as your chart name and click Save.

You can place the chart created on the dashboard. You can also equip the dashboard with selectors to control the values of the QL chart status and interval parameters.

Create a dashboard

Create a dashboard to add these charts to.

  1. Go to the DataLens homepage.

  2. Click Create dashboard.

    image

  3. Enter Change in number of clients by year as the name for the dashboard and click Create.

    The dashboard created will open for editing.

Add the QL chart to the dashboard

  1. At the top of the page, click Add and select Chart.

    image

  2. In the Chart field, click Select and select the previously created New clients chart from the chart list.

    image

    Click Add.

  3. The chart is displayed on the dashboard. Stretch it to improve visualization.

    image

  4. Save the dashboard.

Add selectors to the dashboard

  1. Add a selector to be able to filter the chart by client status:

    1. At the top of the page, click Add.

    2. Choose Selector.

      image

    3. Select Manual input as source type.

    4. In the Field or parameter name field, enter status. Certain selector values will be passed into this SQL query variable.

    5. Choose List as your selector type.

    6. Enable the Multiple choice option.

    7. Click the input field next to the Default value parameter. In the resulting window, add the following values:

      • Золотой
      • Серебряный
      • Базовый

      image

      Click Apply.

    8. In the Default value list, specify Select all.

      image

    9. Enable the Title option and enter Select client status.

    10. Verify the specified selector parameters.

      image

    11. Click Add.

    12. Place the selector on the dashboard under the chart.

  2. Add another selector to be able to filter the chart based on a date range:

    1. At the top of the page, click Add.

    2. Choose Selector.

    3. Select Manual input as source type.

    4. Under Field or parameter name, enter interval. The interval start and end values from the selector will be passed into the SQL query {{interval_from}} and the {{interval_to}} variables.

    5. Choose Calendar as your selector type.

    6. Enable Range.

    7. Enable the Title option and enter Order interval.

    8. Verify the specified selector parameters.

      image

    9. Click Add.

    10. Place the selector on the dashboard on top of the chart next to the first selector.

    11. Save the dashboard.

      image

  3. Your dashboard is ready. Now you can filter the chart by status using a selector.

    image

    You can also filter the chart by a date range using the second selector.

    image

For details, see also

  • Adding charts to dashboards
  • Adding selectors to dashboards
  • Creating a QL chart
  • QL chart

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Before you start
  • Create a connection
  • Create a QL chart
  • Create a dashboard
  • Add the QL chart to the dashboard
  • Add selectors to the dashboard