我想在我的报告 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:
例如,过滤名为 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!