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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Triplee74
Frequent Visitor

What fires the update () method?

Hi,

 

I am developing a pretty simple custom visual but I cannot fully understand what fires the update() method. 

 

I have three data roles and for some strange reason, the update() method is not fired for every field I add to the field pane. It does not seem to be which field I add that causes this issue, it is the order in which I add them. I add a field to the one of the data roles and update() fires. When I add the second field nothing happens. When I then add the third and final field, update() fires again. Could someone help me, I have added the code elements that I think could be relvant below. 

 

As said, it does not seem to matter which field I populate first, it is always the second field that results in "nothing". 

 

I have a feeling that it is my getViewModel that is the issue.

 

capabilities.json

 

 

 

    "dataRoles": [
        {
            "displayName": "KPI Name",
            "name": "category",
            "kind": "Grouping"
        },
        {
            "displayName": "KPI Value",
            "name": "kpimeasure",
            "kind": "Measure"
        },
        {
            "displayName": "Target Value",
            "name": "targetmeasure",
            "kind": "Measure"
        }
    ],



    "dataViewMappings": [ {
            "conditions": [
                {
                    "category": { "max": 1},
                    "kpimeasure": { "max": 1},
                    "targetmeasure": { "max": 1}
                }
            ],
            "categorical": {
                "categories": { 
                    "for": { "in": "category" },
                    "dataReductionAlgorithm": { "top": {} } 
                },
                "values": {
                    "select": [
                        { "bind": { "to": "kpimeasure" } },
                        { "bind": { "to": "targetmeasure" } }
                    ]
                }
            }
        }
    ]

 

 

 

 

visual.ts

 

 

 

 

public update(options: VisualUpdateOptions) {
        
        this.settings = VisualSettings.parse<VisualSettings>(options.dataViews[0]); 

        let viewModel = this.getViewModel(options);

        let width = options.viewport.width;
        let height = options.viewport.height;

        this.svg.attr("width", width);
        this.svg.attr("height", height);

        let labelbackground = this.labelBackground
            .attr("width", width)
            .attr("height", height * this.labelSectionPercentage)
            .attr("fill", viewModel.labelBackgroundColor);
        debugger;
        let labeltext = this.labelGroup
            .selectAll(".labelText")
            .data(viewModel.dataPoints, d => (d as DataPoint).label)
            .attr("x", width / 2)
            .attr("y", height * this.labelSectionPercentage / 2)
            .attr("alignment-baseline", "middle")
            .attr("text-anchor", "middle")
            .attr("fill", "white")
            .enter()
            .append("text")
            .classed("labelText", true)
            .text(d => d.label);
    



        this.labelGroup
            .selectAll(".labelText")
            .data(viewModel.dataPoints, d => (d as DataPoint).label)
            .exit()
            .remove();


    }

private getViewModel(options: VisualUpdateOptions): ViewModel {

        let dv = options.dataViews;

        let viewModel: ViewModel = {
            dataPoints: [],
            labelBackgroundColor: "none"
        };

        if (!dv
            || !dv[0]
            || !dv[0].categorical
            || !dv[0].categorical.categories
            || !dv[0].categorical.categories[0].source
            || !dv[0].categorical.values
            || !dv[0].metadata)
            
            {
                console.log(dv);
                return viewModel;
            }

        let view = dv[0].categorical;
        let categories = view.categories[0];
        let values = view.values[0];
        let targets = view.values[1];

        for (let i = 0, len = Math.max(categories.values.length, values.values.length, targets.values.length); i < len; i++) {
            viewModel.dataPoints.push({
                label: <string>categories.values[i],
                value: <number>values.values[i],
                target: <string>targets.values[i]
                
            });
        };
        
        viewModel.labelBackgroundColor = "blue"

        return viewModel;
    }

 

 

 

 

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @Triplee74,

In terms of what causes the developer visual host to call the update method, this is pretty good overview and should help you to understand what events you're calling in your code may set it going outside of anything Power BI might be doing.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

3 REPLIES 3
dm-p
Super User
Super User

Hi @Triplee74,

In terms of what causes the developer visual host to call the update method, this is pretty good overview and should help you to understand what events you're calling in your code may set it going outside of anything Power BI might be doing.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

HI @Triplee74,

According to your decision, It sounds like you want to further debug with your custom visual update events.
If that is the case, you can take a look at the following links about update event, debug with custom visual and local storage API(may be used to export the logs) of these helps:

Visual API#update 

Local Storage API 

How to debug Power BI visuals 

Regards,

Xiaoxin Sheng

Triplee74
Frequent Visitor

Hi again,

 

I have checked some more, update() is actually firing but something happens inside the getViewModel when I add the second field.

 

Cheers

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.