共用方式為


使用選取器來控制哪些視覺效果會生效

某些功能可讓您使用選取器來控制哪些視覺效果會生效。 選取器是選擇性的,而且當它未出現時,這些設定適用於報表中的所有視覺效果。

支援的功能

選取器可用於下列功能:

選取器類型

視覺效果名稱

僅套用指定視覺效果的設定。

selector: {
    $schema: "http://powerbi.com/product/schema#visualSelector",
    visualName: <a visual name> // You can retrieve the name using `getVisuals`
}

若要尋找視覺效果名稱,您可以在頁面上使用 getVisuals() API,並取得視覺效果的 name 屬性。 視覺名稱是唯一標識碼。

視覺效果類型

將設定套用至指定類型中的所有視覺效果。

selector: {
    $schema: "http://powerbi.com/product/schema#visualTypeSelector",
    visualType: <a visual type> // You can retrieve the type using `getVisuals`
}

若要尋找視覺效果類型,您可以在頁面上使用 getVisuals() API,並取得視覺效果的 type 屬性。

交叉分析篩選器目標

僅針對具有指定目標的交叉分析篩選器套用交叉分析篩選器狀態。

selector: {
    $schema: "http://powerbi.com/product/schema#slicerTargetSelector",
    target: <target data field>  
}

例子

視覺標頭設定

  • 隱藏報表中的所有視覺效果標頭。

    let config = {
        …
        settings: {
            …
            visualSettings: {
                visualHeaders: [
                    {
                        settings: {
                            visible: false
                        }
                        /* No selector - Hide visual header for all the visuals in the report */
                    }
                ]
            }
        }
    };
    
  • 使用視覺選取器隱藏特定視覺效果的視覺效果標頭。

    let config = {
        …
        settings: {
            …
            visualSettings: {
                visualHeaders: [
                    {
                        settings: {
                            visible: false
                        }
                        selector: {
                            $schema: "http://powerbi.com/product/schema#visualSelector",
                            visualName: "VisualContainer1",
                        }
                    }
                ]
            }
        }
    };
    

功能表命令延伸模組和內建命令都會顯示支持選取器。

  • 將擴充功能命令新增至特定的視覺選項功能表。

    let config = {
        ...
        settings: {
            ...
    
            // Adding the extension command to the options menu
            extensions: [
                {
                    command: {
                        name: "campaign",
                        title: "Start campaign",
                        icon: base64Icon,
                        selector: {
                            $schema: "http://powerbi.com/product/schema#visualSelector",
                            visualName: tableVisualName
                        },
                        extend: {
                            visualOptionsMenu: {
                                title: "Start campaign",
                                menuLocation: models.MenuLocation.Top,
                            }
                        }
                    }
                },
            ],
        }
    }
    
  • 針對所有具有 table 類型的視覺效果隱藏一些內建命令。

    let tableSelector = {
        $schema: "http://powerbi.com/product/schema#visualTypeSelector",
        visualType: 'table'
    };
    
    let config = {
        ...
        settings: {
            ...
            // Hiding built-in commands on the options menu
            commands: [
                {
                    spotlight: {
                        selector: tableSelector,
                        displayOption: models.CommandDisplayOption.Hidden,
                    },
                    exportData: {
                        selector: tableSelector,
                        displayOption: models.CommandDisplayOption.Hidden,
                    },
                    seeData: {
                        selector: tableSelector,
                        displayOption: models.CommandDisplayOption.Hidden,
                    },
                }
            ]
        },
    };
    

載入時交叉分析篩選器

注意

負載上的交叉分析篩選器不支援視覺類型選取器

  • 依名稱設定特定的交叉分析篩選器

    let slicers = [
        {
            selector: {
                $schema: "http://powerbi.com/product/schema#visualSelector",
                visualName: "d1feb8891635af3b335a"
            },
            state: {
                filters: [
                {
                    $schema:"http://powerbi.com/product/schema#advanced",
                    target: {
                        table: "Store",
                        column: "StoreNumber"
                    },
                    filterType: models.FilterType.AdvancedFilter,
                    logicalOperator: "And",
                    conditions: [
                        { operator: "GreaterThanOrEqual", value: 37 },
                        { operator: "LessThanOrEqual", value: 576 }]
                }]
            }
        }
    ];
    
    embedConfig = {
        slicers: slicers,
        ...
    };
    
  • 依目標設定交叉分析篩選器

    // We want to slice all slicers with "StoreNumber" column target
    let target = {
        table: "Store",
        column: "StoreNumber"
    };
    
    let slicers = [
        {
            selector: {
                $schema: "http://powerbi.com/product/schema#slicerTargetSelector",
                target: target
            },
            state: {
                filters: [
                {
                    $schema:"http://powerbi.com/product/schema#advanced",
                    target: target,
                    filterType: models.FilterType.AdvancedFilter,
                    logicalOperator: "And",
                    conditions: [
                        {operator: "GreaterThanOrEqual", value: 37 },
                        {operator: "LessThanOrEqual", value: 576 }]
                }]
            }
        }
    ];
    
    embedConfig = {
        slicers: slicers,
        ...
    };