Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:49:51+00:00 2026-06-10T20:49:51+00:00

I am trying to generate a table which is being embedded into SVG with

  • 0

I am trying to generate a table which is being embedded into SVG with a structure like this:

<table>
  <tr>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
  </tr>
</table>

out of a dataset like this:

var a = ["a", 1, "b", 2, "c", 3]

so that the count of tags is dynamic depending on the number of key-value pairs, so in this case 2. Inside of it would be a static number of two td’s each with the key and value respectively.

So far I have tried something like this:

var tr = ele.append("svg:foreignObject")
                    .attr("x", 5)
                    .attr("y", 30)
                    .attr("width", 60)
                    .attr("height", 120)
                    .append("xhtml:body")
                    .attr("xmlns", "http://www.w3.org/1999/xhtml")
                    .selectAll("tr")
                      .data(d3.keys(a))
                    .enter().append("tr");
tr.selectAll("td").data(a).enter()
 .append("td")
   .text(function (d) { return d; } );

which results in something like this:

<tr>
  <td></td>
  <td></td>
  <td></td>
</tr>  
<tr>
  <td></td>
  <td></td>
  <td></td>
</tr>
<tr>
  <td></td>
  <td></td>
  <td></td>
</tr>

So, a correct number of rows, but an incorrect number of tds.

Edit:
Performing a

tr.append("td").text("test");
tr.append("td").text("test2");

results in a correct structure, although when I try to iterate through the dataset using the .data() function with two separate appends, it of course adds two duplicate tds.

Edit 2:
I have ended up solving my problem by generating the HTML for the table outside of d3.js chain and just appending it as .html(). Is there any neater way of doing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:49:54+00:00Added an answer on June 10, 2026 at 8:49 pm

    You can structure your data like this: [["a",1],["b",2],["c",3]].

    Then you can do:

    var tr = table.selectAll("tr").data(data);
    tr.enter().append("tr");
    tr.each(function(d) {
       var td = d3.select(this).selectAll("td").data(d);
       td.enter().append("td");
    })
    

    Something like that.

    Haven’t compiled, but it should give you an idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate a query that selects all from a user table
I'm trying to query 2 tables to generate records for a third table which
I'm trying to write a PowerShell script that will generate a table of information
I'm trying to generate a table of contents from a block of HTML (not
I'm trying to generate a dynamic table using CSS: <html> <head> <style> div.el1, div.el2
I'm trying to generate a big table of consecutive numbers in MySQL. I just
I trying to generate an XML document which is around 23 to 30 MB,
I'm trying to generate SQL table header from a csv file. As I had
I have a table which contains the following columns and I am trying to
I have a table I am trying to generate reports from. Its basically a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.