Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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.Capabilitites.json

  • dm-p's avatar
    dm-p
    5 years ago

    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

4 Replies

    • Anonymous's avatar
      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.

      • dm-p's avatar
        dm-p
        Super User

        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