Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi everyone,
Today I want to reach your help to resolve a problem I face since several days.
What I'm trying to do is to have a dynamic "Format Pane" allowing me to have a ColorPicker for each of my distinct categories.
I've managed to do something but the problem is that every time the update function is called (so every time I change a color in the pane) it resets the colors and so it's impossible to recover the user's selection.
Here are a few code snippets from my project to help you understand my logic:
In the update method:
export interface Legend {
category: powerbi.PrimitiveValue;
color: string
}
// let uniqueLegend = ["A", "B", "C"]
uniqueLegend.forEach((legend, i) => {
const color = colorPalette.getColor(legend).value
DataLegend.push({
category: legend,
color
})
})
this.formattingSettings.populateColorSelector(DataLegend)
In the formatting settings:
class ColorSelectorCardSettings extends Card {
name: string = "colorSelector";
displayName: string = "Data Colors";
slices = [];
}
export class VisualFormattingSettingsModel extends FormattingSettingsModel {
// Create formatting settings model formatting cards
generalSettings = new ColorSelectorCardSettings();
cards = [this.generalSettings];
populateColorSelector(dataPoints: Legend[]) {
const slices: formattingSettings.ColorPicker[] = this.generalSettings.slices;
dataPoints.forEach(d => {
// console.log(d.category)
slices.push(new formattingSettings.ColorPicker({
name:"fill",
displayName: d.category.toString(),
value: {value:d.color}
}))
})
}
}
What I'd like, and what I can't yet figure out how to do, is to be able to have this property pane display as many colorpickers as there are different values in my uniqueLegend array.
What's more, the behavior I'd like to see is for me to be able to store these values for later use in my visual without them being reset every time the update function is called (I guess the logic isn't to make sure that the values don't reset every time the update method is called, but you get the idea, so that I can have a dynamic and functional pane format).
Could someone help me out and clarify the use of dynamic pane formats depending on the data?
Thanks in advance 🙂
Hi @Paulhaha,
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:
Good luck!
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Hey @dm-p , and thank you very much for you answer.
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 😃
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.