是否可以使用 SVG 或其他方式在 XSL-fo 中创建径向进度条?
我的任务是从我在 xsl-fo 中编写的 XSL 生成 pdf 文档。我们的 CSS 专家对其进行了编码(但无法帮助我生成 pdf 和 xsl-fo),但不确定如何在 xsl-fo 中重新创建它,以便 pdf 文档也具有正确的进度条并实现百分比。
这是我应该重新创建的: Radial progress bar 他的部分 CSS 代码是:
.progress-radial {
float: left;
margin-right: 30px;
position: relative;
width: 140px;
height: 140px;
border-radius: 50%;
border: 2px solid #aa94a8;
background-color: #5d2f5d
}
.progress-radial .overlay {
position: absolute;
width: 100px;
height: 100px;
background-color: #fff;
border-radius: 50%;
margin-left: 20px;
margin-top: 20px;
text-align: center;
line-height: 100px;
font-size: 32px;
color: #6c566a
}
.progress-0 {
background-image: linear-gradient(90deg, #aa94a8 50%, transparent 50%, transparent), linear-gradient(90deg, #5d2f5d 50%, #aa94a8 50%, #aa94a8)
}
.progress-1 {
background-image: linear-gradient(90deg, #aa94a8 50%, transparent 50%, transparent), linear-gradient(93.6deg, #5d2f5d 50%, #aa94a8 50%, #aa94a8)
}
.progress-2 {
background-image: linear-gradient(90deg, #aa94a8 50%, transparent 50%, transparent), linear-gradient(97.2deg, #5d2f5d 50%, #aa94a8 50%, #aa94a8)
}
谢谢
最佳答案
这里有一些运行的灵感。鉴于此 XML:
<charts>
<chart percent="20"/>
<chart percent="40"/>
<chart percent="90"/>
</charts>
并使用这个简单的 XSL(我已经消除了所有 XSL FO 页面内容):
<xsl:template match="charts">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="chart">
<fo:block>
<fo:instream-foreign-object>
<xsl:call-template name="drawchart">
<xsl:with-param name="percent" select="@percent"/>
<xsl:with-param name="r" select="90"/>
</xsl:call-template>
</fo:instream-foreign-object>
</fo:block>
</xsl:template>
<xsl:template name="drawchart">
<xsl:param name="percent"/>
<xsl:param name="r"/>
<xsl:variable name="c" select="2*3.1415926*$r"/>
<xsl:variable name="pct" select="((100-number($percent)) div 100)*number($c)"/>
<svg id="svg" width="200" height="200" viewport="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle r="{$r}" cx="100" cy="100" fill="none" stroke="#666" stroke-width="1em" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
<circle id="bar" r="{$r}" cx="100" fill="none" cy="100" stroke="#FF9F1E;" stroke-width="1em" stroke-dasharray="565.48" style="stroke-dashoffset: {$pct}px;"></circle>
</svg>
</xsl:template>
您将得到 PDF 格式的输出:
您可以在 SVG 中添加文本(百分比),根据需要更改笔划的颜色、大小和方向/起点。
关于svg - XSL-FO 中的径向进度、线性渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45345205/