您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

工作簿下拉列表参数Workbook drop down parameters

用户可以使用下拉列表参数从已知的集中收集一个或多个输入值(例如,选择某个应用的请求)。Drop downs allow user to collect one or more input values from a known set (for example, select one of your app’s requests). 下拉列表参数提供从用户收集任意输入的用户友好方式。Drop downs provide a user-friendly way to collect arbitrary inputs from users. 在交互式报表中启用筛选功能时,下拉列表参数特别有用。Drop downs are especially useful in enabling filtering in your interactive reports.

指定下拉列表参数的最简单方法是在参数设置中提供一个静态列表。The easiest way to specify a drop-down is by providing a static list in the parameter setting. 更有意思的方法是通过 KQL 查询动态获取列表。A more interesting way is to get the list dynamically via a KQL query. 还可以使用参数设置来指定单选或多选,如果是多选,则还可以指定如何设置结果集的格式(分隔符、引号等)。Parameter settings also allow you to specify whether it is single or multi-select, and if it is multi-select, how the result set should be formatted (delimiter, quotation, etc.).

创建静态下拉列表参数Creating a static drop-down parameter

  1. 从编辑模式下的空工作簿开始操作。Start with an empty workbook in edit mode.

  2. 从工作簿内的链接中选择“添加参数”。Choose Add parameters from the links within the workbook.

  3. 单击蓝色的“添加参数”按钮。Click on the blue Add Parameter button.

  4. 在弹出的“新建参数”窗格中,输入:In the new parameter pane that pops up enter:

    1. 参数名称:EnvironmentParameter name: Environment
    2. 参数类型:Drop downParameter type: Drop down
    3. 必需:checkedRequired: checked
    4. 允许 multiple selectionuncheckedAllow multiple selection: unchecked
    5. 从以下位置获取数据:JSONGet data from: JSON
  5. 在“JSON 输入”文本块中,插入以下 JSON 片段:In the JSON Input text block, insert this json snippet:

    [
        { "value":"dev", "label":"Development" },
        { "value":"ppe", "label":"Pre-production" },
        { "value":"prod", "label":"Production", "selected":true }
    ]
    
  6. 点击蓝色的 Update 按钮。Hit the blue Update button.

  7. 从工具栏中选择“保存”以创建参数。Choose 'Save' from the toolbar to create the parameter.

  8. Environment 参数将是包含三个值的下拉列表。The Environment parameter will be a drop-down with the three values.

    显示如何创建静态下拉列表参数的插图

创建包含项组的静态下拉列表Creating a static dropdown with groups of items

如果查询结果/JSON 包含“group”字段,则下拉列表将显示值组。If your query result/json contains a "group" field, the dropdown will display groups of values. 请遵循上面的示例,但改用以下 JSON:Follow the above sample, but use the following json instead:

[
    { "value":"dev", "label":"Development", "group":"Development" },
    { "value":"dev-cloud", "label":"Development (Cloud)", "group":"Development" },
    { "value":"ppe", "label":"Pre-production", "group":"Test" },
    { "value":"ppe-test", "label":"Pre-production (Test)", "group":"Test" },
    { "value":"prod1", "label":"Prod 1", "selected":true, "group":"Production" },
    { "value":"prod2", "label":"Prod 2", "group":"Production" }
]

显示分组下拉列表示例的图像

创建动态下拉列表参数Creating a dynamic drop-down parameter

  1. 从编辑模式下的空工作簿开始操作。Start with an empty workbook in edit mode.

  2. 从工作簿内的链接中选择“添加参数”。Choose Add parameters from the links within the workbook.

  3. 单击蓝色的“添加参数”按钮。Click on the blue Add Parameter button.

  4. 在弹出的“新建参数”窗格中,输入:In the new parameter pane that pops up enter:

    1. 参数名称:RequestNameParameter name: RequestName
    2. 参数类型:Drop downParameter type: Drop down
    3. 必需:checkedRequired: checked
    4. 允许 multiple selectionuncheckedAllow multiple selection: unchecked
    5. 从以下位置获取数据:QueryGet data from: Query
  5. 在“JSON 输入”文本块中,插入以下 JSON 片段:In the JSON Input text block, insert this json snippet:

        requests
        | summarize by name
        | order by name asc
    
  6. 点击蓝色的 Run Query 按钮。Hit the blue Run Query button.

  7. 从工具栏中选择“保存”以创建参数。Choose 'Save' from the toolbar to create the parameter.

  8. RequestName 参数将是包含应用中所有请求的名称的下拉列表。The RequestName parameter will be a drop-down the names of all requests in the app.

    显示如何创建动态下拉列表的插图

