将自定义主题应用于powerbi嵌入式中的视觉效果



我有一个嵌入的报告,我想在其中根据视觉效果的偶数和奇数设置视觉效果的主题。有人能建议我如何将主题应用于视觉效果吗?

要将主题应用于视觉效果,请找到以下代码片段:

创建自定义主题:

// Create a theme.
const theme = {
"name": "Sample Theme",
"dataColors": ["#990011", "#cc1144", "#ee7799", "#eebbcc", "#cc4477", "#cc5555", "#882222", "#A30E33"],
"background": "#FFFFFF",
"foreground": "#007799",
"tableAccent": "#990011"
};

获取视觉效果的数量:

const visuals = await page.getVisuals();
const num_of_visuals = visuals.length;

使用applyTheme API将主题应用于视觉效果:

// Apply the custom theme for even number of visuals
if(num_of_visuals % 2 == 0){
report.applyTheme({ themeJson: themes.find(theme => theme.name ==="light")});
}
else { // Apply the custom theme for odd number of visuals
report.applyTheme({ themeJson: themes.find(theme => theme.name === "dark") });
}

参考文献:

https://learn.microsoft.com/javascript/api/overview/powerbi/get-visualshttps://learn.microsoft.com/javascript/api/overview/powerbi/apply-report-themes

最新更新