In my custom Power BI code I have used 'Data Colors' options. I am pushing data points to be further used as shown below:
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()
})
I have used helper file containing definition for getCategoricalObjectValue
function. Definition of function is as shown:
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;
}
I am facing issue with getCategoricalObjectValue
function where category.objects
always comes to be undefined irrespective of when color has been changed from Format menu.
I need help to resolve above issue. All code I have used is based on example given on https://github.com/Microsoft/PowerBI-visuals for Bar Chart
The issue was with the existing code which is deprecated or the implementation has changed lately.
The solution is given in the link provided below: https://github.com/Microsoft/PowerBI-visuals-sampleBarChart/issues/5