Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to access general properties Width and Height in custom visual

Is it possible to get Width and Height properties in code? I know these "general" properties are created by default once you add objects: {} in capabilities.json.

 

SettingsSettings

Based on some requirement and to achieve something, I want to access this width and height properties so I can modify it via code on the go.  

6 REPLIES 6
alihm
Power BI Team
Power BI Team

To get these properties you can use:

let pages = await report.getPages();
let width = pages[0].defaultSize.width;
let height = pages[0].defaultSize.height;
 
To change the width and the height of a specific page, you will need to use custom layout:
Anonymous
Not applicable

@alihm   Thank you for your reply.

 

what are pages[0] here? How can I access it in the visual.ts file? I only want to access the width and height of my custom visual.

drop1.PNG

This is a dropdown. Once I click it, it should open outside of the content area. As it is loading in an iframe, I can't achieve using CSS or javascript/jQuery methods available.

 

That's why I want to increase the width and height of this particular custom visual once the user opens the dropdown.

drop2.PNG

 

Please see this.

Hi aakash1401 ,

 

Inside visual.ts you have the update method, this is the function that gets called everytime the visual renders. 

This method receives one argument of type "VisualUpdateOptions", inside this argument you have a property called viewport this property includes the width & height of the custom visual.

 

So basically inside the update method you can do:

let width = options.viewport.width;

let height = options.viewport.height;

 

Thanks,

Idan

Anonymous
Not applicable

@idgoldfa This just returns the value of height and width. Updating in visual.ts doesn't change its Width and Height that is present in 'General' format properties. Any idea how to do that.

@Anonymousunfortunately there is no API at the moment for modifying the height & width of a visual from inside the visual code. 

Anonymous
Not applicable

@idgoldfa How can team accept it as Enhancement, Future release if this is applicable as a valid requirement.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.