gpt4 book ai didi

d3.js - D3 - 向矩形添加背景填充

转载 作者:行者123 更新时间:2023-12-01 02:14:04 25 4
gpt4 key购买 nike

是否可以向矩形元素添加背景填充?我正在使用 rect 元素来创建条形图。每个 rect 元素都有一个宽度和填充集。我想用颜色填充剩余的宽度。

See here: http://codepen.io/jesouhaite08/pen/fhvzA

谢谢!

最佳答案

为了获得最佳灵活性,我会使用其他矩形来绘制条形图的背景,请查看 fork 示例:http://codepen.io/anon/pen/JnlAE

// Bars
svg_fun.selectAll('rect.background')
.data(dataset)
.enter()
.append('rect')
.classed('background', true)
.attr('y', function(d, i) {return i * h_line; })
.attr('x', 0)
.attr('height', 20)
.attr('width', function(d) {return scale_x(max_x);} )
.attr('fill', 'red')

svg_fun.selectAll('rect.bar')
.data(dataset)
.enter()
.append('rect')
.classed('bar', true)
.attr('y', function(d, i) {return i * h_line; })
.attr('x', 0)
.attr('height', 20)
.attr('width', function(d) {return scale_x(d);} )
.attr('fill', 'teal')

关于d3.js - D3 - 向矩形添加背景填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26535078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com