<?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: Create Custom visuals - Set measure color in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Create-Custom-visuals-Set-measure-color/m-p/836692#M21283</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Did you manage to resolve this issue? I am having the same problem and can't figure out how to read the measure colors&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Nishant&lt;/P&gt;</description>
    <pubDate>Mon, 04 Nov 2019 23:08:47 GMT</pubDate>
    <dc:creator>Nishantjain</dc:creator>
    <dc:date>2019-11-04T23:08:47Z</dc:date>
    <item>
      <title>Create Custom visuals - Set measure color</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-Custom-visuals-Set-measure-color/m-p/673381#M19166</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am developing custom visual for a clustered column chart and I am facing issue while implementing the color palette.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have added the color palette successfully but cannot use the color value for the series.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get it to work withCategory, but I need to set the color per the measure. I am having trouble implementing&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="pl-smi"&gt;host&lt;/SPAN&gt;.&lt;SPAN class="pl-en"&gt;createSelectionIdBuilder&lt;/SPAN&gt;().withMeasure()&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;Once I select a color from palette it returns to the default.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code snipet for updating the view model and for rendering the Power BI properties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        //set up viewmovdel
        //queries power bi to gather data that user is using for the visual
        //power bi makes VisualUpdateOptions available with every call to the update method
        private getViewModel(options: VisualUpdateOptions): ViewModel {

            //option.dataViews stores power bi's query data based on shape (e.g. tabular, matrix, tree, etc.)
            //configured in capabilities.json dataViewMappings.categorical
            //https://microsoft.github.io/PowerBI-visuals/docs/concepts/dataviewmappings/
            let dv = options.dataViews;

            //empty viewModel
            //The empty viewModel will be returned in the case where there is no data to show            
            let viewModel: ViewModel = {
                dataPoints: []
                , maxValue: 0
                , minValue: 0
                , highlights: false
            };

            //Check to make sure that all data that is needed is present before attempting to render the visual
            if (!dv
                || !dv[0]
                || !dv[0].categorical
                || !dv[0].categorical.categories
                || !dv[0].categorical.categories[0].source
                || !dv[0].categorical.values
                || !dv[0].metadata
            )
                return viewModel;

            //Only accepting one dataview
            //  The type that we are using is the categorical dataview
            let view = dv[0].categorical;

            //because we are accepting multiple measure types, iterate through each
            for (let i = 0, len = view.values.length; i &amp;lt; len; i++) {
                //We are only allowing for one series, so use index of 0 for categories
                let categories = view.categories[0];
                let values = view.values[i];
                let highlights = values.highlights;
                let objects = categories.objects;
                let metadata = dv[0].metadata;
                //metadata values will be used to populate the tooltip
                let categoryColumnName = metadata.columns.filter(c =&amp;gt; c.roles["category"])[0].displayName;
                let measureColumnName = metadata.columns.filter(c =&amp;gt; c.roles["measure"])[i].displayName;

                //iterate over all category-value pairs by index
                for (let j = 0, len = Math.max(categories.values.length, values.values.length); j &amp;lt; len; j++) {

                    //push datapoints into the view
                    viewModel.dataPoints.push({

                        category: &amp;lt;string&amp;gt;categories.values[j],
                        measure: &amp;lt;string&amp;gt;values.source.displayName,
                        value: &amp;lt;number&amp;gt;values.values[j],

                        //Since this property is data-bound, the property value is stored in the objects array
                        //if objects array exists and the color for 
                        color: objects &amp;amp;&amp;amp; objects[j] &amp;amp;&amp;amp; dataViewObjects.getFillColor(objects[i], {
                            objectName: "dataColors"
                            , propertyName: "fill"
                        }, null) || this.host.colorPalette.getColor(&amp;lt;string&amp;gt;categories.values[i]).value,

                        //a new SelectionIdBuilder is needed everytime a new selection id is needed
                        identity: this.host.createSelectionIdBuilder()
                            //slice over category column at position i
                            .withCategory(categories, j)
                            .createSelectionId(),
                        
                        measureIdentity: this.host.createSelectionIdBuilder()
                            .withMeasure(values.source.queryName)
                            .createSelectionId(),

                        //checks to see if the highlights array is defined
                        // then checks to see if any value exists in the same position of the corresponding
                        // values array, not the metadata array
                        highlighted: highlights ? highlights[j] ? true : false : false,

                        //set up the base tooltip for each datapoint
                        tooltips: [{
                            displayName: categoryColumnName,
                            value: &amp;lt;string&amp;gt;categories.values[j]
                        }, {
                            displayName: measureColumnName,
                            //if the value doesn't have a decimal, set value to 0 decimal places, otherwise set it 2 decimal places
                            value: ((&amp;lt;number&amp;gt;values.values[j]) == Math.floor(&amp;lt;number&amp;gt;values.values[j])) ? (&amp;lt;number&amp;gt;values.values[j]).toFixed(0) : (&amp;lt;number&amp;gt;values.values[j]).toFixed(2)
                        }]
                    });
                }
            }

            //populate the single-valued datapoints
            viewModel.maxValue = d3.max(viewModel.dataPoints, d =&amp;gt; d.value);
            viewModel.minValue = d3.min(viewModel.dataPoints, d =&amp;gt; d.value);
            //boolean to see whether or not there are any highlights
            viewModel.highlights = viewModel.dataPoints.filter(d =&amp;gt; d.highlighted).length &amp;gt; 0;

            return viewModel;
        }

        //called by power bi everytime it needs to render the properties pane
        //for updating a property/property value in the properties pane
        //Driven by the object object in capabilities.json
        //called one time per property group in object object any time anything is updated in power bi
        //* Note - this takes place outside of the update loop
        public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {

            let propertyGroupName = options.objectName;
            let properties: VisualObjectInstance[] = [];

            switch (propertyGroupName) {
                case "xAxis":
                    properties.push({
                        objectName: propertyGroupName,
                        properties: {
                            show: this.settings.axis.x.show.value
                        },
                        selector: null
                    });
                    break;

                case "yAxis":
                    properties.push({
                        objectName: propertyGroupName,
                        properties: {
                            show: this.settings.axis.y.show.value
                            , invert: this.settings.axis.y.invert.value
                            , minimumDomain: this.settings.axis.y.minimumDomain.value
                            , integers: this.settings.axis.y.integers.value
                            , gridlines: this.settings.axis.y.gridlines.show.value
                        },
                        selector: null
                    });
                    break;

                case "dataColors":
                {
                    if (this.viewModel) {

                        //list out all data point properties that are needed
                        let allColorDatPoints = [];
                        this.viewModel.dataPoints.forEach(dp =&amp;gt; {
                            allColorDatPoints.push({measureIdentity: dp.measureIdentity, measure: dp.measure, color: dp.color})
                        })

                        //get unique list of needed data point properties
                        let colorDatPoints = [];
                        for(let i=0; i&amp;lt;allColorDatPoints.length;i++){
                            let exists = false;
                            for(let j=0; j&amp;lt;colorDatPoints.length; j++){
                                if(//allColorDatPoints[i].measureIdentity == colorDatPoints[j].measureIdentity
                                //&amp;amp;&amp;amp; 
                                allColorDatPoints[i].measure == colorDatPoints[j].measure
                                &amp;amp;&amp;amp; allColorDatPoints[i].color == colorDatPoints[j].color
                                ) {
                                    exists = true;
                                }
                            }
                            (!exists) ? colorDatPoints.push(allColorDatPoints[i]) : null
                        }
                        
                        for (let cdp of colorDatPoints) {

                            properties.push({
                                objectName: cdp.measure
                                , displayName: cdp.measure
                                , properties: {
                                    fill: cdp.color
                                },
                                selector: cdp.measureIdentity.getSelector()
                            });
                        }

                    }
                    break;
                }
            }
            return properties;
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 17:49:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-Custom-visuals-Set-measure-color/m-p/673381#M19166</guid>
      <dc:creator>giammariam</dc:creator>
      <dc:date>2019-04-18T17:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create Custom visuals - Set measure color</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-Custom-visuals-Set-measure-color/m-p/836692#M21283</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Did you manage to resolve this issue? I am having the same problem and can't figure out how to read the measure colors&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Nishant&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 23:08:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-Custom-visuals-Set-measure-color/m-p/836692#M21283</guid>
      <dc:creator>Nishantjain</dc:creator>
      <dc:date>2019-11-04T23:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create Custom visuals - Set measure color</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-Custom-visuals-Set-measure-color/m-p/837978#M21293</link>
      <description>&lt;P&gt;With measures, I've only got it to work by using the &lt;FONT face="courier new,courier"&gt;queryName&lt;/FONT&gt; property from the measure&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;DataViewMetadataColumn&lt;/FONT&gt;. If you use this rather than &lt;FONT face="courier new,courier"&gt;getSelector()&lt;/FONT&gt; against a &lt;FONT face="courier new,courier"&gt;SelectionId&lt;/FONT&gt; it should push it into the data view correctly. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If done right, you should see an &lt;FONT face="courier new,courier"&gt;objects&lt;/FONT&gt; key underneath your column in the metadata, e.g.:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 754px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/206206i9A0A76BD10697FCD/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You should be able to make out the &lt;FONT face="courier new,courier"&gt;queryName&lt;/FONT&gt; property from this screenshot too.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This should then get persisted into your object enumeration, e.g.:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 158px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/206209iCC0C28D61C3860AA/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hopefully this is enough to get you moving; if not, you might need to share some code so we can have a look at specifics.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Good luck!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Daniel&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 23:29:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-Custom-visuals-Set-measure-color/m-p/837978#M21293</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2019-11-05T23:29:14Z</dc:date>
    </item>
  </channel>
</rss>

