Forum Discussion

filipwydra's avatar
filipwydra
Frequent Visitor
4 years ago
Solved

Auto update custom vizualization

Hello,   I develop custom Gantt Chart for Power BI using TS and D3.js. I'm facing a problem with re-rendering my visual once I add or modify fields which are meaures. In this case only "Phases" are...
  • dm-p's avatar
    4 years ago

    Hi filipwydra,

    Thanks for provising your capabilities, but this very much sounds like a common misstep when setting up a D3 visual. Most examples work with a static data set, so don't manage events where the data may change, which is common need with Power BI visuals (as you're experiencing). As I haven't seen your code, I can only assume it's the same, but I'd recommend checking the detail below first.

    If the visual only adds elements for additional data, or works when you refresh, it sounds like you aren't handling data joins with D3 correctly. It sounds like you might just be using .enter() to create your elements? If so you should consider adding handlers for .update() and .exit() so that D3 will re-bind data for already drawn elements and ensure that if elements are not required (e.g. less data in an update) then they are removed from the DOM. By refreshing the visual completely, this is sen by D3 as a new set of data and will only handle .enter() events, which is why it re-draws successfully.

    If you haven't seen it, this article is really good for explaining the concepts, with simple demos. There is a section dedicated to handling updates to the data as well, and what is needed for updating the DOM. I also have a custom visual for the purposes of teaching the SDK that you can look at and cross-check for an example how I'm managing these events, which may give you some ideas (point where joins are introduced | joins in finished visual).

    If you're sure that you've wired this up correctly, then it is possible that there may be an issue with how you're binding your data to your viewmodel for updates, but we'd need to see your code to assist further with that (although I'm confident it's the data join issue).

    Good luck,

    Daniel