Power BI 嵌入式分析中的问答

Power BI 嵌入式分析提供了一种将 Q&A 合并到应用程序中的方法。 用户可以使用自然语言提出问题,并立即以图表或图形等视觉对象形式接收答案。

Power BI Embedded 视图的动画 GIF,其中显示了如何嵌入示例 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.cn/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) {
     …….
});

嵌入令牌

从语义模型创建嵌入令牌以启动 Q&A 部件。 有关详细信息,请参阅 生成令牌操作

试用 Power BI 嵌入式分析体验区

更多问题? 在 Power BI 社区提问