首页 > 代码库 > d3 使用数据
d3 使用数据
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>testD3-3.html</title> <script type="text/javascript" src=http://www.mamicode.com/"http://localhost:8080/spring/js/d3.js"></script> </head> <body> <script type="text/javascript"> var dataset = [ 5, 10, 15, 20, 25 ]; d3.select("body").selectAll("p") .data(dataset) .enter() .append("p") .text(function(d) { return "I can count up to " + d; }) .style("color", function(d) { if (d > 15) { //大于15的数字显示为红色 return "red"; } else { return "black"; } }); </script> </body> </html>
.text(function(d){}), 在回调函数当中传入的数据分别对应数组当中的数据,
.style(), 同上,在回调函数当中传入对应的数据,根据数据返回字体的颜色
d3 使用数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。