cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Super User I
Super User I

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




View solution in original post

2 REPLIES 2
Super User I
Super User I

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




View solution in original post

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
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.