【发布时间】:2022-10-17 11:59:24
【问题描述】:
要将主题应用于视觉效果,请找到以下代码 sn-p:
创建自定义主题:
// 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-visuals https://learn.microsoft.com/javascript/api/overview/powerbi/apply-report-themes
【讨论】: