javascriptcsssvgchartshtml5-canvas

Doughnut chart with rounded corners - is it possible?


I need to implement this as doughnut chart - I looked around for css/svg/canvas solutions but couldn't find any reliable way of doing it.

enter image description here

I know I could have fully rounded corners of each segment, but that's not what I'm looking for.


Solution

  • I would use this answer combined with this 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>