powerbi embedded - TypeError: activePage.createVisual is not a function (Power BI JavaScript API) - Stack Overflow

I'm trying to dynamically add a visual to an embedded Power BI report using the createVisual() met

I'm trying to dynamically add a visual to an embedded Power BI report using the createVisual() method as documented here: Microsoft Docs: Create a visual in Power BI embedded

However, when I try to execute the following code:

try {
      const pages = await this.report.getPages();
      const activePage = pages.find(p  => p.isActive);
      if(!activePage)return;
      const visualLayout = {
        x: 0,
        y: 0,
        z: 0,
        width: 300,
        height: 300
      };
      const visualResponse = await activePage.createVisual('pieChart', visualLayout, false);
      const newVisual = visualResponse.visual;
      await newVisual.update({ title: "Count of RelatedParty by TaxJurisdiction" });

      console.log(" Visual created:", newVisual);

    } catch (error) {
      console.error(" Error creating visual:", error);
    }

I get this error:

TypeError: activePage.createVisual is not a function
at _PowerBiService.<anonymous> (power-bi-service.service.ts:151:47)
at Generator.next (<anonymous>)
at fulfilled (main.js:10:24)

What I’ve Checked So Far:

  • white_heavy_check_mark: My Power BI JavaScript API version is up to date ( "powerbi-client": "^2.23.1")
  • white_heavy_check_mark: The report is properly embedded and interactive
  • white_heavy_check_mark: getPages() works fine, meaning activePage is a valid object

Any insights or solutions would be really helpful!

Thanks in advance!

I'm trying to dynamically add a visual to an embedded Power BI report using the createVisual() method as documented here: Microsoft Docs: Create a visual in Power BI embedded

However, when I try to execute the following code:

try {
      const pages = await this.report.getPages();
      const activePage = pages.find(p  => p.isActive);
      if(!activePage)return;
      const visualLayout = {
        x: 0,
        y: 0,
        z: 0,
        width: 300,
        height: 300
      };
      const visualResponse = await activePage.createVisual('pieChart', visualLayout, false);
      const newVisual = visualResponse.visual;
      await newVisual.update({ title: "Count of RelatedParty by TaxJurisdiction" });

      console.log(" Visual created:", newVisual);

    } catch (error) {
      console.error(" Error creating visual:", error);
    }

I get this error:

TypeError: activePage.createVisual is not a function
at _PowerBiService.<anonymous> (power-bi-service.service.ts:151:47)
at Generator.next (<anonymous>)
at fulfilled (main.js:10:24)

What I’ve Checked So Far:

  • white_heavy_check_mark: My Power BI JavaScript API version is up to date ( "powerbi-client": "^2.23.1")
  • white_heavy_check_mark: The report is properly embedded and interactive
  • white_heavy_check_mark: getPages() works fine, meaning activePage is a valid object

Any insights or solutions would be really helpful!

Thanks in advance!

Share Improve this question asked Mar 24 at 14:58 mestumestu 1267 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

createVisual is a Report authoring API which is not present in "powerbi-client" package. You need to install powerbi-report-authoring package to use that API.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744245214a4564894.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信