首页 文章

无法在Power BI中设置“格式化数据颜色”选项

提问于
浏览
0

在我的自定义Power BI代码中,我使用了“数据颜色”选项 . 我正在推动数据点进一步使用,如下所示:

this.dataPoints.push({
    category: String(categories.values[index]),
    value: Number(dataValues.values[index]),
    color: getCategoricalObjectValue<Fill>(categories, index, 'colorSelector', 'fill', defaultColor).solid.color,
    selectionId: this.host.createSelectionIdBuilder().withCategory(categories, index).createSelectionId()
})

我使用了包含 getCategoricalObjectValue 函数定义的帮助文件 . 功能的定义如下所示:

export function getCategoricalObjectValue<T>(category: DataViewCategoryColumn, index: number, objectName: string, propertyName: string, defaultValue: T): T {
    let categoryObjects = category.objects;

    if (categoryObjects) {
        let categoryObject: DataViewObject = categoryObjects[index];
        if (categoryObject) {
            let object = categoryObject[objectName];
            if (object) {
                let property: T = object[propertyName];
                if (property !== undefined) {
                    return property;
                }
            }
        }
    }
    return defaultValue;
}

我面临 getCategoricalObjectValue 函数的问题,无论何时从格式菜单更改颜色, category.objects 总是未定义 .

我需要帮助来解决上述问题 . 我使用的所有代码都基于https://github.com/Microsoft/PowerBI-visuals给出的条形图示例

1 回答

相关问题