問題描述
我想在我的報告 power bi 嵌入式上添加一些過濾器,我有一個 html 文件,我需要在 javascript 中添加一些過濾器,但我沒有開發經驗.我只需要看一個例子就知道如何添加它.
I want to add somes filters on my reports power bi embedded, i have an html file, and i need to add somes filters in javascript but i dont have experience as a developer. I just need to see an exemple to see how to add it.
<head> `enter code here`
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>test</title>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" language="javascript" src="https://rawgit.com/Microsoft/PowerBI-JavaScript/master/dist/powerbi.min.js"></script>
</head>
<body>
<h1>test</h1>
<div id="reportContainer" style="width: 80%; height: 800px;"></div>
</body>
<script>
$(document).ready(function () {
var getEmbedToken = "https://testclienttest.azurewebsites.net/api/HttpTrigger1?code=XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXX==";
$.ajax({
url: getEmbedToken,
jsonpCallback: 'callback',
contentType: 'application/javascript',
dataType: "jsonp",
success: function (json) {
var models = window['powerbi-client'].models;
var embedConfiguration = {
type: 'report',
id: json.ReportId,
embedUrl: json.EmbedUrl,
tokenType: models.TokenType.Embed,
accessToken: json.EmbedToken
};
var $reportContainer = $('#reportContainer');
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
},
error: function () {
alert("Error");
}
});
});
</script>
</html>
我認為要添加的過濾器在此行之后:var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
i think the filters to add is after this line : var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
推薦答案
要過濾您的嵌入報告,您必須構造一個或多個過濾器并將它們作為數組傳遞給 JavaScript 客戶端 - 在 filters
中embedConfiguration
的屬性,或作為 report
/page
/visual
setFilters
的參數方法.
To filter your embed report, you must construct one or more filters and pass them as array to the JavaScript client - either in filters
property of embedConfiguration
, or as a parameter to report
/page
/visual
setFilters
method.
過濾器可以是以下類型之一:
The filters can be from one of these types:
- IBasicFilter
- 高級過濾器
- IRelativeDateFilter
- ITTopNFilter
- IIncludeExcludeFilter
例如,過濾名為 Product
的表以僅顯示數據,其中 Count
列為 1、2 或 3,可以如下構造:
For example, to filter table named Product
to show only data, where Count
column is 1, 2 or 3 can be constructed as follows:
const basicFilter: pbi.models.IBasicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Product",
column: "Count"
},
operator: "In",
values: [1,2,3],
filterType: 1 // pbi.models.FilterType.BasicFilter
}
然后修改您的代碼以將此過濾器傳遞給 embedConfiguration
:
Then modify your code to pass this filter to embedConfiguration
:
var embedConfiguration = {
type: 'report',
id: json.ReportId,
embedUrl: json.EmbedUrl,
tokenType: models.TokenType.Embed,
accessToken: json.EmbedToken,
filters: [basicFilter]
};
有關配置嵌入元素的詳細信息,請參閱 嵌入配置詳細信息 并查看有關如何使用不同過濾器類型和應用它們的更多信息,請參閱 過濾器.
For more information about configuring the embed element, see Embed Configuration Details and to see more information on how to use different filter types and applying them, see Filters.
這篇關于如何在報告中設置過濾器 Power BI 嵌入式 javascript的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!