使用XSLT从XML创建SVG条形图 [英] Create SVG bar charts from XML with XSLT

查看:102
本文介绍了使用XSLT从XML创建SVG条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XSLT将XML转换为SVG.我想创建水平条形图,其左侧为一个值,条形图值为右侧. XML看起来像这样:

I'm using XSLT to transform XML to SVG. I want to create horizontal bar charts with one value to left and the bar chart value to the right. The XML looks like this:

<value1 name="something">
  <value2>13</value2>
</value1>
<value1 name="something else">
  <value2>45</value2>
</value1>

这就是到目前为止,我从value2创建水平条形图.

And this is what I got so far, creating horizontal bar charts from value2.

<xsl:template match="/" mode="svg">
    <svg width="500px" height="500px" xmlns="http://www.w3.org/2000/svg">
      <g id="bar" transform="translate(50,50) rotate(90 90 90)">
        <xsl:for-each select=".../value1">
        <xsl:variable name="val" select="value2"/>
      <rect x="{position()*25}" y="-{$val*1.5}" height="{$val*1.5}" width="15" style="fill:{@fill};"/>
      <text x="{position()*25 + 7.5}" y="0" style="font-family:arial;text-anchor:middle;baseline-shift:-15;">
      </text>
    </xsl:for-each>
  </g>
</svg>

我遇到的问题是将文本和图表放在一起.我想错了吗?我希望输出看起来像这样:

The problem I'm having is getting the text and the charts together. Am I thinking wrong? I want the output to look like this:

value1     bar chart  value2
value1     longer bar chart  value2

我真的很困,不胜感激!

I'm really stuck so any help is appreciated!

推荐答案

使用XSLT实用程序模板生成SVG条形图,如下所示:

Use XSLT utility templates to generate an SVG bar chart, such as the following:

  • XSLT Cookbook Examples
  • Simple SVG Chart Generation with XSLT
  • Generating SVG with XSLT
  • XSLT Graphtools
  • Using XSLT to Generate SVG Content
  • SVG Coordinate Transformations

这篇关于使用XSLT从XML创建SVG条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