Power BI 內嵌式分析中的問答
Power BI 內嵌式分析可讓您將 Q&A 併入應用程式。 您的使用者可以使用自然語言詢問問題,並以圖表或圖表等視覺效果形式立即收到解答。
在您的應用程式中內嵌 Q&A 有兩種模式: 互動式 和 結果。 互動式 模式可讓您輸入問題,並在視覺效果中顯示它們。 如果您有已儲存的問題或想要顯示的設定問題,您可以在內嵌組態中填入問題,以使用 結果 模式。
以下是 JavaScript 程式代碼的範例:
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed within the JavaScript API.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config= {
type: 'qna',
tokenType: models.TokenType.Embed | models.TokenType.Aad,
accessToken: access token value,
embedUrl: https://app.powerbi.com/qnaEmbed (groupId to be appended as query parameter if required),
datasetIds: array of requested data set ids (at the moment we support only one dataset),
viewMode: models.QnaMode.Interactive | models.QnaMode.ResultOnly,
question: optional parameter for Explore mode (QnaMode.Interactive) and mandatory for Render Result mode (QnaMode.ResultOnly)
};
// Get a reference to the embedded QNA HTML element
var qnaContainer = $('#qnaContainer')[0];
// Embed the QNA and display it within the div container.
var qna = powerbi.embed(qnaContainer, config);
設定問題
如果您使用 結果模式 搭配設定問題,您可以將更多問題插入框架中。 新問題的答案會立即取代先前的結果。 新的視覺效果會轉譯成符合新問題。
此使用方式的其中一個範例是常見問題清單。 用戶可以進行問題,並在相同的內嵌元件內回答這些問題。
JS SDK 使用方式的代碼段:
// Get a reference to the embedded Q&A HTML element
var qnaContainer = $('#qnaContainer')[0];
// Get a reference to the embedded Q&A.
qna = powerbi.get(qnaContainer);
qna.setQuestion("This year sales")
.then(function (result) {
…….
})
.catch(function (errors) {
…….
});
可視化轉譯事件
針對 互動式 模式,每次呈現的視覺效果變更以輸入查詢為目標時,應用程式都可以收到數據變更事件通知。
接 聽visualRendered 事件可讓您儲存問題以供稍後使用。
JS SDK 使用方式的代碼段:
// Get a reference to the embedded Q&A HTML element
var qnaContainer = $('#qnaContainer')[0];
// Get a reference to the embedded Q&A.
qna = powerbi.get(qnaContainer);
// qna.off removes a given event listener if it exists.
qna.off("visualRendered");
// qna.on will add an event listener.
qna.on("visualRendered", function(event) {
…….
});
內嵌令牌
從語意模型建立內嵌令牌,以啟動問答元件。 如需詳細資訊,請參閱 產生令牌作業。
相關內容
更多問題嗎? 詢問 Power BI 社群
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應