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
SonaliDhotre
Advocate I
Advocate I

Custom Visual - Font size showing in percentage

In Formatting options I am getting the font size as a percentage however I want it to show px(pixel).

 

SonaliDhotre_0-1636981321149.png

 

Here are the capabilities:

 

"objects": {
        "formatOptions": {
            "displayName": "Format Options",
            "properties": {
                "categoryTextSize": {
                    "displayName": "Category Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },
                "catDetailsTextSize": {
                    "displayName": "Category Details Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },
                "cardTitleTextSize": {
                    "displayName": "Report Title Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },
                "detailsTextSize": {
                    "displayName": "Report Details Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                }
            }
        }
    }

 

Can anyone please help me with this?
Thanks in advance.

1 ACCEPTED SOLUTION

I had the same problem. It turns out the property name has to be EXACTLY "fontSize" for it to work. Like this:

 

            "properties": {
                "fontSize": {
                    "displayName": "Category Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },

 

In your case, the problem is that you would have many "fontSize" properties in the same object group, and this is not possible, so you'll might have to rearrange your options.

View solution in original post

6 REPLIES 6
dm-p
Super User
Super User

Hi @SonaliDhotre,

The unit suffix in these boxes is pre-defined. This will sometimes be set to something particular if the property name matches a reserved name (although there's no list of these and as you haven't supplied your capabilities, this is merely a guess that it's happening in this case).

If you want to use font size "correctly" in Power BI visuals, and have a unit suffix in the spin control, you will need to work in pt and apply styling using this unit in your code as applicable when binding property values to your appropriate styles. There is a special format type for this called fontSize you need to set in your capabilities.json, e.g.:

                ...
                "categoryFontSize": {
                    "displayName": "Category Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },
                ...

Then you'll get a box like the following when then pane is enumerated:

dmp_0-1637012603829.png

This type has in-built ranges of 8 - 60, and is consistent with other visuals.

If you want to use px, you can configure your property in capabilities to use the integer format type, e.g.

                ...
                "categoryFontSize": {
                    "displayName": "Category Font Size (px)",
                    "type": {
                        "integer": true
                    }
                },
                ...

Note that because this type doesn't present a suffix in the spin control, I've stated the unit in the displayName for UX purposes, but up to you how you want to manage.

Integer fields will not render correctly in the properties pane, unless you specify their min/max ranges when enumerating your visual objects - usually done in enumerateObjectInstances(), when the visual's update method executes. When you process each object instance, you will need to add a validValues object with the ranges for each named property. For example, if you wanted the values for categoryFontSize to be between 2 and 150, you'd do the following:

instances[0].validValues = {
    categoryFontSize: {
        numberRange: {
            min: 2,
            max: 150
        }
    }
}

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

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)




Thank you so much for responding. I have added the capabilities you have mentioned in the first half of the solution. I have added the capabilities in the description above. I am fine with having pt instead of px. But I am getting %. I am willing to go with the first solution you have mensioned. Can you please tell me what I am doing wrong?

It's hard to help further without seeing your visual project; your capabilities.json file as a bare-minumum. Are you able to share this at all?

 

Also, please confirm the version of the API you're using and the SDK version (powerbi-visuals-tools).





Did I answer your question? Mark my post as a solution!

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)




Here is the entire capebilities.json

 

 

 

{
    "dataRoles": [
        {
            "displayName": "Category",
            "name": "category",
            "kind": "Grouping"
        },
        {
            "displayName": "IsLive",
            "name": "islive",
            "kind": "Grouping"
        },
        {
            "displayName": "CatId",
            "name": "catid",
            "kind": "Grouping"
        },
        {
            "displayName": "Has Only One Report ?",
            "name": "hasOnlyOneReport",
            "kind": "Grouping"
        },
        {
            "displayName": "ReportId",
            "name": "reportid",
            "kind": "Grouping"
        },
        {
            "displayName": "Index",
            "name": "id",
            "kind": "Grouping"
        },
        {
            "displayName": "Header",
            "name": "header",
            "kind": "Grouping"
        },
        {
            "displayName": "Details",
            "name": "details",
            "kind": "Grouping"
        },
        {
            "displayName": "IconURL",
            "name": "icon-url",
            "kind": "Grouping"
        },
        {
            "displayName": "HoverURL",
            "name": "hover-url",
            "kind": "Grouping"
        },
        {
            "displayName": "CategoryImgURL",
            "name": "cat-img-url",
            "kind": "Grouping"
        },
        {
            "displayName": "CategoryDetails",
            "name": "cat-details",
            "kind": "Grouping"
        },
        {
            "displayName": "CategoryIllustration",
            "name": "cat-illustration",
            "kind": "Grouping"
        },
        {
            "displayName": "Target",
            "name": "target",
            "kind": "Grouping"
        }
    ],
    "objects": {
        "formatOptions": {
            "displayName": "Format Options",
            "properties": {
                "categoryTextSize": {
                    "displayName": "Category Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },
                "catDetailsTextSize": {
                    "displayName": "Category Details Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },
                "cardTitleTextSize": {
                    "displayName": "Report Title Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },
                "detailsTextSize": {
                    "displayName": "Report Details Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                }
            }
        }
    },
    "dataViewMappings": [
        {
            "table": {
                "rows": {
                    "select": [
                        {
                            "for": {
                                "in": "category"
                            }
                        },
                        {
                            "for": {
                                "in": "islive"
                            }
                        },
                        {
                            "for": {
                                "in": "catid"
                            }
                        },
                        {
                            "for": {
                                "in": "hasOnlyOneReport"
                            }
                        },
                        {
                            "for": {
                                "in": "reportid"
                            }
                        },
                        {
                            "for": {
                                "in": "id"
                            }
                        },
                        {
                            "for": {
                                "in": "header"
                            }
                        },
                        {
                            "for": {
                                "in": "details"
                            }
                        },
                        {
                            "for": {
                                "in": "icon-url"
                            }
                        },
                        {
                            "for": {
                                "in": "hover-url"
                            }
                        },
                        {
                            "for": {
                                "in": "cat-img-url"
                            }
                        },
                        {
                            "for": {
                                "in": "cat-details"
                            }
                        },
                        {
                            "for": {
                                "in": "cat-illustration"
                            }
                        },
                        {
                            "for": {
                                "in": "target"
                            }
                        }
                    ]
                }
            }
        }
    ]
}

 

 

 

And the API version is as shown in screenshot below,

SonaliDhotre_0-1637313239359.png

Correct me if you need other details and let me know if you need to know anything else.

I had the same problem. It turns out the property name has to be EXACTLY "fontSize" for it to work. Like this:

 

            "properties": {
                "fontSize": {
                    "displayName": "Category Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },

 

In your case, the problem is that you would have many "fontSize" properties in the same object group, and this is not possible, so you'll might have to rearrange your options.

I had the same problem. It turns out the property name has to be EXACTLY "fontSize" for it to work. Like this:

 

            "properties": {
                "fontSize": {
                    "displayName": "Category Font Size",
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                },

 

In your case, the problem is that you would have many "fontSize" properties in the same object group, and this is not possible, so you'll might have to rearrange your options.

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.