Forum Discussion

mankeycloun's avatar
mankeycloun
Regular Visitor
9 years ago
Solved

Adding image to visual

Hello everyone! I'm hardly trying to place an image file in my custom visual, but still can't acheive any result. I'm not so experienced, so I would be very thankful for any help. Many thanks!
  • mankeycloun's avatar
    mankeycloun
    9 years ago

    If anybody faces the same problem, there is a code of src/visual.ts file just below.

    Image of logo appears on the visual screen and can be scaled automaticly depending on scale of the visual window.

    The only problem is showing image without binding any data to a visual.

     

    _____________________________________________________________________________________________________________________________

    module powerbi.extensibility.visual {


    export class Visual implements IVisual {

    private logo:d3.Selection<SVGImageElement>;
    private svg:d3.Selection<SVGImageElement>;
    private padding: number = 10; 

    constructor(options: VisualConstructorOptions) {

    this.svg=d3.select(options.element).append('svg')
    .attr("x",0)
    .attr("y",0)
    .attr("width",1000)
    .attr("height",1000);

    this.logo = this.svg.append('svg');

     

    this.svg=this.logo.append("image")
    .attr("xlink:href","https://upload.wikimedia.org/wikipedia/ru/b/b8/Inteco_logo.png")
    .attr("x", 0)
    .attr("y", 0);

    }

    public update(options: VisualUpdateOptions) {

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


    }

    public destroy(): void {

    }
    }
    }

    _____________________________________________________________________________________________________________________________