Documentdb 简明教程

DocumentDB - Visualize Data

在本章中,我们将学习如何可视化存储在 DocumentDB 中的数据。Microsoft 提供了 Power BI Desktop 工具,它可以将你的数据转换为丰富的可视化效果。它还使你能够从各种数据源中检索数据,合并并转换数据,创建强大的报表和可视化效果,以及将报表发布到 Power BI。

在最新版本的 Power BI Desktop 中,Microsoft 也添加了对 DocumentDB 的支持,现在你可以连接到你的 DocumentDB 帐户。你可以从以下链接下载此工具:@ {s3}

我们来看一个示例,在该示例中,我们将可视化上个章节中导入的地震数据。

@ {s4} − 下载该工具后,启动 Power BI 桌面版。

power bi desktop

@ {s5} − 单击“外部数据”组下“主页”选项卡上的“获取数据”选项,它将显示“获取数据”页面。

get data

@ {s6} − 选择 Microsoft Azure DocumentDB(Beta)选项并单击“连接”按钮。

microsoft azure documentdb

@ {s7} − 输入你要可视化数据的 Azure DocumentDB 帐户、数据库和集合的 URL,然后按确定。

If you are connecting to this endpoint for the first time, you will be prompted for the account key.

account key

Step 5 − Enter the account key (primary key) which is unique for each DocumentDB account available on Azure portal, and then click Connect.

list of records

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 − Click ‘Edit’ button which will launch the Query Editor.

edit button

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.

query editor

As you can see that we have latitude and longitude as separate column but we visualize data in latitude, longitude coordinates form.

Step 8 − To do that, click ‘Add Column’ tab.

add column

Step 9 − Select the Add Custom Column which will display the following page.

add custom column

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 − Click OK to continue and you will see that the new column is added.

new column added

Step 12 − Go to the Home tab and click ‘Close & Apply’ option.

close and apply

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.

create reports

Let’s create a map view showing the location of each earthquake.

Step 14 − Drag the map visual type from the Visualizations pane.

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 − Drag and drop the depth field to the Color saturation property.

depth field

You will now see the Map visual showing a set of bubbles indicating the location of each earthquake.