You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Sa...@commerzbank.com on 2004/07/12 16:51:31 UTC

how to generate charts in PDF?

hi derrick, 
thanks alot for your answer...

I just tried your code,
and I got this exception :
 
javax.xml.transform.TransformerException: Prefix must resolve to a
namespace: math

hope you can help me more


sandy


We use SVG to generate our Pie Charts and our bar charts. It's not too hard
to create. I looked at the code from this site and started creating my own
variations for testing.
http://www.svgopen.org/2003/papers/CreatingSVGPieChartsThroughWebService
Here is a Pie Chart that I tested with: <fo:table-cell
xsl:use-attribute-sets="table-piechart-style"> <xsl:variable name="number"
select="operatingaverages/monthly/efficiency" /> <xsl:variable
name="difference" select="100 - $number" /> <xsl:variable
name="currentAngle" select="math:toRadians(($number div 100) * 360.0)" />
<xsl:variable name="halfAngle" select="math:toRadians((($number div 2) div
$total) * 360.0)" /> <xsl:variable name="rotation" select="270 + (360.0 *
($number div 100))" /> <xsl:variable name="x1" select="math:cos($halfAngle)
* 70" /> <xsl:variable name="y1" select="math:sin($halfAngle) * 70" />
<xsl:variable name="cosTheta" select="math:cos(math:toRadians($rotation))"
/> <xsl:variable name="sinTheta"
select="math:sin(math:toRadians($rotation))" /> <fo:instream-foreign-object>
<svg height="100" viewBox="0 0 200 100" width="200"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <path
style="fill:{$color1};stroke:black;stroke-width:1;fillrule:evenodd;
stroke-linejoin:bevel;"> <xsl:attribute name="transform">
<xsl:text>translate(100,50)</xsl:text> <xsl:text>rotate(</xsl:text>
<xsl:value-of select="$rotation" /> <xsl:text>)</xsl:text> </xsl:attribute>
<xsl:attribute name="d"> <xsl:text>M 50 0 A 50 50 0 </xsl:text> <xsl:choose>
<xsl:when test="$currentAngle > 3.14"> <xsl:text>1 </xsl:text> </xsl:when>
<xsl:otherwise> <xsl:text>0 </xsl:text> </xsl:otherwise> </xsl:choose>
<xsl:text>1 </xsl:text> <xsl:value-of select="math:cos($currentAngle) * 50"
/> <xsl:text> </xsl:text> <xsl:value-of select="math:sin($currentAngle) *
50" /> <xsl:text> L 0 0 Z</xsl:text> </xsl:attribute> </path> </g> </svg>
</fo:instream-foreign-object> </fo:table-cell> Derrick Shoemake 


"Die vorstehend geäußerte Meinung gibt nur die Auffassung des Autors wieder
und darf nicht als Hinweis auf die Meinung der Commerzbank AG oder einer
ihrer Tochtergesellschaften verstanden oder ausgelegt werden." 

"those managing expressed opinion shows only the view of the author
and may not not as reference to the opinion of the Commerzbank AG or
one of their subsidiaries be understood or laid out."


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: how to generate charts in PDF?

Posted by Derrick Shoemake <ds...@protocolinc.com>.
Sandy,

You have to add java to the namespace, like so

xmlns:math="java.lang.Math" exclude-result-prefixes="math"

Derrick

On Jul 12, 2004, at 9:51 AM, Sandy.Soesilo@commerzbank.com wrote:

>
> hi derrick,
> thanks alot for your answer...
>
> I just tried your code,
> and I got this exception :
>
> javax.xml.transform.TransformerException: Prefix must resolve to a
> namespace: math
>
> hope you can help me more
>
>
> sandy
>
>
> We use SVG to generate our Pie Charts and our bar charts. It's not too  
> hard
> to create. I looked at the code from this site and started creating my  
> own
> variations for testing.
> http://www.svgopen.org/2003/papers/ 
> CreatingSVGPieChartsThroughWebService
> Here is a Pie Chart that I tested with: <fo:table-cell
> xsl:use-attribute-sets="table-piechart-style"> <xsl:variable  
> name="number"
> select="operatingaverages/monthly/efficiency" /> <xsl:variable
> name="difference" select="100 - $number" /> <xsl:variable
> name="currentAngle" select="math:toRadians(($number div 100) * 360.0)"  
> />
> <xsl:variable name="halfAngle" select="math:toRadians((($number div 2)  
> div
> $total) * 360.0)" /> <xsl:variable name="rotation" select="270 +  
> (360.0 *
> ($number div 100))" /> <xsl:variable name="x1"  
> select="math:cos($halfAngle)
> * 70" /> <xsl:variable name="y1" select="math:sin($halfAngle) * 70" />
> <xsl:variable name="cosTheta"  
> select="math:cos(math:toRadians($rotation))"
> /> <xsl:variable name="sinTheta"
> select="math:sin(math:toRadians($rotation))" />  
> <fo:instream-foreign-object>
> <svg height="100" viewBox="0 0 200 100" width="200"
> xmlns="http://www.w3.org/2000/svg"
> xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <path
> style="fill:{$color1};stroke:black;stroke-width:1;fillrule:evenodd;
> stroke-linejoin:bevel;"> <xsl:attribute name="transform">
> <xsl:text>translate(100,50)</xsl:text> <xsl:text>rotate(</xsl:text>
> <xsl:value-of select="$rotation" /> <xsl:text>)</xsl:text>  
> </xsl:attribute>
> <xsl:attribute name="d"> <xsl:text>M 50 0 A 50 50 0 </xsl:text>  
> <xsl:choose>
> <xsl:when test="$currentAngle > 3.14"> <xsl:text>1 </xsl:text>  
> </xsl:when>
> <xsl:otherwise> <xsl:text>0 </xsl:text> </xsl:otherwise> </xsl:choose>
> <xsl:text>1 </xsl:text> <xsl:value-of select="math:cos($currentAngle)  
> * 50"
> /> <xsl:text> </xsl:text> <xsl:value-of  
> select="math:sin($currentAngle) *
> 50" /> <xsl:text> L 0 0 Z</xsl:text> </xsl:attribute> </path> </g>  
> </svg>
> </fo:instream-foreign-object> </fo:table-cell> Derrick Shoemake
>
>
> "Die vorstehend geäußerte Meinung gibt nur die Auffassung des Autors  
> wieder
> und darf nicht als Hinweis auf die Meinung der Commerzbank AG oder  
> einer
> ihrer Tochtergesellschaften verstanden oder ausgelegt werden."
>
> "those managing expressed opinion shows only the view of the author
> and may not not as reference to the opinion of the Commerzbank AG or
> one of their subsidiaries be understood or laid out."
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: how to generate charts in PDF?

