【问题标题】:Simple way of making an SVG block in React have a gradient of color using D3.js使用 D3.js 在 React 中制作 SVG 块的简单方法具有颜色渐变
【发布时间】:2020-05-29 04:00:46
【问题描述】:

我正在尝试使用 D3.js 在 React 组件中创建条形图,但似乎找不到简单的说明来创建一个矩形,该矩形在一端以纯色开始,向另一端逐渐消失.

所以给定一个简单的 30 x 300 矩形:

const bar = () => {
  const b = select('svg')
    .append('rect')
    .attr('width', 300)
    .attr('height', 30)
}

const App = () => {
  useEffect(() => {
    bar()
  })
    return (
      <div>
        <svg width={200} height={200}>

        </svg>
      </div>
    )
}

render(<App />, document.getElementById('root'))

如何让方块从纯黑色变为灰色?

【问题讨论】:

标签: javascript reactjs d3.js svg


【解决方案1】:

为此,您可以使用带有 defs 的线性渐变。 这是详细的文章供您参考。 D3 Charts with Gradient Color

【讨论】:

    猜你喜欢
    • 2020-11-24
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2016-10-01
    • 2015-12-21
    • 2014-12-03
    • 1970-01-01
    相关资源
    最近更新 更多