动态圆圈依靠d3条形图

时间:2019-01-31 06:59:54

标签: javascript d3.js charts bar-chart

我正在基于d3图表制作分组条形图。

我尝试在条形图上画圈,如下所示。

enter image description here

但是我只能得到低于输出的值。

enter image description here

我的d3代码是

circles.exit().remove();
    circles.enter()
    .append('circle')
        .attr('cx', (d, i) => {
            return this.xScale(d.id) + (this.xScale.bandwidth() / 2);
        })
        .attr('cy', (data) => { 
            const circleCnt = this.getCircleCount(data); 
            return (this.yScale(0) + Math.abs(this.yScale(circleCnt) - this.yScale(0)) - 20) ;
        })

    .attr('r', 4)
    .attr('fill', data => {
        const circleCnt = this.getCircleCount(data); 
            if (circleCnt > 0) { 
                     return 'green';
                } 
            } 
    })

基于count,必须在每个小节中放置小柱。

动态圆圈必须放在每个小节上

0 个答案:

没有答案
相关问题