Forum Discussion

aristogeiton's avatar
aristogeiton
Frequent Visitor
8 years ago
Solved

Cannot successfully implement color picker on visual using table mapping

I am using the table type dataViewMapping.   I'm trying to store and retrieve colors, however colors don't save successfully.   I'm creating my selection Ids using the code from #77:   private ...
  • v-viig's avatar
    v-viig
    8 years ago

    Please this code snippet below to fix the issues with color picker:

     

            private static getSelectionIds(
                dataView: DataView,
                host: IVisualHost
            ): powerbi.visuals.ISelectionId[] {
                const queryName: string = dataView.table.columns[0].queryName;
    
                return dataView.table.identity.map((identity: DataViewScopeIdentity) => {
                    const categoryColumn: DataViewCategoryColumn = {
                        source: {
                            queryName,
                            displayName: null
                        },
                        values: null,
                        identity: [identity]
                    };
    
                    return host.createSelectionIdBuilder()
                        .withCategory(categoryColumn, 0)
                        .withMeasure(queryName)
                        .createSelectionId();
                });
            }

    Ignat Vilesov,

    Software Engineer

     

    Microsoft Power BI Custom Visuals

    [email protected]

  • FR5702's avatar
    FR5702
    8 years ago

    Alright thank you !

     

    For those with the same situation, I find a workaround.

     

    You should use

    d3.scale.ordinal().domain(data.map(d => d.dimension).range(color_library)

    With color_library an array of color your users can pick ( I take 10  for my chart but you can use 3 or 20...).

     

     

    Not the best solution, I have to admit but it works for now until I find something else :)