javascript - Place a link in imported data in table D3 -
i'm importing data csv table through d3.js. want in step place link other pages when user clicks in 1 of cells.
i have table transformer id column , if user clicks id of transformer, redirected page (which create in html).
i have seen few examples .attr started learning d3.js few weeks ago and, @ moment, can't write code myself.
can me please?
$(document).ready(function() { d3.text("data/table-assets.csv", function(data) { var parsedcsv = d3.csv.parserows(data); var container = d3.select(".table-striped") .append("tbody") .selectall("tr") .data(parsedcsv).enter() .append("tr") .selectall("td") .data(function(d) { return d; }).enter() .append("td") .text(function(d) { return d; }).style('background-color',function(d){ if(d>90){ return "#4cc417"; } else if(d<90 && d>80){ return "#b2c248"; } else if(d<80) { return "#dc381f"; }}).style('color', function(d){ if(d>0){ return "white"; } }); }); });
a link can create using .append('a').attr('href',function(d){return ...})
it practise structure code little bit:
var tr = table.selectall("tr").data(...) var tr_new = tr.enter().append("tr") tr_new...//set styles etc. var td = tr_new.selectall("td").data(...) var td_new = td.enter().append("td") td_new...//set styles, append contents etc.
Comments
Post a Comment