Posted by Phillip Rhodes <sp...@rhoderunner.com>.
I am doing this with 20+ charts/graphs and FOP.

I used jfreechart.  My servlet would construct a
jfreechart object based upon request parameters based
to it.  jfreechart allows you to export the java2d
object as png, jpg, svg, etc.

I merely include the URL in my FO document as an
external graphic.  The URL is to my servlet with all
the request parameters needed to generate the chart.

Hope that gives you an idea.

To be honest, I had to give up on using the SVG as a
format for my charts.  While the image quality is much
sharper than png, I found it problematic to use with
my document.  






--- Sandy.Soesilo@commerzbank.com wrote:
> 
> hi derrick, 
> thanks alot for your answer...
> 
> I just tried your code,
> and I got this exception :
>  
> javax.xml.transform.TransformerException: Prefix
> must resolve to a
> namespace: math
> 
> hope you can help me more
> 
> 
> sandy
> 
> 
> We use SVG to generate our Pie Charts and our bar
> charts. It's not too hard
> to create. I looked at the code from this site and
> started creating my own
> variations for testing.
>
http://www.svgopen.org/2003/papers/CreatingSVGPieChartsThroughWebService
> Here is a Pie Chart that I tested with:
> <fo:table-cell
> xsl:use-attribute-sets="table-piechart-style">
> <xsl:variable name="number"
> select="operatingaverages/monthly/efficiency" />
> <xsl:variable
> name="difference" select="100 - $number" />
> <xsl:variable
> name="currentAngle" select="math:toRadians(($number
> div 100) * 360.0)" />
> <xsl:variable name="halfAngle"
> select="math:toRadians((($number div 2) div
> $total) * 360.0)" /> <xsl:variable name="rotation"
> select="270 + (360.0 *
> ($number div 100))" /> <xsl:variable name="x1"
> select="math:cos($halfAngle)
> * 70" /> <xsl:variable name="y1"
> select="math:sin($halfAngle) * 70" />
> <xsl:variable name="cosTheta"
> select="math:cos(math:toRadians($rotation))"
> /> <xsl:variable name="sinTheta"
> select="math:sin(math:toRadians($rotation))" />
> <fo:instream-foreign-object>
> <svg height="100" viewBox="0 0 200 100" width="200"
> xmlns="http://www.w3.org/2000/svg"
> xmlns:xlink="http://www.w3.org/1999/xlink"> <g>
> <path
>
style="fill:{$color1};stroke:black;stroke-width:1;fillrule:evenodd;
> stroke-linejoin:bevel;"> <xsl:attribute
> name="transform">
> <xsl:text>translate(100,50)</xsl:text>
> <xsl:text>rotate(</xsl:text>
> <xsl:value-of select="$rotation" />
> <xsl:text>)</xsl:text> </xsl:attribute>
> <xsl:attribute name="d"> <xsl:text>M 50 0 A 50 50 0
> </xsl:text> <xsl:choose>
> <xsl:when test="$currentAngle > 3.14"> <xsl:text>1
> </xsl:text> </xsl:when>
> <xsl:otherwise> <xsl:text>0 </xsl:text>
> </xsl:otherwise> </xsl:choose>
> <xsl:text>1 </xsl:text> <xsl:value-of
> select="math:cos($currentAngle) * 50"
> /> <xsl:text> </xsl:text> <xsl:value-of
> select="math:sin($currentAngle) *
> 50" /> <xsl:text> L 0 0 Z</xsl:text>
> </xsl:attribute> </path> </g> </svg>
> </fo:instream-foreign-object> </fo:table-cell>
> Derrick Shoemake 
> 
> 
> "Die vorstehend ge�u�erte Meinung gibt nur die
> Auffassung des Autors wieder
> und darf nicht als Hinweis auf die Meinung der
> Commerzbank AG oder einer
> ihrer Tochtergesellschaften verstanden oder
> ausgelegt werden." 
> 
> "those managing expressed opinion shows only the
> view of the author
> and may not not as reference to the opinion of the
> Commerzbank AG or
> one of their subsidiaries be understood or laid
> out."
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail:
> fop-user-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org