Power Bi Javascript API - 修改视觉效果

问题描述 投票:0回答:1

我正在使用一个Power BI嵌入式解决方案。 我知道如何在报表上选择一个特定的视觉效果。 我想完成的是突出显示或视觉上改变特定的视觉效果,这样我就可以识别特定的视觉效果。 在我的解决方案中,我创建了一个自定义讨论窗格,用户可以在其中就特定数据点进行交流。 我希望能够显示页面上哪些数据点有相关的评论,这样我就可以把用户吸引到这些点上。 是否有办法使用Javascript API来改变Power BI Visual的视觉外观? 如果有,有谁有一个如何改变它的例子吗?

javascript powerbi powerbi-embedded
1个回答
0
投票

我已经找到了一个解决方案。 通过使用另一个微软库 Power BI报表编写. 在这个库中,你可以选择一个特定的视觉效果,然后对其应用属性。 这个代码示例来自 git hub页面 是。

report.getPages()
  .then(function (pages) {

      // Retrieve active page.
      var activePage = pages.find(function (page) {
          return page.isActive
      });

      activePage.getVisuals()
        .then(function (visuals) {

            // Retrieve the wanted visual. (replace "VisualContainer1" with the requested visual name)
            var visual = visuals.find(function (visual) {
                return visual.name == "VisualContainer1";
            });

            const selector: models.IVisualPropertySelector = { 
                objectName: "title",
                propertyName: "alignment"
            };

            const propertyValue: models.IVisualPropertyValue = {
                schema: "http://powerbi.com/product/schema#property",
                value: "center" // models.TextAlignment.Center
            };

            visual.setProperty(selector, propertyValue)
                .catch(errors => {
                    // Handle error
                    console.log(errors);
                });
        });
  });
© www.soinside.com 2019 - 2024. All rights reserved.