Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
bhavesh-jadav
Helper I
Helper I

Adding colors for legends in Power BI custom visual

Hello there,

 

I have column with 2 distinct value say and B. I want to give ability to a user to change colors of and category. I managed to display color settings for each cateogry in that column but I am not sure how to fetch and retain those value.

 

capabilities.json file

 

"objects": {
        "alertSettings": {
            "displayName": "Alert",
            "properties": {
                "color": {
                    "displayName": "Color",
                    "type": {
                        "fill": {
                            "solid": {
                                "color": true
                            }
                        }
                    }
                }
            }
        }
    }

 

 

Settings enumeration function

 

public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject {
            const settings: VisualObjectInstance[] = [];
            switch (options.objectName) {
                case 'alertSettings':
                    // uniqueAlerts is an array containing unique values from alert column.
                    this.uniqueAlerts.forEach((alert) => {
                        settings.push({
                            objectName: options.objectName,
                            displayName: alert,
                            properties: {
                                color: ''
                            },
                            selector: {
                                metadata: alert
                            }
                        });
                    })
                    break;
            
                default:
                    break;
            }
            if (settings.length > 0) {
                return settings;
            } else {
                return (AutoPlantVisualSettings.enumerateObjectInstances(this.autoPlantSettings, options) as VisualObjectInstanceEnumerationObject);
            }
        }

By using above code I got the following result.

 

 

Capture.PNG

 

How do I get the color value selected by user?

0 REPLIES 0

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.