Search code examples
powerbivegadeneb

Power BI / Deneb / Vega - Control for position of legend


I'm using the Power BI add-in Deneb to display a Vega-based diagram in my report. The data fed into the Deneb add-in can be filtered by several Power BI slicers on the report page. These filters control for what is displayed in the Vega diagram.

The Vega diagram includes a legend, explaining the color codes applied. Now I'm facing the situation, that the absolute x position of the legend changes depending on which elements are displayed in the diagram (based on the external filter settings).

The legend is positioned to the right of my diagram, however the left x-position of the legend is not fix, but determined by the maximum length of the labels displayed in the legend, and this length subtracted from the width of my Deneb frame determines the x-position of the legend.

Would you have any recommendation how to statically position the legend to the right of my diagram?

Approach used so far was to set the legend attribute "orient" to "none" and use "legendX" however this made the legend collide with the content of my diagram, displaying the legend on top of my diagram, as the diagram itself consumes the whole width of the Deneb frame.


Solution

  • in the process of creating an anonymized sample file I managed to create the desired outcome.

    Issue was resolved by setting

    "autosize": {"contains": "padding", "type": "fit"}

    in Config section and configuring

    "width": 880, "autosize": "pad"

    as well as

    "orient": "none", "legendX": { "signal": "legend_x_position" }, "legendY": { "signal": "legend_y_position" }

    for the legends in Specification