Class ExportUtils


  • public class ExportUtils
    extends java.lang.Object
    Utility functions for exporting charts to SVG and PDF format.
    • Constructor Summary

      Constructors 
      Constructor Description
      ExportUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isJFreeSVGAvailable()
      Returns true if JFreeSVG is on the classpath, and false otherwise.
      static boolean isOrsonPDFAvailable()
      Returns true if OrsonPDF (or JFreePDF) is on the classpath, and false otherwise.
      static void writeAsJPEG​(Drawable drawable, int w, int h, java.io.File file)
      Writes the current content to the specified file in JPEG format.
      static void writeAsPDF​(Drawable drawable, int w, int h, java.io.File file)
      Writes a Drawable to the specified file in PDF format.
      static void writeAsPNG​(Drawable drawable, int w, int h, java.io.File file)
      Writes the current content to the specified file in PNG format.
      static void writeAsSVG​(Drawable drawable, int w, int h, java.io.File file)
      Writes the current content to the specified file in SVG format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExportUtils

        public ExportUtils()
    • Method Detail

      • isJFreeSVGAvailable

        public static boolean isJFreeSVGAvailable()
        Returns true if JFreeSVG is on the classpath, and false otherwise. The JFreeSVG library can be found at http://www.jfree.org/jfreesvg/
        Returns:
        A boolean.
      • isOrsonPDFAvailable

        public static boolean isOrsonPDFAvailable()
        Returns true if OrsonPDF (or JFreePDF) is on the classpath, and false otherwise. The OrsonPDF library can be found at https://github.com/jfree/orsonpdf. JFreePDF is a modular version of the same library, requiring Java 11 or later. Since JFreeChart might be used in a modular context, this function has been modified (in version 1.5.3) to detect JFreePDF also.
        Returns:
        A boolean.
      • writeAsSVG

        public static void writeAsSVG​(Drawable drawable,
                                      int w,
                                      int h,
                                      java.io.File file)
        Writes the current content to the specified file in SVG format. This will only work when the JFreeSVG library is found on the classpath. Reflection is used to ensure there is no compile-time dependency on JFreeSVG.
        Parameters:
        drawable - the drawable (null not permitted).
        w - the chart width.
        h - the chart height.
        file - the output file (null not permitted).
      • writeAsPDF

        public static void writeAsPDF​(Drawable drawable,
                                      int w,
                                      int h,
                                      java.io.File file)
        Writes a Drawable to the specified file in PDF format. This will only work when the OrsonPDF library is found on the classpath. Reflection is used to ensure there is no compile-time dependency on OrsonPDF.
        Parameters:
        drawable - the drawable (null not permitted).
        w - the chart width.
        h - the chart height.
        file - the output file (null not permitted).
      • writeAsPNG

        public static void writeAsPNG​(Drawable drawable,
                                      int w,
                                      int h,
                                      java.io.File file)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
        Writes the current content to the specified file in PNG format.
        Parameters:
        drawable - the drawable (null not permitted).
        w - the chart width.
        h - the chart height.
        file - the output file (null not permitted).
        Throws:
        java.io.FileNotFoundException - if the file is not found.
        java.io.IOException - if there is an I/O problem.
      • writeAsJPEG

        public static void writeAsJPEG​(Drawable drawable,
                                       int w,
                                       int h,
                                       java.io.File file)
                                throws java.io.FileNotFoundException,
                                       java.io.IOException
        Writes the current content to the specified file in JPEG format.
        Parameters:
        drawable - the drawable (null not permitted).
        w - the chart width.
        h - the chart height.
        file - the output file (null not permitted).
        Throws:
        java.io.FileNotFoundException - if the file is not found.
        java.io.IOException - if there is an I/O problem.