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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors