<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Add a basic Legend in a custom visual in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/953127#M22532</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/21853"&gt;@augustindelaf&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry missed to provide some extra information:&lt;/P&gt;&lt;P&gt;1. I am using d3-selection and you can import it via&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { select, Selection } from "d3-selection";&lt;/LI-CODE&gt;&lt;P&gt;2. And just before the settings the legend variable set the moveX variable as:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let moveX = 0;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;3. Sorry I mean indeed the contructor instead of the init.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-JP&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2020 15:53:44 GMT</pubDate>
    <dc:creator>jppp</dc:creator>
    <dc:date>2020-02-28T15:53:44Z</dc:date>
    <item>
      <title>Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/949039#M22497</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to get that from Chart Utils :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Microsoft/powerbi-visuals-utils-chartutils/blob/master/docs/api/legend.md" target="_blank"&gt;https://github.com/Microsoft/powerbi-visuals-utils-chartutils/blob/master/docs/api/legend.md&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and I followed this to install the librarie:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/microsoft/powerbi-visuals-utils-chartutils/blob/master/docs/usage/installation-guide.md" target="_blank"&gt;https://github.com/microsoft/powerbi-visuals-utils-chartutils/blob/master/docs/usage/installation-guide.md&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But without any changes to my code and despite it compiles, the Visual crashes at rendering :&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Uncaught SyntaxError: Cannot use import statement outside a module
    at Object.i [as injectJsCode] (customVisualsHost.bundle.min.js:19)
    at r (customVisualsHost.bundle.min.js:21)
    at i.loadWithoutResourcePackage (customVisualsHost.bundle.min.js:21)
    at i.executeMessage (customVisualsHost.bundle.min.js:21)
    at i.onMessageReceived (customVisualsHost.bundle.min.js:21)
    at customVisualsHost.bundle.min.js:21
    at e.invokeHandler (customVisualsHost.bundle.min.js:20)
    at e.dispatchMessage (customVisualsHost.bundle.min.js:20)
    at e.onMessageReceived (customVisualsHost.bundle.min.js:20)
    at windowMessageHandler (customVisualsHost.bundle.min.js:20)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there another library to draw a legend ? I do not need sophisticated one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 14:09:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/949039#M22497</guid>
      <dc:creator>augustindelaf</dc:creator>
      <dc:date>2020-02-26T14:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/949780#M22501</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/21853"&gt;@augustindelaf&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Looks like that documentation is still out of date and uses the older import methods. I worked this out a while ago and the correct steps are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Import library as normal:&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="markup"&gt;npm install powerbi-visuals-utils-chartutils --save&lt;/LI-CODE&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Skip over the bits about &lt;FONT face="courier new,courier"&gt;pbiviz.json&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;tsconfig.json&lt;/FONT&gt;, as the newer SDK will bundle these up automatically&lt;/STRONG&gt;. Older versions of the SDK needed these dependencies including manually.&lt;/LI&gt;
&lt;LI&gt;Include the CSS assets as documented in your style.css:&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="markup"&gt;@import (less) "node_modules/powerbi-visuals-utils-interactivityutils/lib/index.css";
@import (less) "node_modules/powerbi-visuals-utils-chartutils/lib/index.css";&lt;/LI-CODE&gt;
&lt;UL&gt;
&lt;LI&gt;You then need to import the interfaces you need - &lt;A href="https://github.com/dm-p/powerbi-visuals-smlc/blob/master/src/dom/ChartHelper.ts#L3-L7" target="_self"&gt;here's an example in one of my custom visuals&lt;/A&gt;. You might need to change this based on your requirements.&lt;/LI&gt;
&lt;LI&gt;You'll need to add a container for the legend into your visual DOM - &lt;A href="https://github.com/dm-p/powerbi-visuals-smlc/blob/master/src/dom/ChartHelper.ts#L91-L101" target="_self"&gt;here's the example from mine&lt;/A&gt; and yours will differ depending on how your visual needs to work.&lt;/LI&gt;
&lt;LI&gt;You can then use the &lt;A href="https://github.com/microsoft/powerbi-visuals-utils-chartutils/blob/master/src/legend/legendInterfaces.ts#L92" target="_self"&gt;&lt;FONT face="courier new,courier"&gt;ILegend&lt;/FONT&gt; interface&lt;/A&gt; methods with supplied values to draw your legend as per the examples in your linked page. Here's the parts of my previously linked repo where I manage &lt;A href="https://github.com/dm-p/powerbi-visuals-smlc/blob/master/src/dom/ChartHelper.ts#L131-L185" target="_self"&gt;rendering the legend&lt;/A&gt; and &lt;A href="https://github.com/dm-p/powerbi-visuals-smlc/blob/master/src/dom/ChartHelper.ts#L123-L129" target="_self"&gt;removing it&lt;/A&gt; if I decide I don't have enough room.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Hopefully this gives you some guidance on how to proceed. Good luck!&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 21:09:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/949780#M22501</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2020-02-26T21:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/951228#M22518</link>
      <description>&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much, your answer helped a lot to understand how it works.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have subsidiary questions.&lt;/P&gt;&lt;P&gt;1) I do not see where to set the inputdata in your renderLegend function (for example, I expected an object parameter in the drawLegend method) to have the correct behavior :&amp;nbsp;&lt;BR /&gt;For each dot forming the scatter plot of my visual (all dots having a different shape), I need to display in the legend the identifier of the data with the correct shape used and the correct color.&lt;/P&gt;&lt;P&gt;Legend data is usually a parameter field in the panel&amp;nbsp; but I don't need it because the scatter plot data I have is the information I need.&lt;/P&gt;&lt;P&gt;2) I have no idea what format is your Constants in the dependancies section (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import { VisualConstants } from '../constants'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;) you use to manage the dimensions of your legend box.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) In case I have to use the fields panel after all, is it have I to use datarole + capabilities.json to do it ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Conclusion :&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wish not to use data field in the panel to get data for legend because it wil be redundant with the data used by the visual itself but rather the data object I built (in my update.ts) as an array of objects having all informations needed.&lt;/P&gt;&lt;P&gt;Please feel free to tell me if my wish is not a best practice.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 15:59:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/951228#M22518</guid>
      <dc:creator>augustindelaf</dc:creator>
      <dc:date>2020-02-27T15:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/951743#M22521</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/21853"&gt;@augustindelaf&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lately I am always creating legend myself: tried the legend of the&amp;nbsp;chartutils, but found it to complicated/to little control.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I do it:&lt;/P&gt;&lt;P&gt;1. part of the method to convert the dataView data to your internal data structure store the legend values seperatly&lt;/P&gt;&lt;P&gt;2. in the &lt;EM&gt;init&lt;/EM&gt; method add an SVG &lt;STRONG&gt;g&lt;/STRONG&gt; container/placeholder and store in in a private variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this.legend = this.svg.append("g").classed("legend", true);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. use d3 functionallity to create the legend based on the data structure of step 1 and allign all the legend labels not to overlap each other, see the &lt;FONT face="courier new,courier"&gt;.each(function () {})&lt;/FONT&gt; part&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this.legend
    .selectAll(".legendItem")
    .data(legendNodes)
    .join(enter =&amp;gt; enter
        .append("g")
        .classed("legendItem", true)
            .each(function (d) {
                select(this)
                    .append("circle")
                    .classed("legendMarker", true)
                    .attr("r", 5)
                    .style("fill", d.data.color)
                select(this)
                    .append("text")
                    .classed("legendText", true)
                    .attr("x", 7.5)
                    .attr("y", 4)
                    .style("alignment-baseline", "baseline")
                    .text(d.data.label.value)
            })
            .each(function () {
                let size = (&amp;lt;SVGGElement&amp;gt;this).getBoundingClientRect();
                select(this)
                    .attr("transform", `translate(${moveX} 0)`)
                moveX += size.width + 5;
            }),
        update =&amp;gt; update
                .each(function (d) {
                    select(this)
                        .selectAll(".legendMarker")
                        .style("fill", d.data.color)
                    select(this)
                        .selectAll(".legendText")
                        .text(d.data.label.value)
                })
                .each(function (d) {
                    let size = (&amp;lt;SVGGElement&amp;gt;this).getBoundingClientRect();
                    select(this)
                        .attr("transform", `translate(${moveX} 0)')
                    moveX += size.width + 5;
                }),
            exit =&amp;gt; exit
                .remove()
            );​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. Positioning of the legend you can do via the legend container including the visibility if needed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Feel free to see if this is working for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-JP&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 21:39:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/951743#M22521</guid>
      <dc:creator>jppp</dc:creator>
      <dc:date>2020-02-27T21:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/953091#M22527</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/3821"&gt;@jppp&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I tried your code but sadly, nothing displays yet : I am reviewing if I made no mistake.&lt;/P&gt;&lt;P&gt;To help me for my reviewing, I have some questions :&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) You use the keyword "select" in your function, This keyword is unknown in my code. What does it refer to ? I assumed "selectAll".&lt;/P&gt;&lt;P&gt;2) There is the variable&amp;nbsp;moveX. I assume it is a number but where to initialize it ?&lt;/P&gt;&lt;P&gt;3) For your 2) I have no Init&amp;nbsp; method, I assume the init of the legend to be in the constructor. Am I correct ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again thank you for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 15:42:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/953091#M22527</guid>
      <dc:creator>augustindelaf</dc:creator>
      <dc:date>2020-02-28T15:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/953127#M22532</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/21853"&gt;@augustindelaf&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry missed to provide some extra information:&lt;/P&gt;&lt;P&gt;1. I am using d3-selection and you can import it via&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { select, Selection } from "d3-selection";&lt;/LI-CODE&gt;&lt;P&gt;2. And just before the settings the legend variable set the moveX variable as:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let moveX = 0;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;3. Sorry I mean indeed the contructor instead of the init.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-JP&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 15:53:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/953127#M22532</guid>
      <dc:creator>jppp</dc:creator>
      <dc:date>2020-02-28T15:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/953165#M22533</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/3821"&gt;@jppp&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The legend appeared on first rendering but disapeared on updating.&lt;/P&gt;&lt;P&gt;I will try to relocate the init of the Legend to understand why.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, your contribution saved me&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 16:28:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/953165#M22533</guid>
      <dc:creator>augustindelaf</dc:creator>
      <dc:date>2020-02-28T16:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add a basic Legend in a custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/3482961#M44982</link>
      <description>&lt;P&gt;Hi guys,&lt;BR /&gt;&lt;BR /&gt;Thanks for your contribution!&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/21853"&gt;@augustindelaf&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/3821"&gt;@jppp&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The legends have been developed through the above code. Now, how can we handle the overflow of legend items or how can we add buttons that works like standard power bi legend?&lt;BR /&gt;Also need to add the title.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AakashMarasini_0-1697623723132.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/982659iFABB6DE3FC0EDEBD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AakashMarasini_0-1697623723132.png" alt="AakashMarasini_0-1697623723132.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please help me on this.&lt;BR /&gt;&lt;BR /&gt;Thank You!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2023 10:13:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Add-a-basic-Legend-in-a-custom-visual/m-p/3482961#M44982</guid>
      <dc:creator>AakashMarasini</dc:creator>
      <dc:date>2023-10-18T10:13:05Z</dc:date>
    </item>
  </channel>
</rss>

