【问题标题】:Apply custom theme to visuals in powerbi-embedded将自定义主题应用于 powerbi-embedded 中的视觉效果
【发布时间】:2022-10-17 11:59:24
【问题描述】:

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

【问题讨论】:

标签: powerbi powerbi-embedded


【解决方案1】:

要将主题应用于视觉效果,请找到以下代码 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

【讨论】:

    猜你喜欢
    • 2020-05-04
    • 2020-05-23
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    相关资源
    最近更新 更多