Shi*_*lpa 4 javascript powerbi powerbi-embedded
在尝试从 .Net MVC 应用程序中的嵌入式 Power BI 报告获取视觉效果时,我尝试了来自嵌入式 Power BI Playground 网站的下面提到的代码。但我无法获得视觉效果。在调试时,我可以看到 Report 的 getPages 属性的值如下:
\ngetPages: \xc6\x92 ()arguments: null caller: null length: 0 name: ""
还有console.log(report.getPages());给予
[[PromiseStatus]]: "pending" [[PromiseValue]]: undefined
PF 我尝试过的代码:
\n// Get a reference to the embedded report HTML element\nvar embedContainer = $(\'#embedContainer\')[0];\n\n// Get a reference to the embedded report.\nreport = powerbi.get(embedContainer);\n\n// Retrieve the page collection and get the visuals for the first page.\nreport.getPages()\n .then(function (pages) {\n // Retrieve active page.\n var activePage = pages.filter(function (page) {\n return page.isActive\n })[0];\n\n activePage.getVisuals()\n .then(function (visuals) {\n Log.log(\n visuals.map(function (visual) {\n return {\n name: visual.name,\n type: visual.type,\n title: visual.title,\n layout: visual.layout\n };\n }));\n })\n .catch(function (errors) {\n Log.log(errors);\n });\n })\n .catch(function (errors) {\n Log.log(errors);\n });\nRun Code Online (Sandbox Code Playgroud)\n
你有一个时间问题。使用 PowerBI 事件处理程序,除非您知道报表已完全加载、呈现且可用,否则不要对报表应用更改。为此,您可以确保 Rendered 事件。
https://github.com/Microsoft/PowerBI-JavaScript/wiki/Handling-Events
以下是获取页面、从页面获取视觉对象以及从视觉对象导出数据的示例。
var report = powerbi.embed(reportContainer, config);
report.on("rendered", function (event) {
// do stuff here like get pages, export data, apply filters or whatever it is you want to do to manipulate the report
report.getPages().then((pages) => {
pages[0].getVisuals().then((visuals) => (d = visuals));
});
var v = d[1].exportData(models.ExportDataType.Summarized, 100);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1688 次 |
| 最近记录: |