Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
nicksav
Helper II
Helper II

Applying colors for Table. Custom Visual

Guys, I am struggaling here to get the colors working and I would like to understand the flow in the code for Sample Bar Chart.

 

So, there is a function to show properties on UI, called enumerateObjectInstances. In the BarChart sample, we are doing this by looping through Categories (Apple, Orange, Plumb) and pushing the (Label - Color picker) pair to the UI. At this point we already have color as part of our Data Point, So, making total sense.

 

Now, to assign a color to data point, we are going to the visualTransform function. And this is where I get some issues understanding the flow.

1) We get a colorPalette. Just a simple array of all avalable colors. 

2) Now depending on count of Values and Categories, we need to get max, we assign a default color to the the Category. 

3) Now before setting value for Data Point, we call function getCategoricalObjectValue. I understand, that this function goes for Apple and cheking if any colour was already assigned before to Apple, if not set the default from step 2. So, basically, if we run it first time, we dont have any colors assigned, so all categories pick the color from default.

 

Now, the interesting thing for me here is that when we have categorical data set, and we run the first time, category.objects is even dont exsts (in getCategoricalObjectValue function). However, when I changed the color for one of the Category, the update is trigered and I can see that now each Category will have object assign to it, kind of binding Category to Object Fill. I am missing this link guys. I don't understand at which point that link is happening..

 

Please help

Thanks

Nick

 

 

 

 

 

 

4 REPLIES 4
v-chuncz-msft
Community Support
Community Support

@nicksav,

 

To get a better understanding of its workflow, you could add console.log() in .ts files to output a message to the Web Console.

        constructor(options: VisualConstructorOptions) {
			console.log("options:", options);
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

The way "the link" between objects and categories happen is when you enumerate the objects in enumerateObjectInstance, by using the selector. The list of all objects wont be in metadata but in the category object within categories. 

This helped https://github.com/Microsoft/PowerBI-visuals/blob/master/Tutorial/DataBoundObjects.md 

 

Hope this helps. 

nicksav
Helper II
Helper II

Ok guys, one more question on top of this:)

I have a table dataViewMappings. I want to do a color picker for distinct values in one of the columns. So, I get this working, I mean it displays the correct result when I open the Visual Settings. However, when I pick color for one of the values, and update function is trigered, I dont get any values in metadata objects. How would you know which color picker was changed?

 

Thanks

Nick

Guys, no help at all?

Nobody stuck yet with Custom Visuals?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.