Forum Discussion

NileshBhayani's avatar
NileshBhayani
Frequent Visitor
1 year ago
Solved

Dynamic slice color based on categories change functionality

I'm creating custom pie chart so in that i have to add slice color change functionality. 

I have prepared default color array for the categories and creating slice for formate penal.

 

Below is the code which i have added in setting.ts file

 

sliceSettings.sliceDropdownItems.forEach((item, idx) => {
  slices.push({
    uid: `slice_color_uid_${item.value}`,
    displayName: `${item.displayName} Color`,
    control: {
      type: powerbi.visuals.FormattingComponent.ColorPicker,
      properties: {
        descriptor: {
          objectName: 'slices',
          propertyName: 'sliceColor', 
        },
        value: {
          value: sliceSettings.sliceColorArray?.[idx] || ''
        }
      }
    },
    disabled: false
  });
});

 

but when I try to change the color I'm not able the get that changed color details so Please help me on that

 

capabilities.json

 

"slices": {
            "displayName": "Slices",
            "properties": {
                "selectedSlice": {
                    "displayName": "Selected Slice",
                    "type": { "enumeration": [] }
                },
                "sliceColor": {
                    "displayName": "Slice Color",
                    "type": { "fill": { "solid": { "color": true } } }
                }
            }
        },


I think, I have to set dynamic properties based on categories but I'm not able to find any solution to set dynamic properties.

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi NileshBhayani  ,
    Thanks for reaching out to the Microsoft fabric community forum.

    In the current setup, the capabilities.json file defines a single sliceColor property under the slices object, which applies uniformly rather than on a per-category basis. This structure lacks the flexibility to store and retrieve distinct formatting settings for each slice. As a result, while colour pickers may appear in the formatting pane, the visual cannot persist or retrieve category-specific colour selections at runtime. To enable this level of customization, we must shift from static to data-bound object properties, which allow Power BI to associate formatting settings dynamically with each data point in the visual.

    Reference: GitHub - microsoft/powerbi-visuals-utils-formattingmodel: powerbi visuals formatting model helper utils

    If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS. Feel free to reach out if you need further assistance.
    Thank you


1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi NileshBhayani  ,
    Thanks for reaching out to the Microsoft fabric community forum.

    In the current setup, the capabilities.json file defines a single sliceColor property under the slices object, which applies uniformly rather than on a per-category basis. This structure lacks the flexibility to store and retrieve distinct formatting settings for each slice. As a result, while colour pickers may appear in the formatting pane, the visual cannot persist or retrieve category-specific colour selections at runtime. To enable this level of customization, we must shift from static to data-bound object properties, which allow Power BI to associate formatting settings dynamically with each data point in the visual.

    Reference: GitHub - microsoft/powerbi-visuals-utils-formattingmodel: powerbi visuals formatting model helper utils

    If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS. Feel free to reach out if you need further assistance.
    Thank you