Sometimes, a seemingly straightforward request brings a fascinating technical challenge. Recently, an old friend expressed the wish to display country flags as symbols on the bars in a stacked bar chart. Initially, this idea seemed a bit humorous, but I was intrigued by the technical challenge. In this post, I’ll show how I fulfilled this wish using country emojis and a special font—and the hurdles involved in the process.
The Challenge: Flags as Data Labels
Power BI does not offer an option to directly integrate flags or other custom symbols as data labels. Therefore, I had to devise a creative approach to represent country flags through emojis. I created a measure that automatically translates the countries from the legend into appropriate emojis to display as data labels. A pragmatic solution, though not without some limitations.
Flag Emoji =
SWITCH (
SELECTEDVALUE ( 'Fact'[Geography] ),
“USA”, ‘🇺🇸’,
“Europe”, ‘🇪🇺’,
“Germany”, ‘🇩🇪’,
“Emirates”, ‘🇦🇪’,
“Italy”, ‘🇮🇹’,
“Mexico”, ‘🇲🇽’,
“Austria”, ‘🇦🇹’,
“United Kingdom”, ‘🇬🇧’,
“Brazil”, ”🇧🇷”
)
The Pitfalls: Country Emojis in the Browser
One complication was the display of country emojis in different browsers. In Microsoft Edge and Chrome, country flags are not displayed as colorful symbols but only as country codes (e.g., “DE” for Germany). However, Firefox displays the flags as emojis. These differences are due to how each browser processes and displays emoji fonts. To ensure a consistent cross-platform display, a special emoji font was needed.
The Solution: Installing and Applying the Font
To correctly display the flags, I installed the emoji font NotoColorEmoji_WindowsCompatible.ttf, available from Google Fonts on GitHub. Here’s the link to the font: NotoColorEmoji.
To make the flag emojis appear in Power BI, this font is specified in the Theme JSON file, allowing the font to be applied to the data labels of the stacked bar chart. Since only standard fonts are available in Power BI Desktop, this workaround with the theme file is essential for displaying flags as data labels.
{
"name": "Flags",
"visualStyles": {
"columnChart": {
"*": {
"labels": [
{
"fontFamily": "Noto Color Emoji"
}
]
}
}
}
}
Step-by-Step Guide
- Finding Emoji Codes: You can conveniently copy the appropriate emoji codes for the flags from Emojipedia. Each country has its own code, which can then be used as an emoji in Power BI.
- Creating the Measure: Create a measure that outputs the country name or code from the legend as an emoji code.
- Installing the Font: Install the
NotoColorEmoji_WindowsCompatible.ttf
so that the emojis appear as flags in Power BI. - Modifying the Theme JSON: In the theme file, ensure that the data labels use the
NotoColorEmoji
font. This ensures that the font is correctly applied to the data labels of the bar chart in Power BI Desktop.
Conclusion
From a design and information design perspective, using emojis in stacked bar charts can be questionable. This approach may compromise readability and clarity. It’s always worth considering whether this type of visualization truly enhances the information flow or if alternative forms might be more suitable. Additionally, using fonts that are not natively available in Power BI poses challenges, as the specific font must be installed on every device for the report to display correctly.
However, this blog post aims to demonstrate what is technically possible and to inspire creative solutions for technical challenges. The approach showcased here exemplifies the versatility of Power BI for those willing to take unconventional paths.