Forum Discussion
Dynamic Legend Color - Format Pane
Hi Anonymous,
This is quite a big question to sort out, made slightly more complicated that (a) your data role/mapping information from your capabilities isn't supplied and (b) I haven't tried this yet with the new formatting model, so I can't provide a working example.
However, the one thing that sticks out is that you're not adding anything to the properties pane with a suitable selector in the object, which means that it doesn't map to the data point where you're interested in styling. Selectors are how Power BI reconciles interactivity and properties to your data. Power BI will apply the selected value to the specified location in the data view if a valid selector is supplied when adding a property to the pane. Once this has been applied, it's a case of knowing where to read it out when processing your view model.
The following may help you get moving:
- Information on creating selectors is documented here. Typically, for legend-type scenarios, you will have a categorical mapping with a 'series' role mapped in your data view. An example of how to create a selection ID from this setup is documented here, lower down on the page.
- Information on the selector in the properties pane is documented here.
- The sample bar chart has an example for assignment by data value, with the selector property here. You should be able to track this back to the selector generation to see a more complete example.
Good luck!
Daniel
- Anonymous2 years agoNot applicable
Hey dm-p , and thank you very much for you answer.
I watched the documentation you provided and I think I start to understand the mechanism by retro-engineering the sample bart chart 😌However, I still have a problem adapting the methods used in the sample bar chart since:- My data role/mapping is for a table
- I use table mapping to be able to collect all the data without aggregation (GroupingOrMeasure or just Grouping)
- The aim of the visual is to display X/Y coordinates and be able to diffentiate points using a legend field. (so should I, as you mentioned, create a selection for series instead of a selection fortable? )
Here are the code uploaded on github:
I can't find out a solution to adapte the method getColumnColorByIndex() to a table data view.
I think it's the key for my problem, as this method to either selects the default color from the color palette or either select the color from the object properties (which are defined by the user and populating the format pane)
Do you have any recommendations (or documentation) on how I could adapt this method to cover my needs?
Thank you very much and I wish you a nice day 😃