Superset official introductory tutorial Chinese translation

This translation from Superset official document: Toturial - Creating your First Dashboard

Superset interfaces and functions in the latest version of the documents mentioned there was a little discrepancy to the actual main. This article only for translation

Getting Started - Creating your first Kanban

This tutorial target users are those who want to create charts and Kanban in the Superset. We'll show you how to connect through Superset to a new database and configure the library a table for analysis. You also can go to explore data has been added onto the database, you can add a chart to visualize the kanban. In this tutorial, you can have an end to end (end-to-end) user experience.

Connect to a new database

Assuming you already have a good database configuration, and can be connected via a running Superset environment. If you just want to experience Supertest and explore some sample data, you can load PostgreSQL sample data set to a new database, or configure us in this section will be used to the weather sample data .

In the Data Source menu, select the database options:

source-database

Jump in the results page, select the top right corner of the green "+" sign:

add-database-button

You can configure a number of advanced options on this page, but for this tutorial, you only need to configure the following two just fine:

  1. To add a database to come in a name:

name-database

  1. SQLAlchemy URI input connection and test the connection:

sqlalchemy-postgresql-uri

The figure shows the connection of a weather database for testing. URI text as shown below, you can refer to the SQLAlchemy documentation create a new connection URI to connect to the target database.

点击 测试连接 按钮来确认两端都没问题。如果 Superset 能够成功连接并获得授权,那么你将看到如下弹窗提醒:

database-connection-success

此外,你应该能够在页面底部看到 Superset 能够读取到的、你刚添加的数据库中已经创建的表:

table-list

如果连接没问题,点击位于页面底部的 保存 按钮来保存这个配置:

save-database-configuration

添加新表

到此数据库已经配置好了,你需要添加一个将要用于查询的具体的表到 Superset 中。

数据源 按钮下,选择 数据表 选项:

source-tables

在跳转的结果页中,单击右上角的绿色“+”号按钮:

add-new-table

为了添加新表到 Superset 中你只需要添加少许的几个信息即可:

  • 表名

name-table

  • 数据库 下拉列表中选择目标库(例如,你刚才添加上去的一个)

choose-database

  • 可选的,数据库的 schema。如果数据表是存在于默认的 schema 中(例如 PostgreSQL 或者 Redshift 中的 public),那么该选项可以留空。

单击 保存 按钮来保存配置:

save-table-configuration

当页面重定向到数据表清单页面后,你应该能看到一条信息提示说你的表已经创建好了:

cretaed-info

这条信息同时也告诉你可以编辑表配置。我们当前将仅会编辑一小部分配置-为了能让你开始-同时剩下一些留在高级教程中。

在你刚才创建的表旁边单击编辑按钮:

edit-table-configuration

在结果页中,点击 列列表 标签。在这里,你可以定义一些在探索数据时使用到的具体列。我们将会历遍这些选项去描述它们的作用:

  • 如果你希望用户根据具体的列来进行分组,那么在 可分组 下勾选它
  • 如果你需要根据具体的列来进行过滤,那么在 可过滤 下勾选它
  • 是否有一些字段你需要去统计它的唯一值个数的?勾选 唯一性统计
  • 是否有一些字段你需要去求和的,或者想要得到一些基本的统计信息?那么 求和最小值最大值 列会有帮助
  • 所有的日期或者时间字段,都应该勾选上 表示时间(原文是 is temporal )。我们将会在稍后讲述它们是如何操作的。

(译注:目前我安装上的版本中,只剩下可分组、可过滤、表示时间这三个选项了)

以下是已经针对天气数据配置好的字段。对于天气数据的测量(比如降雨量、降雪量等等)来说,根据以下这些字段它已经足够去分组和过滤的了:

weather-data-configuration

如上图所示,点击 保存 按钮以保存这些配置。

探索数据

要探索数据,只需要在表列表中点击你刚才创建的表的名字即可:

weather-data-denormalized

默认地,展现在你面前的是表视图(Table View):

table-view

让我们使用一些基本的查询来统计表中的所有记录数。首先,我们需要更改 时间(Since)过滤器来取得数据的时间范围,你可以通过一些简单的词语来应用这个筛选,例如“3年前”:

since

而这个时间区间的上限,在 Until 过滤器中,默认是 现在,当然这个可能并不是你想要的。

再看到位于 分组 下方的 指标 部分,可以在其中输入 “Count” —— 你会看到一个根据你的输入而匹配出来的指标列表:

