Forum Discussion
timseltman
3 years agoFrequent Visitor
Custom visual retaining dynamic fill colors for supplemental data
I am in the middle of developing a categorical custom visual where I have different status; but they are not the primary data for the visual. These are a supplemental data value. As such the status' ...
Anonymous
3 years agoNot applicable
Are you making use of the Color Pallete Service from Power BI? I personally have not used this but I can provide a solution that does not use this.
I am assuming you have default colors for each status in the settings.ts file. It might look something like
export class StatusColors {
public completed: string = "";
public inAnalysis: string = "";
public inProgress: string = "";
}
export class VisualSettings extends DataViewObjectParser {
public statusColors: StatusColors = new StatusColors();
}
Using these, since there are only 3 possible values for status, you can simply check the type of status for a data point and assign it the color.
import { StatusColors } from "./settings"
class Visual implements IVisualHost {
.
.
.
public update (options: VisualUpdateOptions) {
this.visualSettings = VisualSettings.parse(options.dataViews[0])
// while rendering the color of the category, you can use the status to get the colors associated with that status
// for example, assuming data[] has all the information
let html = ""
for (let dataPoints in data) {
const status = dataPoints.status;
const color = this.getColor(status);
html += `
<div>
<div>
${status}
</div>
<div style={"color": ${color}}>
${color}
</div>
</div>
`
}
}
private getColor(status: string) {
const statusColors: StatusColors = this.visualSettings.statusColors;
switch(status) {
case 'completed': return statusColors.completed
case 'inAnalysis': return statusColors.inAnalysis
case 'inProgress': return statusColors.inProgress
default: return statusColors.completed
}
}
.
.
.
}
timseltman
3 years agoFrequent Visitor
Thank you, but the status may change, I just provided those three as examples. We may not know what the status are, and users should select a color for each status, and Power BI should hold* that status regardless of what filters are applied. Is there a way to do this same thing, but with dynamic status values?