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
SriThiru
Frequent Visitor

How to add Object dynamically in capabilities.json using enumerateObjectInstances method

How to dynamically add new objects in properties pane like the following screenshot (seen in donut chart), inside the enumerateObjectInstances method.

dynamicproperties.PNG

2 REPLIES 2
dm-p
Super User
Super User

Hi @SriThiru,

It's hard to provide a targeted answer without knowing your choice of data view mapping and view model, but the high-level approach to this is that:

  1. You create a 'template' property (or properties) within the object in capabilities.json for the property that you wish to bind to your data. This has the structure and typing that the main window needs to know about when the visual is initialised, as you cannot dynamically manipulate the capabilities post-initialisation.
  2. When you process your dataset, you assign a selector (reconciling the data point's grouping) to the attribute that you wish to bind to the properties pane. Selectors are not just used for interactivity and are the way of bridging your view model to the original data view that Power BI sends through.
  3. When enumerating your settings (enumerateObjectInstances), you use the knowledge of your data to push additional object instances that reference the template property (or properties) for each selector.

How to do this will very much depend on how you are intending to structure your data within the visual, and whether it is possible to retain the correct context against the data view that is sent to the visual by Power BI.

The easiest way to have a look and play with a working example would be to go through the sample bar chart visual and see what's being done to achieve the solution there. Specific points of interest in this codebase are:

  1. Template property
  2. How the selector is assigned when processing the view model (and how color is retrieved from properties)
  3. How the dynamic properties are added to the object when settings are enumerated

Here's an additional post where the author has a correct setup and shows these three in context (but the problem was actually something else).

Hopefully this should help you get a little further. Good luck!

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




SriThiru
Frequent Visitor

Thanks @dm-p , for the detailed response, and the code reference, I'll try your suggestions.

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.