是否可以使用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)
}谢谢
发布于 2017-07-28 05:52:22
这里有一些可以用来运行的灵感。给定此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中添加文本(百分比),根据需要更改笔划的颜色、大小和方向/起点。
发布于 2017-07-27 17:08:35
如果您使用AH格式化程序,则可以使用linear-gradient()。参见https://www.antennahouse.com/product/ahf64/ahf-ext.html#linear-gradient。否则,您也许能够在fo:instream-foreign-object中生成您想要的SVG。
https://stackoverflow.com/questions/45345205
复制相似问题