Using XSLT and SVG to create bar chart from XML - Scaling Bar Chart

后端 未结 1 718
借酒劲吻你
借酒劲吻你 2021-01-05 14:19

I\'m new to XSLT and SVG and have already done a lot of research. I\'ve seen some answers on here that look close to what I need help with but not quite working for me. Any

相关标签:
1条回答
  • 2021-01-05 14:58

    There's probably a better way to do this, but here's a quick fix:

    <xsl:template match="/">
    
    <xsl:variable name="max">
        <xsl:for-each select="Report/RESULTS/ROW/*">
            <xsl:sort select="." data-type="number" order="descending"/>
            <xsl:if test="position()=1">
                <xsl:value-of select="."/>
            </xsl:if>
        </xsl:for-each>
    </xsl:variable>
    
    <svg width="650" height="500">
      <g id="axis" transform="translate(0 500) scale(1 -1)">
      <line id="axis-y" x1="30" y1="20" x2="30" y2="450" style="fill:none;stroke:rgb(0,0,0);stroke-width:2"/>
      <line id="axis-x" x1="30" y1="20" x2="460" y2="20"  style="fill:none;stroke:rgb(0,0,0);stroke-width:2"/>
      </g>  
      <xsl:for-each select="Report/RESULTS/ROW">
       <g id="bars" transform="translate(30 479) scale(1 -430)">
        <rect x="30" y="0" width="50" height="{PASSED div $max}"  style="fill:rgb(81,223,13);stroke:rgb(0,0,0);stroke-width:0"/>     
        <rect x="100" y="0" width="50" height="{FAILED div $max}"  style="fill:rgb(224,12,12);stroke:rgb(0,0,0);stroke-width:0"/>  
        <rect x="170" y="0" width="50" height="{CAUTION div $max}"  style="fill:rgb(245,136,37);stroke:rgb(0,0,0);stroke-width:0"/>  
        <rect x="240" y="0" width="50" height="{BLOCKED div $max}"  style="fill:rgb(248,241,7);stroke:rgb(0,0,0);stroke-width:0"/>  
        <rect x="310" y="0" width="50" height="{NOTRUN div $max}"  style="fill:rgb(180,180,180);stroke:rgb(0,0,0);stroke-width:0"/>  
      </g> 
    ...
    
    0 讨论(0)
提交回复
热议问题