如何以编程方式在SVG路径中构建曲线?

时间:2018-07-30 09:54:02

标签: javascript html css svg

我正在尝试使用SVG构建折线图,但是我很难使路径具有漂亮的曲线。就像互联网告诉我的那样,实现这一目标的最佳方法是使用QT,但我并没有真正获得预期的结果。

这里是我构建的两个版本,第一个没有曲线,但是第二个由于某种原因使svg容器溢出。

*, *:after, *:before {
  box-sizing: border-box;
  position: relative;
  
  font-family: 'Montserrat', sans-serif;
}

svg {
  width: 30vmin; height: 30vmin;
  fill: none;
  position: relative;
  z-index: 3;
  
  border: 2px solid red;
}

path {
  stroke-width: 3px;
  
  // stroke-dasharray: 4;
}

button {
  left: 0; top: 0;
  position: absolute;
}

html, body {
  overflow: hidden;
  width: 100%; height: 100%;
  
  display: flex;
  align-items: center;
  justify-content: space-around;
  
  margin: 0; padding: 0;
  
  background-color: #333ddd;
}
<svg viewBox="0 0 100 100" preserveAspectRatio="none"><path d="M0,16.372727272727275 Q7.6923076923076925,29.09090909090908 15.384615384615385,29.09090909090908 23.076923076923077,2.7363636363636346 30.76923076923077,42.73636363636363 38.46153846153846,69.0909090909091 46.15384615384615,56.37272727272727 53.84615384615385,56.37272727272727 61.53846153846154,82.73636363636363 69.23076923076923,95.45454545454545 76.92307692307692,82.73636363636363 84.61538461538461,82.73636363636363 92.3076923076923,42.73636363636363 T100,42.73636363636363" fill="none" stroke="white" vector-effect="non-scaling-stroke"></path></svg>

<svg viewBox="0 0 100 100" preserveAspectRatio="none"><path d="M0,16.372727272727275 Q 7.6923076923076925,29.09090909090908 15.384615384615385,29.09090909090908 T 23.076923076923077,2.7363636363636346 30.76923076923077,42.73636363636363 38.46153846153846,69.0909090909091 46.15384615384615,56.37272727272727 53.84615384615385,56.37272727272727 61.53846153846154,82.73636363636363 69.23076923076923,95.45454545454545 76.92307692307692,82.73636363636363 84.61538461538461,82.73636363636363 92.3076923076923,42.73636363636363 100,42.73636363636363" fill="none" stroke="white" vector-effect="non-scaling-stroke"></path></svg>

<svg viewBox="0 0 100 100" preserveAspectRatio="none"><path d="M0,16.372727272727275 7.6923076923076925,29.09090909090908 15.384615384615385,29.09090909090908 23.076923076923077,2.7363636363636346 30.76923076923077,42.73636363636363 38.46153846153846,69.0909090909091 46.15384615384615,56.37272727272727 53.84615384615385,56.37272727272727 61.53846153846154,82.73636363636363 69.23076923076923,95.45454545454545 76.92307692307692,82.73636363636363 84.61538461538461,82.73636363636363 92.3076923076923,42.73636363636363 100,42.73636363636363" fill="none" stroke="white" vector-effect="non-scaling-stroke"></path></svg>

有什么主意我在做错什么,或者如何更好地解决这个问题?

0 个答案:

没有答案