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 :)
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?
I didn't receive the code. Could you please share tocde by using One Drive?
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
- v-viig8 years agoCommunity Champion
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
- aristogeiton8 years agoFrequent Visitor
Excellent! It now works! Thanks very much for this!
- anandsoftweb8 years agoAdvocate V
I am having same issue color picker does not save in custom visual stack bar.
what I have to do? do you have any example of custom visual.
Please help me.
Thanks,
Anand
- ChrisWilliams7 years agoAdvocate II
I know this is an old post, but I wanted to post a modification to this (I'm using the SDK 2.1.0).
In cases where my table was empty, I was seeing an exception in my visual. I traced it and found that dataView.table.identity can be undefined, which would lead to an exception in this method. A simple fix is to perform a check for undefined.
private getSelectionIds(dataView: DataView, host: IVisualHost): ISelectionId[] { if (dataView.table.identity === undefined){ return []; } const queryName: string = dataView.table.columns[0].queryName; return dataView.table.identity.map((identity: data.DataRepetitionSelector) => { const categoryColumn: DataViewCategoryColumn = { source: { queryName, displayName: null }, values: null, identity: [identity] }; return host.createSelectionIdBuilder() .withCategory(categoryColumn, 0) .withMeasure(queryName) .createSelectionId(); }); }- v-viig7 years agoCommunity Champion
Can you share whole source code for deeper debugging?
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals