-
Notifications
You must be signed in to change notification settings - Fork 1
/
pbi.html
68 lines (56 loc) · 2.5 KB
/
pbi.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<div id="qnaContainer" style="width: 600px;height: 600px;"></div>
<script>
var qna;
window.onload = function () {
var txtAccessToken = "<TOKEN>";
var txtEmbedUrl = "<EMBED_URL>";
var txtDatasetId = "<DATASET>";
var initialQuery = "<INITIAL_QUERY>";
var qnaMode = "ResultOnly";
// Get models. models contains enums that can be used.
var models = window["powerbi-client"].models;
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config = {
type: "qna",
tokenType: models.TokenType.Embed,
accessToken: txtAccessToken,
embedUrl: txtEmbedUrl,
datasetIds: [txtDatasetId],
viewMode: models.QnaMode[qnaMode],
question: initialQuery,
};
// Get a reference to the embedded QNA HTML element
var qnaContainer = document.getElementById("qnaContainer");
// Embed the QNA and display it within the div container.
qna = powerbi.embed(qnaContainer, config);
qnaContainer.firstChild.setAttribute("frameBorder", "0"); // Remove border.
// qna.off removes a given event handler if it exists.
qna.off("loaded");
// qna.on will add an event handler which prints to Log window.
// Qna.allowedEvents = ["loaded", "visualRendered"];
// https://github.com/Microsoft/PowerBI-JavaScript/blob/master/dist/powerbi.js
qna.on("loaded", function (event) {
// Currently not working.
// https://stackoverflow.com/questions/49432205/power-bi-embedded-qa-events-do-not-fire-is-it-a-bug
});
qna.on("rendered", function(event) {
// Currently not working.
});
}
function setQuestion(question) {
// TODO: When rendered event works, return promise and resolve when event triggered.
qna.setQuestion(question);
return question;
}
</script>
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js"></script>
</body>
</html>