【问题标题】:Defs pattern with css module - modify point in c3.js line chart to have an image inside带有 css 模块的 Defs 模式 - 修改 c3.js 折线图中的点以在其中包含图像
【发布时间】:2016-08-02 08:57:35
【问题描述】:

我正在使用 c3.js,我的组件正在使用 CSS 模块。我想用图像修改折线图中点的填充。为此,我在渲染方法中添加了 defs-pattern -

render(){
    return (
          <div>
            <defs>
              <pattern id="image" x="0" y="0" patternUnits="userSpaceOnUse" height="1" width="1">
                <image x="0" y="0" src="http://dummyimage.com/20x20/faf2fa/0011ff.png&text=x" />
              </pattern>
            </defs>
            <C3Chart {...this.getConfig()}/>
          </div>
        );
}

在我添加的样式 css 文件中 -

container :global(.c3-target-subscriber .c3-circle-5) {
  fill: url(#image) !important;
}

但是什么也没发生。我只想在折线图的点内显示一个图像。

非常感谢任何帮助。

【问题讨论】:

    标签: reactjs c3.js css-modules


    【解决方案1】:

    &lt;defs&gt; 元素的父元素必须是 SVG 元素,而不是 HTML 元素。你需要这样的东西:

    <svg>
      <defs>
        <pattern id="image" x="0" y="0" patternUnits="userSpaceOnUse" height="1" width="1">
           <image x="0" y="0" src="http://dummyimage.com/20x20/faf2fa/0011ff.png&text=x" />
        </pattern>
      </defs>
    <svg>
    

    你的 CSS 也指向一个 id 为渐变的东西,但你的图案的 id 是图像。

    【讨论】:

    • 对不起,但这并不能解决问题。它是 w.r.t css 模块,我想知道如何在 react 中使用 css 模块。
    • 它确实解决了您的一个问题。也许您还有其他人,在这种情况下您需要创建一个minimal reproducible example
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    相关资源
    最近更新 更多