<?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: Problem with formatting and series in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Problem-with-formatting-and-series/m-p/3969256#M9786</link>
    <description>&lt;P&gt;Literally 3 minutes after posting the message I found the problem, and it works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  fillProp: DataViewObjectPropertyIdentifier = {
                objectName: "colorSelector",
                propertyName: "fill"
            };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The object property identifier was wrong.......&lt;/P&gt;&lt;P&gt;Thanks to myself lol&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For those interested, here is the full code:&amp;nbsp;&lt;A href="https://github.com/EquinetPaul/powerbi_multiple_axis_legend_linechart" target="_blank"&gt;EquinetPaul/powerbi_multiple_axis_legend_linechart: powerbi_multiple_axis_legend_linechart (github.com)&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jun 2024 15:36:25 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-06-03T15:36:25Z</dc:date>
    <item>
      <title>Problem with formatting and series</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Problem-with-formatting-and-series/m-p/3965894#M9733</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I'm developing a PowerBI custom visual to draw time series differentiated by a legend.&lt;BR /&gt;The problem I'm having is with formatting settings.&lt;BR /&gt;What I would like is to have a colorPicker in my formatting pane for each of my series.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I've already done:&lt;BR /&gt;- I created a "colorSelector" object in capabilities.json that will be a Slice for each series colorPicker&lt;BR /&gt;- I created a selection for each series using &lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/visuals/selection-api#create-selections-for-series" target="_blank" rel="noopener"&gt;this documentation&amp;nbsp; (Create selections for series)&lt;/A&gt;&lt;BR /&gt;- I used colorHelper to set the default color for series with colorPalette or find the color of the “colorSelector” object associated with a serie, &lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/visuals/utils-color#getcolorforseriesvalue" target="_blank" rel="noopener"&gt;based on this documentation&amp;nbsp;&lt;/A&gt;&lt;BR /&gt;- I populated the pane formatting based as much as possible on the barChat example&amp;nbsp;&lt;A href="https://github.com/microsoft/PowerBI-visuals-sampleBarChart/blob/main/src/barChartSettingsModel.ts#L185" target="_blank" rel="noopener"&gt;github&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I manage to get something but the behavior is bizarre:&lt;BR /&gt;- There's a colorPicker for each different series &lt;STRONG&gt;BUT when I change the color, it instantly reverts to its default value&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Paulhaha_0-1717242042522.png" style="width: 139px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1109578i730434FC27C2EDEB/image-dimensions/139x250?v=v2" width="139" height="250" role="button" title="Paulhaha_0-1717242042522.png" alt="Paulhaha_0-1717242042522.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I'm missing some information so that I can properly assign a color to each series and then retrieve them, but I haven't been able to find a solution for several days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I think&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The colorHelper can't find the color associated to the object but I tried to find the color &lt;A href="https://github.com/microsoft/PowerBI-visuals-sampleBarChart/blob/main/src/barChart.ts#L230" target="_blank" rel="noopener"&gt;in a manual way&lt;/A&gt; and there is the same result&lt;/LI&gt;&lt;LI&gt;There is a problem with the selection,&amp;nbsp;maybe I'm doing it wrong?&lt;/LI&gt;&lt;LI&gt;populateColorSelector is not implemented properly?&lt;/LI&gt;&lt;LI&gt;I'm not creating the data properly? (dataSeries)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I'd like to thank anyone who can help me understand the problem I encounter.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code:&lt;BR /&gt;&lt;STRONG&gt;capabilities.json&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "dataRoles": [
        {
            "displayName": "Categories",
            "name": "category",
            "kind": "Grouping"
        },
        {
            "displayName": "Measures",
            "name": "measure",
            "kind": "Measure"
        },
        {
            "displayName": "Series",
            "name": "series",
            "kind": "Grouping"
        }
    ],
    "objects": {
        "colorSelector": {
          "properties": {
            "fill": {
              "type": {
                "fill": {
                  "solid": {
                    "color": true
                  }
                }
              }
            }
          }
        }
      },
    "dataViewMappings": [
        {
            "categorical": {
                "categories": {
                    "for": {
                        "in": "category"
                    }
                },
                "values": {
                    "group": {
                        "by": "series",
                        "select": [{
                                "for": {
                                    "in": "measure"
                                }
                            }
                        ]
                    }
                }
            }
        }
    ],
    "privileges": []
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;settings.ts:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"use strict";

