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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ysapiyev
Responsive Resident
Responsive Resident

Trouble with adding checkbox

Hi everyone,

 

I wanted to add checkbox and tried this code:

svg.selectAll("foreignObject")
        .data(nodes)
        .enter().append("foreignObject")
        .attr('x' , o.x)
        .attr('y',  o.y)
        .attr('width', 50)
        .attr('height', 20)
        .append("xhtml:body")
        .html("<form><input type=checkbox id=check></input></form>")
     .on("click", function(d, i){            console.log(svg.select("#check").node().checked) 
            }) ;

How it can be added using "input"?

 

 

9 REPLIES 9
v-viig
Community Champion
Community Champion

Hi @ysapiyev

 

At first, you should include the second body tag since iframe already has it.

The input tag can be added by using d3.append method.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

 

ysapiyev
Responsive Resident
Responsive Resident

@v-viig

 

Can you give an exaple, how it will look like? 

v-viig
Community Champion
Community Champion

 

You might use something like this code snippet:

 

d3.select(Your_Root_Element)
    .append("input")
    .attr({
        type: "checkbox"
    });

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

ysapiyev
Responsive Resident
Responsive Resident

@v-viig

 

I tried something like this:

 

let input1 = this.svg.append("input")
                    .attr({
                        type: "checkbox",
                        x: 200,
                        y: 50
                    });

However, nothing is shown. What can be wrong?

v-viig
Community Champion
Community Champion

Does this.svg contain an svg element?

Checkbox can be used only in HTML elements such as div, table, footer, etc.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

ysapiyev
Responsive Resident
Responsive Resident

@v-viig,

 

So, as I understood, I should add div to svg, then add to it checkbox?

 

let checkbox_d = d3.select("div")
.append("input")
.attr(type: "checkbox");

Is it correct?

 

 

v-viig
Community Champion
Community Champion

You should add a div container to the root element.

After that you should include input element and svg element into this div container.

 

SVG element supports the only SVG elements.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

ysapiyev
Responsive Resident
Responsive Resident

@v-viig,

 

So it will look like that?

 

let check= d3.select('body')
.append('div')
.append('input')
.type('checkbox')
let svg = d3.select(div)
.append('svg')

v-viig
Community Champion
Community Champion

Yes, that's correct.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors