Documentdb 简明教程
DocumentDB - Visualize Data
在本章中,我们将学习如何可视化存储在 DocumentDB 中的数据。Microsoft 提供了 Power BI Desktop 工具,它可以将你的数据转换为丰富的可视化效果。它还使你能够从各种数据源中检索数据,合并并转换数据,创建强大的报表和可视化效果,以及将报表发布到 Power BI。
In this chapter, we will learn how to visualize data which is stored in DocumentDB. Microsoft provided Power BI Desktop tool which transforms your data into rich visuals. It also enables you to retrieve data from various data sources, merge and transform the data, create powerful reports and visualizations, and publish the reports to Power BI.
在最新版本的 Power BI Desktop 中,Microsoft 也添加了对 DocumentDB 的支持,现在你可以连接到你的 DocumentDB 帐户。你可以从以下链接下载此工具:@ {s3}
In the latest version of Power BI Desktop, Microsoft has added support for DocumentDB as well in which you can now connect to your DocumentDB account. You can download this tool from the link, https://powerbi.microsoft.com
我们来看一个示例,在该示例中,我们将可视化上个章节中导入的地震数据。
Let’s take a look at an example in which we will visualize the earthquakes data imported in the last chapter.
@ {s4} − 下载该工具后,启动 Power BI 桌面版。
Step 1 − Once the tool is downloaded, launch the Power BI desktop.

@ {s5} − 单击“外部数据”组下“主页”选项卡上的“获取数据”选项,它将显示“获取数据”页面。
Step 2 − Click ‘Get Data’ option which is on the Home tab under External Data group and it will display the Get Data page.

@ {s6} − 选择 Microsoft Azure DocumentDB(Beta)选项并单击“连接”按钮。
Step 3 − Select the Microsoft Azure DocumentDB (Beta) option and click ‘Connect’ button.

@ {s7} − 输入你要可视化数据的 Azure DocumentDB 帐户、数据库和集合的 URL,然后按确定。
Step 4 − Enter the URL of your Azure DocumentDB account, Database and Collection from which you want visualize data and press Ok.
如果您是第一次连接到此端点,系统将会提示您输入帐户密钥。
If you are connecting to this endpoint for the first time, you will be prompted for the account key.

Step 5 − 输入帐户密钥(主键),它对于 Azure 门户上可用的每个 DocumentDB 帐户是唯一的,然后单击“连接”。
Step 5 − Enter the account key (primary key) which is unique for each DocumentDB account available on Azure portal, and then click Connect.

当帐户连接成功后,它将从指定数据库中检索数据。预览窗格显示记录项列表,文档在 Power BI 中表示为记录类型。
When the account is successfully connected, it will retrieve the data from specified database. The Preview pane shows a list of Record items, a Document is represented as a Record type in Power BI.
Step 6 − 单击“编辑”按钮,这将启动查询编辑器。
Step 6 − Click ‘Edit’ button which will launch the Query Editor.

Step 7 − 在 Power BI 查询编辑器中,您应当在中心窗格中看到“文档”列,单击“文档”列标题右侧的展开符,然后选择您想要显示的列。
Step 7 − In the Power BI Query Editor, you should see a Document column in the center pane, click on the expander at the right side of the Document column header and select the columns which you want display.

正如你所见,我们有经度和纬度作为单独的列,但以纬度,经度坐标的形式可视化数据。
As you can see that we have latitude and longitude as separate column but we visualize data in latitude, longitude coordinates form.
Step 8 − 为此,点击“添加列”选项卡。
Step 8 − To do that, click ‘Add Column’ tab.

Step 9 − 选择添加自定义列,它将显示以下页面。
Step 9 − Select the Add Custom Column which will display the following page.

Step 10 − 指定新列名,假定为 LatLong,以及公式,它将以逗号分隔的形式将纬度和经度组合在一列中。以下是该公式。
Step 10 − Specify the new column name, let’s say LatLong and also the formula which will combine the latitude and longitude in one column separated by a comma. Following is the formula.
Text.From([latitude])&", "&Text.From([longitude])
Step 11 − 点击确定继续,您将看到添加了新列。
Step 11 − Click OK to continue and you will see that the new column is added.

Step 12 − 转到主页选项卡并点击“关闭并应用”选项。
Step 12 − Go to the Home tab and click ‘Close & Apply’ option.

Step 13 − 您可通过将字段拖放到报告画布中创建报告。您可以在右侧看到两个窗格,一个为可视化窗格,另一个为字段窗格。
Step 13 − You can create reports by dragging and dropping fields into the Report canvas. You can see on the right, there are two panes − one Visualizations pane and the other is Fields pane.

我们创建一个地图视图来展示每次地震的位置。
Let’s create a map view showing the location of each earthquake.
Step 14 − 从可视化窗格中拖动地图可视化类型。
Step 14 − Drag the map visual type from the Visualizations pane.
Step 15 − 现在,从字段窗格将 LatLong 字段拖放到可视化窗格中的位置属性。然后,将震级字段拖放到值属性。
Step 15 − Now, drag and drop the LatLong field from the Fields pane to the Location property in Visualizations pane. Then, drag and drop the magnitude field to the Values property.
Step 16 − 将深度字段拖放到颜色饱和度属性。
Step 16 − Drag and drop the depth field to the Color saturation property.

现在,您将看到地图可视化展示了一组表示每个地震位置的气泡。
You will now see the Map visual showing a set of bubbles indicating the location of each earthquake.