metrics

选择 COUNT(*) 指标,然后点击位于探索器顶部旁边的绿色按钮:

query-button

你将会右侧的表格里看到查询结果:

query-result

让我们在 分组 区域中,以 weather_description 字段为分组,取得以天气记录类型为分类的记录数有多少:

group-by-weather-description

执行查询:

query-result

让我们查找一个更加有用的数据:在 2015 年有记录的温度最高的时间和地点的 TOP 10。

分组 区域中,把 weather_description 替换为 latitudelongitudemeasurement_date

group-by-latitude-longitude-measurement_date

同时在 指标 区域中,把 COUNT(*) 替换为 *max__measurement_flag*:

metrics-max__measurement_flag

*max__measurement_flag* 指标是在我们前面配置表的时候,勾选了 measurement_flag 字段对应的 Max 选框而创建的,指明这个字段是一个数值并且当需要根据指定的字段进行分组的时候我们要在其中查询它的最大值。

在本案例中,measurement_flag 是测量所需要使用到的值,它很明显是依赖于测量的类别的(研究者会记录不同的降雨量和气温的值)。因此,我们必须仅在 weather_description 相等于 “Maximum temperature” 的记录中过滤我们的查询,这个过滤会在探索器窗口底部的 过滤 模块中进行:

filters

最后,由于我们仅关心 top 10,所以我们要限制我们的查询结果为 10 条记录,通过位于 Options 头下方的 行限制 来实现:

row-limit

点击 查询 然后可以得到如下的结果:

query-result

在这个数据集中,最高温度以十分之一摄氏度记录( is recorded in tenths of a degree Celsius)。最大值是 1370,在内华达州中部测量得到的,相当于 137 摄氏度,或约等于 278 华氏度。这个数据可能是错的。我们已经使用 Superset 探查了一些异常值,但这仅仅是冰山一角。

你可以通过这些方法来做许多事情:

  • 默认的显示数值的格式是 1.37k,是不便于人们阅读的。可能你会更加喜欢使用全的、使用逗号分隔的值。通过修改配置(编辑 表配置 > 列出 SQL 指标 > 编辑指标 > D3 格式)你可以更改任何一个指标数据的格式。
  • 此外,可能你想把温度直接以原生的摄氏度来显示,而不是显示它的 10 倍值,又或者你需要把它转换成华氏度来显示。你可以修改针对数据库执行的 SQL 语句,将转换逻辑直接映射到指标本身(编辑 表配置 > 列出 SQL 指标 > 编辑指标 > SQL 表达式)。

Now, let's create a better visualization of these data for the chart and add it to the kanban.

We change the chart type to "distribution - histogram":

分布-柱状图

Our filter for maximum temperature indicators previously set can be retained, but the query and formatting options are dependent on the type of chart, so you have to configure these values ​​again:

chart-options

You should be noticed that for this chart, it has more formatting options: Set axis labels, margins, scale and so on. In order to demonstrate in front of a larger audience chart, you might want to use more of these charts and add them to the kanban. Now, we execute the query and get the following chart:

temperature-bar-chart

Creating slice and Kanban

These figures may be useful for researchers is, so let's save it. In Superset, one of the saved query is called a slice (Slice).

To create a slice, click the Save button located in the upper left corner of the Explorer:

save-chart

At this point there will be a pop appears to write a slice name, and whether you want to add to a kanban options. Since we have not created a task Kanban, where we can simultaneously create a direct addition to this slice of our billboards in:

save-a-chart

Click Save, and then you will be redirected back to the original query interface. At the same time we can see our slice and billboards have been successfully created:

created-success

To check our new billboards. Click Kanban menu:

dashboard

Kanban found just created:

weather-data-dashboard

All is well - we slices are here:

weather-data-slice

But it is smaller than we expected it. Fortunately, you can adjust the slices in a card. Click on it, keeping the mouse down, do not let go and drag the bottom right corner until the size you want:

adjust-size-of-slice

After the adjustment finished, you will be prompted to click the top left button Kanban to save this new configuration.

Congratulations! You have successfully connected Superset, were analyzed and the data visualization. And there are many table configuration and visualization options, so please start exploring and creating your own slice of it and billboards.

This translation belongs to my blog Park - East Wai lay all, please indicate the source

Guess you like

Origin www.cnblogs.com/wuzhiblog/p/superset-chinese-toturial.html