html - 构建圆形百分比图表

标签 html css svg

我想建立响应SVG圆形图表,我已经在一定程度上成功了。

HTML

<div>
            <p class="Project_Analytics_Heading text-center">
                Time per Application
            </p>
            <svg viewBox="0 0 36 36" class="circular-chart">

                <path class="that-circle" stroke="#ffba00" stroke-dasharray="50" d="M18 2.0845
                                a 15.9155 15.9155 0 0 1 0 31.831
                                a 15.9155 15.9155 0 0 1 0 -31.831" />

                <path class="that-circle" stroke="#ff4858" stroke-dasharray="25" d="M18 2.0845
                                a 15.9155 15.9155 0 0 1 0 31.831
                                a 15.9155 15.9155 0 0 1 0 -31.831" />

                <path class="that-circle" stroke="#845cee" stroke-dasharray="25" d="M18 2.0845
                                a 15.9155 15.9155 0 0 1 0 31.831
                                a 15.9155 15.9155 0 0 1 0 -31.831" />

                <text x="18" y="20.35" class="percentage">50%</text>
                <text x="13" y="25" class="percentage_done">iOS</text>

            </svg>
        </div>

CSS

.circular-chart {
  display: block;
  margin: 5% auto;
  max-width: 80%;
  max-height: 240px;
  margin-bottom: 15%;
}
.that-circle {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  animation: progress 1s ease-out forwards;
  box-shadow: 0 8px 25px 0 #e5e5e5;
}
@keyframes progress {
  0% {
    stroke-dasharray: 0 100;
  }
}

.percentage {
  fill: #4285f4;
  font-size: 0.375em;
  text-anchor: middle;
  font-family: AvenirNext;
  font-weight: bold;
  font-style: normal;
  font-stretch: normal;
  line-height: 1;
  letter-spacing: normal;
}
.percentage_done {
  fill: #9b9b9b;
  font-size: 0.2em;
  font-family: AvenirNext;
  font-weight: 500;
  font-style: normal;
  font-stretch: normal;
  line-height: normal;
  letter-spacing: 0.1px;
}

获取输出

期望的输出

enter image description here

我认为中风破折号数组存在问题。

非常感谢您的评论。

我已推荐

https://medium.com/@pppped/how-to-code-a-responsive-circular-percentage-chart-with-svg-and-css-3632f8cd7705

最佳答案

关于html - 构建圆形百分比图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52644567/

相关文章:

c# - ASP.NET Web 应用程序无法使用自定义 Bootstrap 正确显示内容

html - 将字形 div 移高

python - 为什么我的 CSS 样式不会显示在 Flask 应用程序上

html - 表格固定标题和第一列 css/html

html - 跨浏览器的毛玻璃效果与css

javascript - 使用 JavaScript 选择 SVG 和路径元素

javascript - 使 three.js 脚本固定在可滚动页面中

javascript - 如何使用按钮更改嵌入源?

jquery - 将文本换行到未设置的图像宽度

javascript - 使用 https 命名空间时 createElementNS 无法正常工作