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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
matthias_vc
Frequent Visitor

Visual Format settings are reset after closing and opening

Hi, I've made a Custom visual that Looks quite ok and has about 60 Format settings that a user can vary depending on their preference.
It all worked perfectly untill I saved a PBI file with this visual and opened it up again. All the settings were back to default. Any ideas on what I did wrong?
below is the general scheme of how my code looks like related to the settings:

 

...
interface Viewmodel {
    ...
    settings: MSTASettings;
}
interface MSTASettings {
    lines: {
        show: boolean;
        ...
       }
    ...
}
let defaultSettings: MSTASettings = {
    lines: {
        show: true,
        ...
       }
    ...
}
export class Visual implements IVisual {
    constructor(options: VisualConstructorOptions) {
    this.mstaSettings = <MSTASettings>{};
    ...
    }
    public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
    let objectEnumeration: VisualObjectInstance[] = [];
    switch (options.objectName) {
        case 'lines':
            objectEnumeration.push({
                objectName: objectName,
                properties: {
                    show: this.mstaSettings.lines.show,
                    ...
                },
                selector: {}
            });
            break;
        ...
    return objectEnumeration
    }
    public update(options: VisualUpdateOptions) {
        let viewModel = this.getViewModel(options);
        let settings = this.mstaSettings = viewModel.settings;
        ...
    }
    private getViewModel(options: VisualUpdateOptions): Viewmodel {
        let viewmodel: Viewmodel = {
            ...
            settings:<MSTASettings>{},
            ...
        };
        viewmodel.settings = {
            lines: {
               show: getValue<boolean>(objects, 'lines', 'show', defaultSettings.lines.show),
                ...
            },
            ...
        }
        ...
        return viewmodel;
    }
    function getValue<T>(objects: DataViewObjects, objectName: string, propertyName: string, defaultValue: T): T {
        if (objects) {
            let object = objects[objectName];
            if (object) {
                let property: T = <T>object[propertyName];
                if (property !== undefined) {
                    return property;
                }
            }
        }
        return defaultValue;
    }
}

 

Note: I didn't use the latest version as I started this project a couple of years ago and only now found the time to tweek it. 
Note2: I tried getting rid of the line In the Constructor. My code still worked, but the issue remained the same.

0 REPLIES 0

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors