d3.js v4 Symbols曲线添加符号

1.d3.symblo()

  • d3提供的符号的生成器,原理是通过path画出的形状;

  • d3提供了7种不同的的符号: circle, cross, diamond, square, star, triangle, and wye,如下图;对应d3.symbols[n]n代表的0,1,2,3,4,5,6;

2.demo

  • 曲线图标识案例,注意定位symbol的时候要使用translate

    let n = Math.round(Math.random()*6) 
     enterDot.append("path")
    .attr("class","dot")
    .attr("transform",function(d){return `translate(${xScale(d.x)},${yScale(d.y)})`})
    .attr("d",d3.symbol().type(function (d, i) {
             return d3.symbols[n];
    }).size(200))
    .style("fill","green")
  • 源码:https://github.com/HK-Kevin/d...

  • demo:https://hk-kevin.github.io/d3...

你可能感兴趣的:(数据可视化,d3.js)