如何在报告中设置过滤器 Power BI 嵌入式 javascript

How to set filters in reports power BI embedded javascript(如何在报告中设置过滤器 Power BI 嵌入式 javascript)
本文介绍了如何在报告中设置过滤器 Power BI 嵌入式 javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想在我的报告 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 客户端 - 在 filtersembedConfiguration 的属性,或作为 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why are button#39;s discouraged from navigation?(为什么不鼓励按钮导航?)
Should I use window.navigate or document.location in JavaScript?(我应该在 JavaScript 中使用 window.navigate 还是 document.location?)
Power BI - Get data from post request(Power BI - 从发布请求中获取数据)
Embed a Power BI report in React JS to get report instance(在 React JS 中嵌入 Power BI 报表以获取报表实例)
Create Report in Embed View via PowerBI API(通过 PowerBI API 在嵌入视图中创建报表)
Interactive Dialog Box in PowerBI(PowerBI 中的交互式对话框)