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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Custom Visual DataBound properties

Hi,

 

I am working on a Custom Visual where I want to be able to select and apply a color for each category in my dataset. I managed to display ColorPalletes for each of the categories in the formatting options. After selecting colors in the ColorPalletes for the categories,

the color is not reflected immediately in the graph. I can see in the console output that the color selections are being saved in the viewmodel within the program but the colors do not change in the developer visual even though it is set on auto reload. I have to stop auto reload and reload again to see the new color selection I have made. I have added screenshots of the output and the code for reference.InkedCommunity_q1_LI.jpgInkedCommunity_q2_LI.jpgCapabilitites.jsonCapabilitites.jsonInkedCommunity_q4_LI.jpgInkedCommunity_q5_LI.jpgInkedCommunity_q6_LI.jpg

1 ACCEPTED SOLUTION

Hi @Anonymous,

Your viewModel and property enumeration are both fine. The issue is that the selection.enter() method only works for elements that need to be added to the DOM. Reloading the visual will clear the DOM so the selection.enter() method has to run again and re-create, so your colour values will be correct in these cases.

You can resolve by adding a selection.update() method to your d3 data join, to ensure your viewModel is re-bound to existing elements when the visual's update method runs.

I'm on leave at present so not able to provide a specfic solution until next week sometime but you can check the approach we applied in this post, or look at the enter-update-exit pattern for d3 and this should provide examples that you could apply here.

Good luck!

Daniel





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

Proud to be a Super User!


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




View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

Please review the following threads, hope they can help you resolve the problem.

.json and custom visuals with power bi theme possible?

Create Custom visuals - Set measure color

Best Regards

Anonymous
Not applicable

Thank you @Anonymous for your reply. I appreciate your help, but these threads do not quite address the problem I am facing. Thank you again.

Hi @Anonymous,

Your viewModel and property enumeration are both fine. The issue is that the selection.enter() method only works for elements that need to be added to the DOM. Reloading the visual will clear the DOM so the selection.enter() method has to run again and re-create, so your colour values will be correct in these cases.

You can resolve by adding a selection.update() method to your d3 data join, to ensure your viewModel is re-bound to existing elements when the visual's update method runs.

I'm on leave at present so not able to provide a specfic solution until next week sometime but you can check the approach we applied in this post, or look at the enter-update-exit pattern for d3 and this should provide examples that you could apply here.

Good luck!

Daniel





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

Proud to be a Super User!


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




Anonymous
Not applicable

Thank You @dm-p 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.