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
callum
Helper II
Helper II

Confused about objects...

Hello,

 

I'll try to explain my situation as clearly as possible. I'm building a visual to simulate the functionality of ThoughtWorks' Tech Radar. I therefore have four classes; Radar, Sector, Point and Ring. Radar is the "main" class for which is an instance is returned from my visualTransform method. And then a radar has a property called sectors, which is an array of Sector instances. Each Sector then contains many Points (which then has a ring!), although this last bit doesn't really matter for the question.

 

Anyway, you can see how each sector has a different colour. I'd like the user to be able to choose these colours. I want to store it in a property of a Sector called colours, i.e. when plotting the visual I would use sector.colour.

 

I took a leaf out of the sample bar chart guide and added this to my capabilities.json:

 

  "objects": {
    "colourSelector": {
      "displayName": "Sector colours",
      "properties": {
        "fill": {
          "displayName": "Colour",
          "type": {
            "fill": {
              "solid": {
                "color": true
              }
            }
          }
        }
      }
    }
  }

But I'm not sure how to proceed further. I changed my enumerateObjectInstances to:

 

 

public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject {
    let objectEnumeration = [];

    switch (options.objectName) {
        case "colourSelector":
            this.radar.sectors.forEach(function (sector) {
                objectEnumeration.push({
                    objectName: options.objectName,
                    displayName: sector.name,
                    properties: {
                        fill: {
                            solid: {
                                color: sector.colour
                            }
                        }
                    },
                    selector: sector
                });
            });
            break;
    }

    return objectEnumeration;
}

But I clearly need to do something more. Specifically in the "selector" bit; I don't think passing in an actual Sector instance is correct, but the guide seems to just glance over what should be passed in without giving much detail. (For clarity: each sector is given a default colour, hence why sector.colour is used here)

 

With this, I do get the following in the Format pane:

Capture2.PNG

However I don't know how I can bind these values to sector.colour. Where do they go?

 

I hope this makes sense! Thanks in advance.

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@callum,

 

You may check function getCategoricalObjectValue.

https://github.com/Microsoft/PowerBI-visuals/blob/f76ae919d9c9df83318e62e2bd7b24d185e8a32e/Tutorial/...

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.

View solution in original post

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@callum,

 

You may check function getCategoricalObjectValue.

https://github.com/Microsoft/PowerBI-visuals/blob/f76ae919d9c9df83318e62e2bd7b24d185e8a32e/Tutorial/...

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.

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.