javascript - 如何以编程方式在 svg 路径中构建曲线?
问题描述
我正在尝试使用 SVG 构建折线图,但我很难让路径具有漂亮的曲线。正如互联网告诉我的那样,实现这一目标的最佳方法是使用Q
and T
,但我并没有真正得到预期的结果。
这是我构建的两个版本,第一个没有曲线,但第二个由于某种原因溢出了 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>
任何想法我做错了什么或如何更好地解决这个问题?
解决方案
推荐阅读
- docker - 无法让 nodemon 在 docker 容器中工作
- groovy - 将 Jmeter __V 函数变量转换为 groovy vars.get
- r - 如何在R中重复值直到某一年
- excel - 尝试在具有更改行数的过滤数据的表上使用 Vlookup
- c# - 如何使用 Microsoft.Azure.Management.Fluent 在 Azure 存储帐户上设置最小 TLS;
- php - Laravel 中的集合计数
- javascript - Firebase:如何通过 JS 接收/添加信息到单独的集合
- ruby-on-rails - 头像图片主动存储 Rails 6
- amazon-web-services - AWS ECR - 应用适用于所有存储库而不是单独的 IAM 策略
- google-app-engine - Google App Engine 服务到服务身份验证(非编程)