內嵌編頁報告
提示
請嘗試在 Power BI Embedded Analytics 遊樂場的 [探索我們的 API] 區段中,內嵌編頁報表或實驗我們的用戶端 API。
本文涵蓋在應用程式中內嵌編頁報表的步驟。 若要深入瞭解編頁報表,請參閱什麼是 Power BI Premium 中的編頁報表?。
如何內嵌編頁報表
當您在應用程式中內嵌 Power BI 內容時,您會定義內容,並在組態物件中指定其設定。 然後,您會將該對象傳遞至 API。
當您內嵌編頁報表時,請使用 類型的 IPaginatedReportLoadConfiguration
組態物件:
export interface IPaginatedReportLoadConfiguration {
accessToken: string;
id: string;
embedUrl?: string;
settings?: IPaginatedReportSettings;
tokenType?: TokenType;
type?: string;
parameterValues?: IPaginatedReportParameter[];
}
此介面包含下列屬性:
accessToken - 可讓您存取所內嵌之 Power BI 數據的令牌。 若要深入瞭解存取令牌 ,請參閱瞭解不同的內嵌解決方案 。
embedUrl - 您要內嵌之報表的 URL。 此 URL 會成為包含內嵌報表的 HTML iframe 元素來源。 具體而言,API 會將URL指派給
src
iframe的屬性。 您可以使用 報表 API 來取得此 URL。 以下為兩個範例:我們建議使用
parameterValues
下列屬性,將報表參數傳遞至報表。 不過,您也可以將查詢字串新增至內嵌 URL 結尾,將參數傳遞至報表。 深入瞭解如何在 編頁報表中傳遞 URL 參數。 請參閱 將參數傳遞至 URL 的範例。id - 您要內嵌之 Power BI 報表的識別碼。
hostname - 預設值
hostname
為 app.powerbi.com。 如果您使用主權雲端,請在這裡提供URL。 如果您提供的值embedURL
,hostname
會忽略 。settings - IPaginatedReportSettings 類型的組態物件。 此物件會指定報表參數面板外觀的相關信息。 參數面板是可展開或隱藏之動作列下方的列。
您可以按下動作列上的 [ 參數 ] 按鈕,以顯示或隱藏參數面板。 預設會提供該按鈕。 但是,如果您將面板的
enabled
屬性設定為false
,則無法使用 [ 參數 ] 按鈕。根據預設,API 會折迭參數面板。 如果您將面板的
expanded
屬性設定為true
,API 會載入已展開此面板的報表。此程式代碼示範設定 屬性的
settings
其中一種方式:settings: { commands: { parameterPanel: { enabled: true, expanded: true } } }
tokenType - 可讓您存取所內嵌之 Power BI 數據的令牌類型。
- 如果您要為組織內嵌, (使用者擁有資料) ,請使用
models.TokenType.Aad
。 - 如果您要為客戶內嵌, (應用程式擁有資料) ,請使用
models.TokenType.Embed
。
如需詳細資訊 ,請參閱瞭解不同的內嵌解決方案 。
- 如果您要為組織內嵌, (使用者擁有資料) ,請使用
parameterValues – 類型的
IPaginatedReportParameter
組態物件。 使用這個屬性設定報表參數。 這個方法會使用 JavaScript SDK,而且是傳遞報表參數的慣用方法。 例如:parameterValues: [ {name: "State", value: "WA"}, {name: "City", value: "Seattle"}, {name: "City", value: "Bellevue"}, {name: "City", value: "Redmond"} ]
這個方法只能用來傳遞報表參數, (具有 URL 前置
rp:
詞) ,而不是使用 URLrdl:
前置詞 (rdl 參數) 。
範例
下列範例示範如何內嵌編頁報表:
// Set up the configuration object that determines what to embed and how to embed it.
let embedConfiguration = {
accessToken: anAccessToken,
embedUrl: anEmbedUrl,
uniqueId: aReportId,
tokenType: aTokenType,
type: 'report',
datasetBindings: [{
sourceDatasetId: "originalDatasetId",
targetDatasetId: "notOriginalDatasetId"
}]
};
// Get a reference to the HTML element that contains the embedded report.
let embedContainer = $('#embedContainer')[0];
// Embed the report.
let report = powerbi.embed(embedContainer, embedConfiguration);
請確定您在 多重資源內嵌令牌中包含用於系結的所有 DatasetId。
考量與限制
- 若要使用動態系結,請參閱 將數據集動態系結至編頁報表。
- 編頁報表不支持啟動程式方法。
- 內嵌編頁報表時,不支援多重值參數。
- 屬性
parameterValues
只能用於報表參數。 它不能用於 rdl 參數。 - 不支援使用即時數據集內嵌編頁報表, (推送數據集) 。