admin管理员组

文章数量:1302497

This is probably really straight forward. I'm looking to add a link to another page. I'm trying to add it through d3. Do I add another attribute in the JS? Iv tried .attr("src", "newPage.html") and .attr("url", "newPage.html") but neither work.

Any advice would be appreciated. Thanks.

   //JS
   var newLink = d3.select(".chart")
      .append("div")
      .html("Trend Graph")
      .attr("class", "populationTrend")


    //CSS
   .populationTrend{
       font-weight:400;
       margin-top:-15%;
       cursor:pointer;
       padding-left:70%;
       background-color:#039;
    }   

This is probably really straight forward. I'm looking to add a link to another page. I'm trying to add it through d3. Do I add another attribute in the JS? Iv tried .attr("src", "newPage.html") and .attr("url", "newPage.html") but neither work.

Any advice would be appreciated. Thanks.

   //JS
   var newLink = d3.select(".chart")
      .append("div")
      .html("Trend Graph")
      .attr("class", "populationTrend")


    //CSS
   .populationTrend{
       font-weight:400;
       margin-top:-15%;
       cursor:pointer;
       padding-left:70%;
       background-color:#039;
    }   
Share Improve this question asked May 9, 2013 at 12:12 DaftDaft 11k16 gold badges65 silver badges105 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

To add a "normal" link (i.e. anchor tag), you can simply do

d3.select(".chart")
  .append("a")
  .attr("href", "newPage.html")
  .html("new page");

or even

d3.select(".chart")
  .append("div")
  .html("<a href='newPage.html'>new page</a>");

本文标签: javascriptAdd a link to another page with d3jsStack Overflow