SvgCharts4Xsl

SVG or Scalable Vector Graphics is a powerful way to render vector graphics on screen and print media. Propelled by its adoption and availability of editors, it has become the de-facto standard for creating and publishing vector graphics.

SvgCharts4Xsl is a set of utility XSL templates, written in XSLT 1.0, for SVG charting. It can be used to embed SVG images in your HTML and PDF documents (via XSL-FO). If you want to convert the generated SVG to a raster format (JPEG/PNG/TIFF) from a Java application, consider using Batik.

Currently SvgCharts4Xsl supports the following types of charts:

  1. Line Chart: Plots both positive and negative values.
  2. Bar Chart: Plots both positive and negative values.
  3. Pie Chart: Plots only positive values, negative values are discarded. Uses EXSLT extensions to overcome the limitations of XPath 1.0, hence may not work with all transformers.

Usage

Import/include the respective chart XSL file in your stylesheet and call the appropriate method with required arguments (some are optional). For generating standalone SVG files, use appropriate DOCTYPE tag as shown in the examples.

Download

You can download this project in either zipor tar formats.

Sample Outputs

Shows up correctly only on SVG 1.1 compliant browser (E.g: Google Chrome)

Line Chart

0 82 164 246 328 410 492 574 656 738 820 902 984 ABC BDE CDE DEF EGH FGH GHI HIJ IJK JKL KLM LMN MNO NOP OPQ PQR QRS RST STU TUV VWX XYZ
-120 -100 -80 -60 -40 -20 0 20 40 60 80 ABCDE BCDEF CDEFG DEFGH EFGHI FGHIJ GHIJK HIJKL IJKLM JKLMN KLMNO LMNOP MNOPQ NOPQR OPQRS PQRST QRSTU

Bar Chart

0 82 164 246 328 410 492 574 656 738 820 902 984 ABC BDE CDE DEF EGH FGH GHI HIJ IJK JKL KLM LMN MNO NOP OPQ PQR QRS RST STU TUV VWX XYZ
-120 -100 -80 -60 -40 -20 0 20 40 60 80 ABCDE BCDEF CDEFG DEFGH EFGHI FGHIJ GHIJK HIJKL IJKLM JKLMN KLMNO LMNOP MNOPQ NOPQR OPQRS PQRST QRSTU

Pie Chart

9% 9% 8% 8% 7% 7% 6% 5% 41% IJK (975) OPQ (939) XYZ (900) RST (834) NOP (797) HIJ (712) MNO (652) QRS (580) Others (4447)
20% 11% 10% 9% 9% 7% 7% 6% 6% 6% 11% LMNOP (65) KLMNO (35) IJKLM (32) ABCDE (30) HIJKL (29) MNOPQ (23) PQRST (22) BCDEF (20) QRSTU (20) EFGHI (19) Others (37)