在 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:

    此直條圖會顯示過去 3 年每項產品的營收資料:The column chart shows revenue data for each product over three years: