在 PowerApps 中使用折线图、饼图或条形图显示数据Show data in a line, pie, or bar chart in PowerApps

使用折线图、饼图和条形图显示数据。Use line charts, pie charts, and bar charts to display your data. 使用图表时,所导入数据的结构应如下所示:When working with charts, the data that you import should be structured like the following:

  • 各系列应在第一行。Each series should be in the first row.
  • 标签应在最左边的列。Labels should be in the leftmost column.

例如,数据看起来应与下图类似:For example, your data should look similar to the following:

可以在 PowerApps 中创建并使用这些图表。You can create and use these charts within PowerApps. 让我们开始吧。Let's get started.

先决条件Prerequisites

  • 注册 PowerApps,然后安装 PowerApps。Sign up for PowerApps, and then install PowerApps. 打开 PowerApps 时,使用注册所用的凭据登录。When you open PowerApps, sign in using the same credentials that you used to sign up.
  • 根据模板数据从头开始创建应用。Create an app from a template, from data, or from scratch.
  • 了解如何在 PowerApps 中 配置控件Learn how to configure a control in PowerApps.
  • 下载 ChartData.zip,其中包含 XML 文件形式的示例数据。Download ChartData.zip, which contains sample data as an XML file. 按照本主题中的步骤将其直接导入到应用中。Follow the steps in this topic to import it directly into your app. 也可以解压缩该 .zip 文件,在 Excel 中打开 XML 文件,然后将其保存到云存储帐户As an alternative, decompress the .zip file, open the XML file in Excel, and save it to a cloud-storage account.

导入示例数据Import the sample data

在以下步骤中,我们将示例数据导入到名为“ProductRevenue”的集合。In these steps, we import the sample data into a collection, named ProductRevenue.

  1. 在“插入”选项卡上,选择“控件”,然后选择“导入”:On the Insert tab, select Controls, and then select Import:

  2. 将控件的 OnSelect 属性设置为下面的函数:Set the control's OnSelect property to the following function:

    Collect(ProductRevenue, Import1.Data)

  3. 按 F5 打开预览模式,然后选择“导入数据”按钮。Press F5 to open Preview mode, and then select the Import Data button.

  4. 在“打开”对话框中,选择 ChartData.zip,选择“打开”,然后按 Esc。In the Open dialog box, select ChartData.zip, select Open, and then press Esc.

  5. 在“文件”菜单上,选择“集合”。On the File menu, select Collections.

    随即会列出包含已导入的图表数据的 ProductRevenue 集合:The ProductRevenue collection is listed with the chart data you imported:

    备注

    导入控件用于导入类似于 Excel 的数据并创建集合。The import control is used to import Excel-like data and create the collection. 导入控件在创建应用和预览应用时导入数据。The import control imports data when you are creating your app, and previewing your app. 目前,导入控件不在发布应用时导入数据。Currently, the import control does not import data when you publish your app.

  6. 按 Esc 返回默认工作区。Press Esc to return to the default workspace.

添加饼图Add a pie chart

  1. 在“插入”选项卡上,选择“图表”,然后选择“饼图”。On the Insert tab, select Charts, and then select Pie Chart.

  2. 将饼图移到“导入数据”按钮下面。Move the pie chart under the Import data button.

  3. 在饼图控件中,选择饼图的中间:In the pie-chart control, select the middle of the pie chart:

  4. 将饼图的 Items 属性设置为以下表达式:ProductRevenue.Revenue2014Set the Items property of the pie chart to this expression: ProductRevenue.Revenue2014

    该饼图显示 2014 年以来的收入数据。The pie chart shows the revenue data from 2014.

添加条形图以显示数据Add a bar chart to display your data

现在,让我们在条形图中使用此 ProductRevenue 集合:Now, let's use this ProductRevenue collection in a bar chart:

  1. 在“主页”选项卡上,添加一个屏幕。On the Home tab, add a screen.]

  2. 在“插入”选项卡上,选择“图表”,然后选择“柱形图”。On the Insert tab, select Charts, and then select Column Chart.

  3. 选择柱形图的中间。Select the middle of the column chart. 将柱形图的 Items 属性设置为 ProductRevenueSet the Items property of the column chart to ProductRevenue:

    该柱形图显示 2012 年以来的收入数据:The column chart shows the revenue data from 2012:

  4. 在柱形图中,选择中心方形:In the column chart, select the center square:

  5. 在“图表”选项卡上,选择“系列数”,然后在公式栏中输入 3On the Chart tab, select Number of Series, and then enter 3 in the formula bar:

    该柱形图显示每个产品三年的收入数据:The column chart shows revenue data for each product over three years: