Add a link to another page with d3.js

£可爱£侵袭症+ 提交于 2019-12-24 12:29:51

问题


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;
    }   

回答1:


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>");


来源:https://stackoverflow.com/questions/16461512/add-a-link-to-another-page-with-d3-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!