Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 17884

Value Formatter Causing Custom Visual To Disappear

$
0
0

Hi there.

 

After banging my head on a brick wall for many an hour now, I cannot get the final piece of a custom visual working. 

 

I am trying to format a value, which is coming through as a measure, into the same format as described by Power BI, in this case, a precentage number to 1 decimal place. Here is a simplified version of my code, I've removed all drawing commands etc.

 

Visual.ts

enter code module powerbi.extensibility.visual {

"use strict";

import ValueFormatter = powerbi.extensibility.utils.formatting.valueFormatter;
import IValueFormatter = powerbi.extensibility.utils.formatting.IValueFormatter;

export class Visual implements IVisual {

    private host: IVisualHost;
    private svg: d3.Selection<SVGElement>;
    private container: d3.Selection<SVGElement>;
    private textValue: d3.Selection<SVGElement>;

    private visualSettings: VisualSettings;

    constructor(options: VisualConstructorOptions) {

        this.svg = d3.select(options.element)
            .append('svg')
            .classed('circleCard', true);

        this.container = this.svg.append("g")
            .classed('container', true);

        this.textValue = this.container.append("text")
            .classed("textValue", true);
    }

    public update(options: VisualUpdateOptions) {

        let dataView: DataView = options.dataViews[0];

        this.visualSettings = VisualSettings.parse<VisualSettings>(dataView);

        // Grab the width and height of the element.
        let width: number = options.viewport.width;
        let height: number = options.viewport.height;

        // Set the width and height of element to the SVG viewport.
        this.svg.attr({
            width: width,
            height: height
        });

        // Height, width and radius of the gauge
        let tWidth: number = width / 2;
        let tHeight: number = height - 1;
        let radius: number = height;

        // Make sure the gauge fits within the view.
        if (radius > (width / 2))
            radius = tWidth;

        // Define the inner and outer radius of the gauge.
        let oRadius: number = radius;
        let iRadius: number = radius / 1.5;

        // Trying to format the number! Smiley Sad
        let valueFormatter: IValueFormatter = ValueFormatter.create({
            format: "0.00"
        });

        // Commenting out this line makes it work!
        console.log(valueFormatter.format(123));

        // Display the value used for the arc calculation.
        this.textValue
            .text("69.8%")
            .attr({
                x: '50%',
                y: tHeight - (iRadius / 3),
                dy: '0.35em', 'text-anchor': 'middle'
            }).style({
                'font-size': (iRadius / 30) + 'em',
                'font-family': 'Arial',
                'fill': '#ffffff'
            });

    }

    private static parseSettings(dataView: DataView): VisualSettings {
        return VisualSettings.parse(dataView) as VisualSettings;
    }

    /** 
     * This function gets called for each of the objects defined in the capabilities files and allows you to select which of the 
     * objects and properties you want to expose to the users in the property pane.
     * 
     */
    public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
        const settings: VisualSettings = this.visualSettings || VisualSettings.getDefault() as VisualSettings;
        return VisualSettings.enumerateObjectInstances(settings, options);
    }
}
}

If I comment out the console.log line, the visual displays the text, if I uncomment the console.log line, the text in the visual disappears. I do not get any warnings from PBIVIZ, therefore it is compiling okay. I'm sure there is an error occuring but what and how/where to find the error, I've no idea (new to this custom visual lark).

 

Any help would be gratefully appreciated.


Viewing all articles
Browse latest Browse all 17884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>