Forum Discussion

smpa01's avatar
smpa01
Icon for Community Champion rankCommunity Champion
4 years ago
Solved

How to render d3 charts in Power BI currently

dm-p v-viig    I am trying to find out how can I render a d3.js scripted chart in Power BI   Sample HTML which works fine in the browser.   <!DOCTYPE html> <html lang="en"> <head> <...
  • dm-p's avatar
    4 years ago

    Hi smpa01,

    As noted on the website, HTML Content doesn't support JavaScript. If you want to use D3 to its full potential, I'd suggest creating a custom visual. I have a blog post here (pt2) which may help with converting over existing code to a custom visual.

    For your example, I notice you're only really using the DOM manipulation capabilities of D3 rather than things such as scaling, so you could do your example in HTML Content by writing a measure that creates the SVG elements and binds the data. Assuming your data is in a table called Test with the same columns as your example:

    SVG Circles = 
    VAR Circles =
        CONCATENATEX(
            'Test',
            "<circle cy='60' cx='" & 'Test'[x] & "' r='" & 'Test'[r]
                & "'/>"
        )
    RETURN
        "<svg width='350'>" & Circles & "</svg>"

    ...which would result in the following output in the visual:

    Alternatively, you can use Charticulator or Deneb to produce richer visual content without the overhead of writing a custom visual from scratch. Neither are D3, but they expose a reasonably broad grammar of graphics, which can be more convenient than coding. Deneb exposes the Vega and Vega-Lite languages (which can do a lot of common D3 use cases with much less code) and has the additional benefit of being certified.

    Regards,

    Daniel