cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ysapiyev Member
Member

How to alter capabilities.json to have 4 inputs for values?

hi,

 

I am creating custom visual, and I'm new in power bi. I need to be able to enter 1 category and 4 values in capabilities.json in categorical data mapping. how it can be done?

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator v-viig
Moderator

Re: How to alter capabilities.json to have 4 inputs for values?

 

{
    "dataRoles": [
        {
            "displayName": "Category",
            "name": "Category",
            "kind": "Grouping"
        },
        {
            "displayName": "Values1",
            "name": "Values1",
            "kind": "Measure"
        },
        {
            "displayName": "Values2",
            "name": "Values2",
            "kind": "Measure"
        },
        {
            "displayName": "Values3",
            "name": "Values3",
            "kind": "Measure"
        },
        {
            "displayName": "Values4",
            "name": "Values4",
            "kind": "Measure"
        }
    ],
    "dataViewMappings": [
        {
            "categorical": {
                "categories": {
                    "for": {
                        "in": "Category"
                    }
                },
                "values": {
                    "select": [
                        {
                            "for": {
                                "in": "Values1"
                            }
                        },
                        {
                            "for": {
                                "in": "Values2"
                            }
                        },
                        {
                            "for": {
                                "in": "Values3"
                            }
                        },
                        {
                            "for": {
                                "in": "Values4"
                            }
                        }
                    ]
                }
            }
        }
    ]
}

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

View solution in original post

8 REPLIES 8
skizofre3e Member
Member

Re: How to alter capabilities.json to have 4 inputs for values?

why don't you simply use Table instead of categorical ? otherwise I think what you are looking for is serie.

Moderator v-viig
Moderator

Re: How to alter capabilities.json to have 4 inputs for values?

 

{
    "dataRoles": [
        {
            "displayName": "Category",
            "name": "Category",
            "kind": "Grouping"
        },
        {
            "displayName": "Values1",
            "name": "Values1",
            "kind": "Measure"
        },
        {
            "displayName": "Values2",
            "name": "Values2",
            "kind": "Measure"
        },
        {
            "displayName": "Values3",
            "name": "Values3",
            "kind": "Measure"
        },
        {
            "displayName": "Values4",
            "name": "Values4",
            "kind": "Measure"
        }
    ],
    "dataViewMappings": [
        {
            "categorical": {
                "categories": {
                    "for": {
                        "in": "Category"
                    }
                },
                "values": {
                    "select": [
                        {
                            "for": {
                                "in": "Values1"
                            }
                        },
                        {
                            "for": {
                                "in": "Values2"
                            }
                        },
                        {
                            "for": {
                                "in": "Values3"
                            }
                        },
                        {
                            "for": {
                                "in": "Values4"
                            }
                        }
                    ]
                }
            }
        }
    ]
}

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

View solution in original post

Maikeru Regular Visitor
Regular Visitor

Re: How to alter capabilities.json to have 4 inputs for values?

@v-viig

 

I am beginning to design custom visuals and am interested by this data scheme.

 

Once the capabilities.json is set, how would you extract each Value 1, 2, 3, 4 into the visual.ts file?

I understand that the dataViews method is able to fetch user data but I can't figure out the correct syntax to pick each specific node.

 

Sorry for this newbie question. I am also just starting with TS.

 

Thank you in advance for your guidance.

 

Best regards

 

Michael

skizofre3e Member
Member

Re: How to alter capabilities.json to have 4 inputs for values?

@Maikeru

let valColumnName = metadata.columns.filter(c => c.roles["value1"])[0].displayName;
let valColumnIndex = metadata.columns.filter(c => c.roles["value1"])[0].index;

 

I hope this helps you !

Highlighted
ysapiyev Member
Member

Re: How to alter capabilities.json to have 4 inputs for values?

@Maikeru

 

let dv = options.dataViews;
let view = dv[0].categorical;
let values1 = view.values[0];
let values2 = view.values[1];
let values3 = view.values[2];
let values4 = view.values[3];

This should help.

 

Regards,

Yerkhan

Maikeru Regular Visitor
Regular Visitor

Re: How to alter capabilities.json to have 4 inputs for values?

 

Thank you very much, @v-viig!

 

Really appreciate your time helping me out.

 

I tried to implement the piece of code you sent me, but I am not able to retrieve the data to the viz.

 

As you can see below, I tried to substitute the fetched data with some static one (value_array) and in the latter case, the visual displays properly.

 

Is there something obvious that I missed?

 

 

 

function visualTransform(options: VisualUpdateOptions, host: IVisualHost) {

        let dataInfo = {
            dataPoints: [],
            dataMax: 0
        };

        let dataPoints = [];
        let dataMax: number;

        let dv = options.dataViews;
        let view = dv[0].categorical;
        let values1 = view.values[0];
        let values2 = view.values[1];
        let values3 = view.values[2];
        let values4 = view.values[3];

        //let value_array = [values1,values2,values3,values4,values5];
        let value_array = [100,10,8,120];

        for (let i = 0; i < 4; i++) {
            dataPoints.push({
                category: "test" + i,
                value: view.values[i]
                //value: value_array[i]
            });
        }
        dataMax = 130;

        return {
            dataPoints: dataPoints,
            dataMax: dataMax
        };
    }

 

Best regards

 

Michael

 

Maikeru Regular Visitor
Regular Visitor

Re: How to alter capabilities.json to have 4 inputs for values?

 

Thank you very much, @v-viig!

 

Really appreciate your time helping me out.

 

I tried to implement the piece of code you sent me, but I am not able to retrieve the data to the viz.

 

As you can see below, I tried to substitute the fetched data with some static one (value_array) and in the latter case, the visual displays properly.

 

Is there something obvious that I missed?

 

 

 

function visualTransform(options: VisualUpdateOptions, host: IVisualHost) {

        let dataInfo = {
            dataPoints: [],
            dataMax: 0
        };

        let dataPoints = [];
        let dataMax: number;

        let dv = options.dataViews;
        let view = dv[0].categorical;
        let values1 = view.values[0];
        let values2 = view.values[1];
        let values3 = view.values[2];
        let values4 = view.values[3];

        //let value_array = [values1,values2,values3,values4];
        let value_array = [100,10,8,120];

        for (let i = 0; i < 4; i++) {
            dataPoints.push({
                category: "test" + i,
                value: view.values[i]
                //value: value_array[i]
            });
        }
        dataMax = 130;

        return {
            dataPoints: dataPoints,
            dataMax: dataMax
        };
    }

 

Best regards

 

Michael

 

Maikeru Regular Visitor
Regular Visitor

Re: How to alter capabilities.json to have 4 inputs for values?

I figured out what was wrong.
I needed to add an extra « values » property to retrieve the node value.

view.values[i].values

Helpful resources

Announcements
New Ranks and Rank Icons in 2020

New Ranks and Rank Icons in 2020

Read the announcement for more information!

New Kudos Given Badges Coming

New Kudos Given Badges Coming

We're rolling out new Kudos Given badges. Find out how many Kudos you've given.

November 2019 Community Highlights

November 2019 Community Highlights

Get an overview of the events and great community content from November.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)