import { formattingSettings } from "powerbi-visuals-utils-formattingmodel";

import { dataSerie } from "./visual";

import FormattingSettingsCard = formattingSettings.SimpleCard;
import FormattingSettingsSlice = formattingSettings.Slice;
import FormattingSettingsModel = formattingSettings.Model;
import ColorPicker = formattingSettings.ColorPicker;

class ColorSelectorCardSettings extends FormattingSettingsCard {
    name: string = "colorSelector";
    displayName: string = "Data Colors";
    slices: FormattingSettingsSlice[] = [];
}

export class VisualFormattingSettingsModel extends FormattingSettingsModel {
    colorSelector = new ColorSelectorCardSettings();

    cards: FormattingSettingsCard[] = [this.colorSelector];

    populateColorSelector(dataPoints: dataSerie[]) {
        const slices: FormattingSettingsSlice[] = this.colorSelector.slices;
        if (dataPoints) {
            dataPoints.forEach(dataPoint =&amp;gt; {
                slices.push(new ColorPicker({
                    name: "fill",
                    displayName: dataPoint.value.toString(),
                    value: { value: dataPoint.color },
                    selector: dataPoint.selection.getSelector(),
                }));
            });
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;visual.ts:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"use strict";

import powerbi from "powerbi-visuals-api";
import { FormattingSettingsService } from "powerbi-visuals-utils-formattingmodel";
import { ColorHelper } from "powerbi-visuals-utils-colorutils";

import "./../style/visual.less";

import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import ISelectionId = powerbi.visuals.ISelectionId;
import IVisualHost = powerbi.extensibility.visual.IVisualHost;
import IColorPalette = powerbi.extensibility.IColorPalette;

import DataViewValueColumns = powerbi.DataViewValueColumns;
import DataViewValueColumnGroup = powerbi.DataViewValueColumnGroup;
import DataViewObjectPropertyIdentifier = powerbi.DataViewObjectPropertyIdentifier;

import ILocalizationManager = powerbi.extensibility.ILocalizationManager;


import { VisualFormattingSettingsModel } from "./settings";

export interface dataSerie {
    value: powerbi.PrimitiveValue;
    selection: ISelectionId,
    color: string;
}

export class Visual implements IVisual {
    private formattingSettings: VisualFormattingSettingsModel;
    private formattingSettingsService: FormattingSettingsService;
    private host: IVisualHost;
    private colorPalette: IColorPalette;
    private localizationManager: ILocalizationManager;

    constructor(options: VisualConstructorOptions) {
        this.host = options.host;
        this.localizationManager = this.host.createLocalizationManager();
        this.formattingSettingsService = new FormattingSettingsService(this.localizationManager);
        this.colorPalette = options.host.colorPalette;
    }

    public update(options: VisualUpdateOptions) {
        this.formattingSettings = this.formattingSettingsService.populateFormattingSettingsModel(VisualFormattingSettingsModel, options.dataViews?.[0]);
        
        const dataSeries: dataSerie[] = [];

        const series: powerbi.DataViewValueColumnGroup[] = options.dataViews[0].categorical.values.grouped();

        const valueColumns: DataViewValueColumns = options.dataViews[0].categorical.values,
            grouped: DataViewValueColumnGroup[] = valueColumns.grouped(),
            defaultDataPointColor: string = "green",
            fillProp: DataViewObjectPropertyIdentifier = {
                objectName: "objectName",
                propertyName: "propertyName"
            };

        series.forEach((ser: powerbi.DataViewValueColumnGroup, index) =&amp;gt; {
            // create selection id for series
            const seriesSelectionId = this.host.createSelectionIdBuilder()
                .withSeries(options.dataViews[0].categorical.values, ser)
                .createSelectionId();

            // get the color from series
            const defaultDataPointColor: string = this.colorPalette.getColor(ser.name.toString()).value;
            let colorHelper: ColorHelper = new ColorHelper(
                this.colorPalette,
                fillProp,
                defaultDataPointColor);
            let grouping: DataViewValueColumnGroup = grouped[index];
            let color = colorHelper.getColorForSeriesValue(grouping.objects, grouping.name);

            // create the series elements
            dataSeries.push({
                value: ser.name,
                selection: seriesSelectionId,
                color: color
            });
        });

        // Populate the formatting pane
        this.formattingSettings.populateColorSelector(dataSeries);
    }

    public getFormattingModel(): powerbi.visuals.FormattingModel {

        return this.formattingSettingsService.buildFormattingModel(this.formattingSettings);
    }
}   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sample of data:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;Legend&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;samedi 30 décembre 2023&lt;/TD&gt;&lt;TD&gt;14022,91642&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dimanche 31 décembre 2023&lt;/TD&gt;&lt;TD&gt;0,551076646&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dimanche 31 décembre 2023&lt;/TD&gt;&lt;TD&gt;10435,26002&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;lundi 1 janvier 2024&lt;/TD&gt;&lt;TD&gt;0,689471555&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;lundi 1 janvier 2024&lt;/TD&gt;&lt;TD&gt;12759,20759&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mardi 2 janvier 2024&lt;/TD&gt;&lt;TD&gt;0,305575341&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mardi 2 janvier 2024&lt;/TD&gt;&lt;TD&gt;10230,89312&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mercredi 3 janvier 2024&lt;/TD&gt;&lt;TD&gt;0,587809939&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mercredi 3 janvier 2024&lt;/TD&gt;&lt;TD&gt;11722,69859&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;jeudi 4 janvier 2024&lt;/TD&gt;&lt;TD&gt;0,964788095&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;jeudi 4 janvier 2024&lt;/TD&gt;&lt;TD&gt;13221,84671&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;vendredi 5 janvier 2024&lt;/TD&gt;&lt;TD&gt;0,721572695&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;vendredi 5 janvier 2024&lt;/TD&gt;&lt;TD&gt;11472,99755&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;samedi 6 janvier 2024&lt;/TD&gt;&lt;TD&gt;0,394463782&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;samedi 6 janvier 2024&lt;/TD&gt;&lt;TD&gt;43840,72009&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;samedi 6 janvier 2024&lt;/TD&gt;&lt;TD&gt;11982,3041&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;samedi 6 janvier 2024&lt;/TD&gt;&lt;TD&gt;515,2744629&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;samedi 6 janvier 2024&lt;/TD&gt;&lt;TD&gt;694,6464676&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dimanche 7 janvier 2024&lt;/TD&gt;&lt;TD&gt;0,359213967&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dimanche 7 janvier 2024&lt;/TD&gt;&lt;TD&gt;46322,50275&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dimanche 7 janvier 2024&lt;/TD&gt;&lt;TD&gt;14065,89778&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dimanche 7 janvier 2024&lt;/TD&gt;&lt;TD&gt;279,9718025&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dimanche 7 janvier 2024&lt;/TD&gt;&lt;TD&gt;653,0402894&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And how I fill the data fields:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Paulhaha_1-1717242763404.png" style="width: 109px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1109580i93E49050AD6EEEC2/image-dimensions/109x128?v=v2" width="109" height="128" role="button" title="Paulhaha_1-1717242763404.png" alt="Paulhaha_1-1717242763404.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jun 2024 12:01:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Problem-with-formatting-and-series/m-p/3965894#M9733</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-01T12:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with formatting and series</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Problem-with-formatting-and-series/m-p/3969256#M9786</link>
      <description>&lt;P&gt;Literally 3 minutes after posting the message I found the problem, and it works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  fillProp: DataViewObjectPropertyIdentifier = {
                objectName: "colorSelector",
                propertyName: "fill"
            };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The object property identifier was wrong.......&lt;/P&gt;&lt;P&gt;Thanks to myself lol&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For those interested, here is the full code:&amp;nbsp;&lt;A href="https://github.com/EquinetPaul/powerbi_multiple_axis_legend_linechart" target="_blank"&gt;EquinetPaul/powerbi_multiple_axis_legend_linechart: powerbi_multiple_axis_legend_linechart (github.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 15:36:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Problem-with-formatting-and-series/m-p/3969256#M9786</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-03T15:36:25Z</dc:date>
    </item>
  </channel>
</rss>

