Angular / svg - 将数据传递到 svg

ttm*_*tmt 2 svg angular

我这里有一个 stackblitz - https://stackblitz.com/edit/angular-vkwets?file=src%2Fapp%2Fdonuts.template.html

我有一个 Angular 组件,它为传​​递给组件的数组的每个数据点创建一个 svg 圆环图。

我可以访问传递到组件中的数据,但是否可以在 svg.json 中使用它?

我想使用传递给组件的数据来更新 svg 中的“行程-破折号”。

就像是stroke-dasharray=donut.percent 100-donut.perecent

<div>
  <ul>
    <li *ngFor="let donut of donutData">
      {{donut.percent}}
      <svg width="20%" height="20%" viewBox="0 0 42 42" class="donut">
        <circle class="donut-hole" 
                cx="21" 
                cy="21" 
                r="15.91549430918954" 
                fill="#fff"></circle>

        <circle class="donut-ring" 
                cx="21" 
                cy="21" 
                r="15.91549430918954" 
                fill="transparent" 
                stroke="#d2d3d4" 
                stroke-width="3"></circle>

        <circle class="donut-segment" 
                cx="21" 
                cy="21" 
                r="15.91549430918954" 
                fill="transparent" 
                stroke="green" 
                stroke-width="3" 
                stroke-dasharray="60 40"
                stroke-dashoffset="25"></circle>
      </svg>

    </li>
  </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

Con*_*Fan 5

将值转换为字符串并使用属性绑定

[attr.stroke-dasharray]="donut.percent + ' ' + (100 - donut.percent)"
Run Code Online (Sandbox Code Playgroud)

请参阅此 stackblitz的演示。