code: public void saveToFile(File outputFile) throws IOException {
      String filename = outputFile.getName();
  
      int extPoint = filename.lastIndexOf('.');
  
      if (extPoint < 0) {
        throw new IOException("Illegal filename, no extension used.");
      }
  
      // Determine the extension of the filename.
      String ext = filename.substring(extPoint + 1);
  
      // Handle jpg without transparency.
      if (ext.toLowerCase().equals("jpg") || ext.toLowerCase().equals("jpeg")) {
        BufferedImage chart = (BufferedImage) getChartImage(false);
  
        // Save our graphic.
        saveGraphicJpeg(chart, outputFile, 1.0f);
      }
      else {
        BufferedImage chart = (BufferedImage) getChartImage(true);
  
        ImageIO.write(chart, ext, outputFile);
      }
    }
docs: Generates a new chart <code>Image</code> based upon the currently held settings and then
  attempts to save that image to disk, to the location provided as a File parameter. The image
  type of the saved file will equal the extension of the filename provided, so it is essential
  that a suitable extension be included on the file name.
  
  <p>
  All supported <code>ImageIO</code> file types are supported, including PNG, JPG and GIF.
  
  <p>
  No chart will be generated until this or the related <code>getChartImage()</code> method are
  called. All successive calls will result in the generation of a new chart image, no caching is
  used.
  
  @param outputFile the file location that the generated image file should be written to. The
  File must have a suitable filename, with an extension of a valid image format (as supported by
  <code>ImageIO</code>).
  @throws IOException if the output file's filename has no extension or if there the file is
  unable to written to. Reasons for this include a non-existant file location (check with the
  File exists() method on the parent directory), or the permissions of the write location may be
  incorrect.