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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
KennethWang
Frequent Visitor

Custom Object Formatting

Hi All,

 

I tried searching for this topic thinking it would be popoular. I just couldn't nail the keywords correctly and nothing comes up.

 

My question is, when you build a custom visual, is there a way to dynamic populate the formatting tab so that you can create some settings/formatting around them? For example, in the diagram below, the data color for each data node can be changed individually.

 

CustomFormatting.jpg

 

Is this possible in custom visual? Thank you.

 

Regards,

 

Kenneth

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @KennethWang

This is possible in custom visuals - there is a specific portion of the tutorial in the sample bar chart repo for it, and this is pretty much the scenario you've added the image for.

This is all covered in the example in more detail but in short, you need to do the following:

  • Define a template object in your capabilities.json you can use for each value.
  • Add a property to your view model for each category's colour.
  • Create selectionIds for the items you want to appear in the properties pane (more about selection) when mapping your view model.
  • Also, when mapping your view model, you need to set the colour by looking in the dataView for any stored values based on this selectionId. If there is nothing found (which there typically won't be the first time), then this needs to be assigned a suitable default.
  • In your enumerateObjectInstances method (in visual.ts), you need to iterate through your categories from your view model and create colour pickers based on the vales set in your view model mapping, and use the template object defined in your capabilities.json above. Each one needs the selectionId also, so it knows where to store the value to in the dataView when the user sets it in the properties pane.

If this is all set up accordingly, the colour should be stored in the dataView and retrieved correctly for subsequent updates. If the colour changes back after selection, then there is an issue with the selectionId and you might need to review this to get it to work.

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)




View solution in original post

2 REPLIES 2
dm-p
Super User
Super User

Hi @KennethWang

This is possible in custom visuals - there is a specific portion of the tutorial in the sample bar chart repo for it, and this is pretty much the scenario you've added the image for.

This is all covered in the example in more detail but in short, you need to do the following:

  • Define a template object in your capabilities.json you can use for each value.
  • Add a property to your view model for each category's colour.
  • Create selectionIds for the items you want to appear in the properties pane (more about selection) when mapping your view model.
  • Also, when mapping your view model, you need to set the colour by looking in the dataView for any stored values based on this selectionId. If there is nothing found (which there typically won't be the first time), then this needs to be assigned a suitable default.
  • In your enumerateObjectInstances method (in visual.ts), you need to iterate through your categories from your view model and create colour pickers based on the vales set in your view model mapping, and use the template object defined in your capabilities.json above. Each one needs the selectionId also, so it knows where to store the value to in the dataView when the user sets it in the properties pane.

If this is all set up accordingly, the colour should be stored in the dataView and retrieved correctly for subsequent updates. If the colour changes back after selection, then there is an issue with the selectionId and you might need to review this to get it to work.

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)




Thank you!

 

I can't mention enough how much that has helped. It took me a while to get through your points layers by layers and also with reference to the bar chart. I also fell into the SelectionID issue as you have foresighted, mainly because I have multiple Categories and also processed the categories in a way different from the usual bar charts. 

 

You are awesome!

 

Regards,

 

Kenneth

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors