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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Krunalbpatel
Helper III
Helper III

How to change the bar color/axis label color in custom visuals

Hi,

 

I want to change the bar color and axis label color. How can I change the color. I write the same code which is downloaded from the github.

 

This is my sample code to set the color in VisualTransform method

 

let defaultColor: Fill = {
                solid: {
                    color: colorPalette.getColor(category.values[i] + '').value
                }
            }

            barChartDataPoints.push({
                category: <string>category.values[i],
                value: <number>dataValue.values[i],
                color: getCategoricalObjectValue<Fill>(category, i, 'colorSelector', 'fill', defaultColor).solid.color,
                selectionId: host.createSelectionIdBuilder()
                    .withCategory(category, i)
                    .createSelectionId()
            });

 

And This is the code in enumerateObjectInstances method

 

case 'colorSelector':
                    for(let barDataPoint of this.barDataPoints) {
                        objectEnumeration.push({
                            objectName: objectName,
                            displayName: barDataPoint.category,
                            properties: {
                                fill: {
                                    solid: {
                                        color: barDataPoint.color
                                    }
                                },
                            },
                            selector: barDataPoint.selectionId
                        });
                    }
                    break;

 

But it is not working. It will remain the same color as set it by default. It is not updating the bar color.

 

If I write

 

selector: barDataPoint.selectionId.getSelection()

 

then I got the following error.

 Property 'getSelection' does not exist on type 'ISelectionId'.

 

Can you please help me.

2 ACCEPTED SOLUTIONS

@Krunalbpatel,

 

I've also replied your new thread. Follow the link below to update API version.

https://github.com/Microsoft/PowerBI-visuals/blob/master/tools/usage.md#updating-visuals-api

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @v-chuncz-msft,

 

From this thread thread I got my solution for changing bar color. But I am not able to change the axis label color. Same thing has happen it flashes only the same color has been applied again.

 

Regards,

Krunal Patel

 

 

View solution in original post

4 REPLIES 4
v-chuncz-msft
Community Support
Community Support

@Krunalbpatel, Here is the solution. https://github.com/Microsoft/PowerBI-visuals-sampleBarChart/issues/5
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-chuncz-msft

 

I am not getting the exact solution that I want.

 

How color palette object has been declared?
let colorPalette: IColorPalette = host.colorPalette;
I am getting error "Property 'reset' is missing in type 'IColorPalette'" while I am declare this way

 

And If I declare other way like
let colorPalette= createColorPalette(host.colors).reset();

Then also I am getting the error "Property 'colors' does not exist in 'IvisualHost'"

@Krunalbpatel,

 

I've also replied your new thread. Follow the link below to update API version.

https://github.com/Microsoft/PowerBI-visuals/blob/master/tools/usage.md#updating-visuals-api

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-chuncz-msft,

 

From this thread thread I got my solution for changing bar color. But I am not able to change the axis label color. Same thing has happen it flashes only the same color has been applied again.

 

Regards,

Krunal Patel

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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