【问题标题】:Doughnut chart with rounded corners - is it possible? [closed]圆角圆环图 - 有可能吗? [关闭]
【发布时间】:2021-06-03 06:56:51
【问题描述】:

我需要将其实现为圆环图 - 我四处寻找 css/svg/canvas 解决方案,但找不到任何可靠的方法。

我知道我可以将每个部分都做成圆角,但这不是我想要的。

【问题讨论】:

标签: javascript css svg charts html5-canvas


【解决方案1】:

我会使用this answerthis one 结合使用

.palette {
  --g:20px; /* The gap between shapes*/
  --s:50px; /* the size*/

  height: 300px;
  width: 300px;
  position:relative;
  display:inline-block;
  overflow:hidden;
  filter: url('#goo');
}
.palette > * {
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  border:var(--s) solid var(--c,red);
  border-radius:50%;
  clip-path:polygon(
    calc(50% + var(--g)/2) 50%, 
    calc(50% + var(--g)/2) 0%, 
    100% 0%,
    100% calc(33.745% - var(--g)/2),
    50% calc(50% - var(--g)/2)); 
}
.color1 {
  transform:rotate(72deg);
  --c:blue;
}
.color2 {
  transform:rotate(144deg);
  --c:orange;
}
.color3 {
  transform:rotate(-72deg);
  --c:green;
}
.color4 {
  transform:rotate(-144deg);
  --c:purple;
}
<div class="palette">
  <div class="color1"></div>
  <div class="color2"></div>
  <div class="color3"></div>
  <div class="color4"></div>
  <div class="color5"></div>
</div>


<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <defs>
        <filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="5" result="blur" />    
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="goo" />
            <feComposite in="SourceGraphic" in2="goo" operator="atop"/>
        </filter>
    </defs>
</svg>

【讨论】:

    【解决方案2】:

    该过滤器也可以应用于 SVG 描边路径:

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="20 20 60 60">
    <defs>
          <filter id="round">
              <feGaussianBlur in="SourceGraphic" stdDeviation="1.5" result="round1" />    
              <feColorMatrix in="round1" mode="matrix" 
                 values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 20 -14" result="round2"/>
              <feComposite in="SourceGraphic" in2="round2" operator="atop"/>
          </filter>
      </defs>
    <style>
        path{
            fill:none;
            stroke-width:9;
         }
    </style>
      <path stroke-dasharray="70 230" stroke-dashoffset="94" value="70" stroke="blue"
        filter="url(#round)" pathLength="300" d="M75 50a1 1 90 10-50 0a1 1 90 10 50 0"
      ></path>
      <path stroke-dasharray="55 245" stroke-dashoffset="173" value="55" stroke="gold"
        filter="url(#round)" pathLength="300" d="M75 50a1 1 90 10-50 0a1 1 90 10 50 0"
      ></path>
      <path stroke-dasharray="45 255" stroke-dashoffset="242" value="45" stroke="purple"
        filter="url(#round)" pathLength="300" d="M75 50a1 1 90 10-50 0a1 1 90 10 50 0"
      ></path>
      <path stroke-dasharray="30 270" stroke-dashoffset="296" value="30" stroke="red"
        filter="url(#round)" pathLength="300"  d="M75 50a1 1 90 10-50 0a1 1 90 10 50 0"
      ></path>
    </svg>
    
    <style> svg{ width:180px; background:lightgreen } </style>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-18
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 2014-04-04
      • 2010-09-05
      • 1970-01-01
      相关资源
      最近更新 更多