Forum Discussion
Cannot successfully implement color picker on visual using table mapping
- 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
- 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 :)
Hello aristogeiton
The issue is in this code:
getCategoricalObjectValue<Fill>(options.dataViews[0].categorical.categories[0], i, 'colorSelector', 'fill', defaultColor).solid.color,
- The color for table mapping is kept in options.dataViews[0].table.rows[rowIndex].objects[0] instead of options.dataViews[0].categorical.categories[0].
- You should modify getCategoricalObjectValue function to handle options.dataViews[0].table.rows[rowIndex].objects[0] properly
Please let me know if you have any further questions.
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
Thanks for your response Igor. This still doesn't work. Is getSelectionIds() defined correctly? rows[index].objects is undefined in all cases.
- v-viig8 years agoCommunity Champion
The getSelectionIds looks ok.
The rows[index].objects is undefiend if you haven't changed any settings of formatting panel.
Could you pleas share the whole source code as a zip?
Just want to debug it deeper.
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
- aristogeiton8 years agoFrequent Visitor
Hi Igant,
I sent this through last week; I hope you received it.
Could the problem be that I am running getSelectionIds for each VisualUpdateType = 2? I get a type 2 update whenever I change one of the selections. Is running getSelectionIds() at that time overwriting my selections?
- v-viig8 years agoCommunity Champion
I didn't receive the code. Could you please share tocde by using One Drive?
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals