Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am trying to create a custom visual, requirement is to show the text in the visual on a Button click.
Created a project and added code for the button and on click event for the button, I am able to create the button but on click event is not triggered/not working.
"use strict";
import "core-js/stable";
import "./../style/visual.less";
import powerbi from "powerbi-visuals-api";
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import { html, select, selectAll, Selection } from 'd3';
import { VisualSettings } from "./settings";
export class Visual implements IVisual {
private target: HTMLElement;
private updateCount: number;
private settings: VisualSettings;
private textNode: Text;
private svg: Selection<SVGElement, any, any, any>;
private onclick1 = "<button onclick=\"myFunction()\">Click me</button>"
+"<p id=\"demo\"></p><script>"
+"function myFunction() {"
+" document.getElementById(\"demo\").innerHTML = \"Hello World\";"
+"}"
+"</script>";
constructor(options: VisualConstructorOptions) {
this.target = options.element; //Working code for HTML
}
public update(options: VisualUpdateOptions) {
this.target.innerHTML = this.onclick1;
}
}
Beginner in the typescript and Power BI.
Hope to get some help.
Any luck with this? I'm trying the same thing.
No, left typerscript workk now working on power bi desktop, are you able to resovle this? if yes please help me with solution.
I did.
This code just keeps appending text to the visual each time the button is clicked.
"use strict";
import "core-js/stable";
import "./../style/visual.less";
import powerbi from "powerbi-visuals-api";
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import * as d3 from "d3";
import { VisualSettings } from "./settings";
export class Visual implements IVisual {
private root: d3.Selection<HTMLElement, {}, HTMLElement, any>;
private button: d3.Selection<HTMLInputElement, {}, HTMLElement, any>;
private settings: VisualSettings = new VisualSettings;
constructor(options: VisualConstructorOptions) {
this.root = d3.select(options.element);
// Add Button Element
this.button = this.root.append("input")
.attr("type", "button")
.attr("name", "mybutton")
.attr("value", "Click Me")
.on("click", this.clickedButton);
}
public update(options: VisualUpdateOptions) {
}
// Event handler for button click
private clickedButton = () => {
this.root.append("div")
.text("Hello World!");
}
}
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
7 | |
6 | |
3 | |
2 | |
2 |