【问题标题】:SVG gradient as polylines stroke background with absolute positionSVG渐变作为具有绝对位置的折线描边背景
【发布时间】:2015-06-27 07:36:06
【问题描述】:

是否可以设置应用于折线的渐变背景的绝对位置?

例如当我设置渐变时:

<filter id="black-glow">
    <feColorMatrix type="matrix" values=
       "0 0 0 0   0        
        0 0 0 0   0
        0 0 0 0   0
        0 0 0 1   0" />
    <feGaussianBlur stdDeviation="3" result="coloredBlur" />
    <feMerge>
      <feMergeNode in="coloredBlur" />
      <feMergeNode in="SourceGraphic" />
    </feMerge>
</filter>

到折线的笔划:

<polyline points="50,350 ... 350,239" style="fill:none;" stroke="url(#grad1)" stroke-width="3" stroke-linecap="round" />

(折线有最大/最小位置点)

结果还可以:

但是,当折线是平的:

绿色要高得多。由于这是彩色图表,我需要实现不断查看背景,与绘制折线的方式无关。

【问题讨论】:

  • 你能给我们一个jsfiddle吗?
  • 你看。一个简单的 jsfiddle 有帮助 ;)

标签: svg polyline linear-gradients


【解决方案1】:

如果您希望在用户空间中应用渐变,则可以通过如下方式表达渐变:

<linearGradient id="grad1" gradientUnits="userSpaceOnUse" x1="0"
                y1="350" x2="0" y2="220">

fiddle

x1、y1、x2 和 y2 中的值将相对于当前用户空间坐标系,因此如果您使用百分比,它们将相对于最近的视口,而不是使用渐变的形状的边界框。详情请见svg specification

【讨论】:

  • 谢谢,它有效。我看过文档,我尝试使用“objectBoundingBox”而不是“userSpaceOnUse”,但出现了问题(图表不可见)。我意识到另一个过滤器有问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-27
  • 2011-08-25
  • 1970-01-01
  • 2020-12-29
  • 2018-01-18
  • 1970-01-01
相关资源
最近更新 更多