引用下拉列表参数Referencing drop down parameter

在 KQL 中In KQL

  1. 在工作簿中添加查询控件,然后选择 Application Insights 资源。Add a query control to the workbook and select an Application Insights resource.

  2. 在 KQL 编辑器中输入此片段In the KQL editor, enter this snippet

        requests
        | where name == '{RequestName}'
        | summarize Requests = count() by bin(timestamp, 1h)
    
    
  3. 此片段可根据查询评估时间扩展为:This expands on query evaluation time to:

        requests
        | where name == 'GET Home/Index'
        | summarize Requests = count() by bin(timestamp, 1h)
    
  4. 运行查询以查看结果。Run query to see the results. (可选)以图表形式呈现结果。Optionally, render it as a chart.

    显示在 KQL 中引用下拉列表的插图

参数值、标签、选项和组Parameter value, label, selection and group

上述动态下拉列表参数中使用的查询只返回下拉列表中真正呈现的值列表。The query used in the dynamic drop-down parameter above just returns a list of values that are rendered faithfully in the drop-down. 但如果需要不同的显示名称,或者要选择其中的一个显示名称,该怎么办?But what if you wanted a different display name, or one of these to be selected? 下拉列表参数可通过值、标签、选项和组列来实现此目的。Drop down parameters allow this via the value, label, selection and group columns.

以下示例演示如何获取已使用表情符号设置其显示名称样式的 Application Insights 依赖项的列表,选择第一个依赖项,并按操作名称分组依赖项。The sample below shows how to get a list of Application Insights dependencies whose display names are styled with an emoji, has the first one selected, and is grouped by operation names.

dependencies
| summarize by operation_Name, name
| where name !contains ('.')
| order by name asc
| serialize Rank = row_number()
| project value = name, label = strcat('🌐 ', name), selected = iff(Rank == 1, true, false), group = operation_Name

显示使用值、标签、选项和组选项的下拉列表参数的图像

参数Parameter 说明Explanation 示例Example
{DependencyName} 选定值The selected value GET fabrikamaccountGET fabrikamaccount
{DependencyName:label} 选定标签The selected label 🌐 GET fabrikamaccount🌐 GET fabrikamaccount
{DependencyName:value} 选定值The selected value GET fabrikamaccountGET fabrikamaccount

多重选择Multiple selection

目前为止,示例将参数显式设置为仅选择下拉列表中的一个值。The examples so far explicitly set the parameter to select only one value in the drop-down. 下拉列表参数还支持 multiple selection - 只需选中 Allow multiple selection 选项即可启用此功能。Drop down parameters also support multiple selection - enabling this is as simple as checking the Allow multiple selection option.

用户还可以选择通过 delimiterquote with 设置指定结果集的格式。The user also has the option of specifying the format of the result set via the delimiter and quote with settings. 默认设置仅以集合形式返回采用以下格式的值:'a', 'b', 'c'。The default just returns the values as a collection in this form: 'a', 'b', 'c'. 用户还可以选择限制选项数目。They also have the option to limit the number of selections.

需要更改引用参数的 KQL 才能使用结果的格式。The KQL referencing the parameter will need to change to work with the format of the result. 做到这一点的最常用方式是使用 in 运算符。The most common way to enable it is via the in operator.

dependencies
| where name in ({DependencyName})
| summarize Requests = count() by bin(timestamp, 1h), name

下面是多选下拉列表的工作示例:Here is an example for multi-select drop-down at work:

显示多选下拉列表参数的插图

后续步骤Next steps

  • 开始详细了解工作簿丰富的可视化效果选项。Get started learning more about workbooks many rich visualizations options.
  • 控制并共享对工作簿资源的访问权限。Control and share access to your workbook resources.