Retail chain's dashboard based on a ClickHouse® DB
- Getting started
- Step 1. Create a connection and dataset
- Step 2. Set up the dataset fields
- Step 3. Create a line chart
- Step 4. Create a column chart
- Step 5. Create a pivot table chart
- Step 6. Create a heat map
- Step 7. Create a dashboard
- Step 8. Add charts to the dashboard
- Step 9. Add selectors to the dashboard
We will use a Moscow retail chain's demo ClickHouse® sales database as our data source.
In this example, DataLens is used to visualize:
- Sales dynamics by day and month.
- Sales by product categories.
- Order heat map.
A connection named Sample ClickHouse will be created for database access.
To visualize and explore data, set up DataLens and follow the steps below:
- Define the data source for a dataset.
- Configure the dataset fields.
- Create a line chart.
- Create a bar chart.
- Create a pivot table chart.
- Create a heat map.
- Create a dashboard.
- Add charts to the dashboard.
- Add selectors to the dashboard.
Getting started
To get started with DataLens:
- Log in
to your Yandex account. If you do not have an account, create one. - Open the DataLens home page
. - Click Open DataLens.
- Confirm that you have read the Terms of use
and click Log in.
-
Log in
to your Yandex account. -
Open the DataLens home page
. -
Click Open DataLens.
-
Select one of the options:
-
If you already have an organization, select it from the drop-down menu in the Organizations tab and click DataLens.
Note
To activate a DataLens instance, the user must have the
admin
orowner
role. For more information about roles, see Access management in Yandex Cloud Organization. -
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 any technical questions about the service, contact Yandex Cloud support
Step 1. Create a connection and dataset
Warning
If you use a new DataLens object model with workbooks and collections:
- Go to the DataLens home page
. In the left-hand panel, select Collections and workbooks. - Open the workbook, click Create in the top-right corner, and select the appropriate object.
Follow the guide from step 3.
-
Go to the connections page
. -
Click Create connection.
-
Select the ClickHouse connection.
-
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
.
-
Enable Allow subqueries in datasets and queries from charts.
-
Check the connection and click Create connection.
-
Enter the connection name:
Sample ClickHouse
. -
Click Create.
-
Wait for the connection to be saved.
- In the top-right corner, click Create dataset.
Step 2. Set up the dataset fields
-
Drag the MS_SalesFacts table to the workspace.
-
Drag the MS_Clients table to the workspace. The tables are automatically linked.
-
To check the link, click the link icon between the tables.
-
Tables are linked by the ClientID field. If needed, you can modify or expand the link by specifying another pair of fields. To close the link settings window, click the cross button or anywhere outside the window.
-
Drag the MS_Products table to the workspace. The table is automatically linked to the left (root) table MS_SalesFacts.
-
Drag the MS_Shops table to the workspace. The table is automatically linked to the left (root) table MS_SalesFacts.
-
Go to the Fields tab.
-
Delete the duplicate fields left over from joining the tables: ClientID (1), ProductID (1), and ShopID (1).
-
Create an order date field named OrderDate.
-
Duplicate the OrderDatetime field.
-
Rename the OrderDatetime (1) duplicate field to OrderDate: click the row name, delete the current name, and enter the new one.
-
Change the data type from Date and time to Date.
-
-
For the ShopDistrictCoordinates field, change the data type to Geopolygon.
-
For the DeliveryDistrictCoordinates field, change the data type to Geopolygon.
-
For the DeliveryAddressCoord field, change the data type to Geopoint.
-
In the Aggregation column, select Sum for the Sales field.
The aggregation field changes color to blue: Sales is now a measure.
-
Create a measure for the number of orders.
-
Duplicate the OrderID field.
-
Rename the OrderID (1) duplicate field to OrderCount.
-
Change the aggregation type to Number of unique.
-
-
Create a calculated field for the average sales amount per order.
-
In the top-right corner, click Add field.
-
In the Name field, specify Sales per Order.
-
In the column to the left, click the Sales field.
-
Enter a
/
. -
In the column to the left, click the OrderCount field.
-
Click Create.
-
-
Click Save in the top-right corner to save the dataset.
-
Enter a name for the dataset: Moscow Sales dataset, then click Create.
-
When the dataset is saved, click Create chart.
Step 3. Create a line chart
To visualize sales dynamics by month, create a line chart.
-
For the visualization type, choose Line chart.
-
Add the sales date to the chart. Drag the OrderDate field from the Dimensions section to the X section.
-
Add a sales measure to the chart. To do this, drag the Sales field from Measures to the Y section.
-
Add the delivery type to the chart. To do this, drag the PaymentType field from the Dimensions to the Colors section.
-
Display the chart by month.
- Click the calendar icon next to the OrderDate field in the X section.
- In the Grouping field, select Rounding ⟶ Month and click Apply.
-
Save the chart.
-
Click Save in the top-right corner to save the chart.
-
In the window that opens, enter a name for the chart: Sales dynamics by month and payment type, and click Save.
-
Step 4. Create a column chart
To visualize sales by brand and product category, create a column chart.
-
Copy the chart from the previous step.
-
Click the down arrow next to the Save button in the top-right corner.
-
Choose Save as.
-
In the window that opens, enter the Sales by brand and category name for the new chart and click Save.
-
-
Select the Bar chart visualization type.
-
The OrderDate, Sales, and PaymentType fields are automatically added to the X, Y, and Colors sections, respectively.
-
Replace the months with brands on the X-axis. Drag the ProductBrand field from the Dimensions section to the X section and hold it over the OrderDate field until it turns red.
-
Replace payment types for product categories in the Colors section. Drag ProductCategory from the Dimensions to the Colors section and hold it over the PaymentType field until it turns red.
-
Sort the chart in descending order of sales measure. Drag the Sales field from the Measures section to the Sorting section.
-
Save the chart.
Step 5. Create a pivot table chart
To visualize sales by product and time, create a pivot table chart.
-
Copy the chart from the previous step.
- Click the down arrow next to the Save button in the top-right corner.
- Click Save as.
- In the window that opens, enter Sales by year and product as the name for the new chart.
- Click Save.
-
Choose the Pivot table visualization type.
-
The ProductBrand and Sales fields are automatically copied to the Columns and Measures sections, respectively.
-
Remove ProductBrand from the table.
-
Add the order date to the table. To do this, drag the OrderDate field from the Dimensions section to the Columns section.
-
Change the display format in the OrderDate field to years.
- Click the calendar icon next to the OrderDate field in the Columns section.
- In the Grouping field, select Date part ⟶ Year and click Apply.
-
Add the product category and subcategory to the table. To do this, drag the ProductCategory and ProductSubcategory fields from the Dimensions section to the Rows section.
-
Change the color of the sales measure in the table. To do this, drag the Sales field from the Measures section to the Colors section.
-
Save the chart.
Step 6. Create a heat map
To visualize the density of orders on the map of Moscow, create a heat map chart.
-
Copy the chart from the previous step.
- Click the icon next to the Save button in the top-right corner and select Save as.
- In the window that opens, enter Sales heat map as the name for the new chart.
- Click Save.
-
Select the Map visualization type.
-
Select the Points (heat map) layer type.
-
Add the delivery point coordinates to the map. To do this, drag the DeliveryAddressCoord field from the Dimensions section to the Points (heat map) section.
-
Save the chart.
Step 7. Create a dashboard
Create a dashboard to add these charts to.
-
Go to the DataLens home page
. -
Click Create dashboard.
Step 8. Add charts to the dashboard
-
The first time you open the dashboard after saving, it opens in edit mode. If you open it later, click Edit in the top-right corner.
-
Click Add and select Chart.
-
In the window that opens, click Select.
-
Select the chart Sales dynamics by month and payment type. This automatically fills in the Title field with the name of the selected chart.
-
Click Add.
-
Similarly, add the following charts:
- Sales by brand and category
- Sales by year and product
- Sales heat map
-
Position the charts on the dashboard however you like.
Step 9. Add selectors to the dashboard
Add selectors to filter your charts by date, Moscow districts, products, and customer statuses.
-
Click Add.
-
Choose Selector.
-
Add the calendar selector for the order date.
- Select the Moscow Sales dataset.
- Select the OrderDate field.
- This automatically fills in Title with the name of the selected field. Click the Show checkbox next to the selector title.
- Select the Calendar type.
- Enable Range.
- Click Add.
-
Add a product category selector.
- Select the Moscow Sales dataset.
- Select the ProductCategory field.
- This automatically fills in Title with the name of the selected field. Click the Show checkbox next to the selector title.
- Enable the Multiple choice option.
- Click Add.
-
Similarly, add selectors for the following fields:
- ProductBrand
- DeliveryDistrictName
- DeliveryType
- PaymentType
-
Position the selectors on the dashboard however you like.
-
Save the dashboard:
-
In the top-right corner, click Save.
-
Enter Moscow Shops dashboard for the dashboard name and click Create.
-
-
Your dashboard is ready. Now you can filter charts using selectors.
ClickHouse® is a registered trademark of ClickHouse, Inc