Java Code Examples for org.jfree.chart.ChartUtils#saveChartAsPNG()

The following examples show how to use org.jfree.chart.ChartUtils#saveChartAsPNG() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EChartPanel.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
@Override
public void doSaveAs() throws IOException {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setCurrentDirectory(this.getDefaultDirectoryForSaveAs());
  FileNameExtensionFilter filter =
      new FileNameExtensionFilter(localizationResources.getString("PNG_Image_Files"), "png");
  fileChooser.addChoosableFileFilter(filter);
  fileChooser.setFileFilter(filter);

  int option = fileChooser.showSaveDialog(this);
  if (option == JFileChooser.APPROVE_OPTION) {
    String filename = fileChooser.getSelectedFile().getPath();
    if (isEnforceFileExtensions()) {
      if (!filename.endsWith(".png")) {
        filename = filename + ".png";
      }
    }
    ChartUtils.saveChartAsPNG(new File(filename), getChart(), getWidth(), getHeight(),
        getChartRenderingInfo());
  }
}
 
Example 2
Source File: EChartPanel.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
@Override
public void doSaveAs() throws IOException {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setCurrentDirectory(this.getDefaultDirectoryForSaveAs());
  FileNameExtensionFilter filter =
      new FileNameExtensionFilter(localizationResources.getString("PNG_Image_Files"), "png");
  fileChooser.addChoosableFileFilter(filter);
  fileChooser.setFileFilter(filter);

  int option = fileChooser.showSaveDialog(this);
  if (option == JFileChooser.APPROVE_OPTION) {
    String filename = fileChooser.getSelectedFile().getPath();
    if (isEnforceFileExtensions()) {
      if (!filename.endsWith(".png")) {
        filename = filename + ".png";
      }
    }
    ChartUtils.saveChartAsPNG(new File(filename), getChart(), getWidth(), getHeight(),
        getChartRenderingInfo());
  }
}
 
Example 3
Source File: EChartPanel.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
@Override
public void doSaveAs() throws IOException {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setCurrentDirectory(this.getDefaultDirectoryForSaveAs());
  FileNameExtensionFilter filter =
      new FileNameExtensionFilter(localizationResources.getString("PNG_Image_Files"), "png");
  fileChooser.addChoosableFileFilter(filter);
  fileChooser.setFileFilter(filter);

  int option = fileChooser.showSaveDialog(this);
  if (option == JFileChooser.APPROVE_OPTION) {
    String filename = fileChooser.getSelectedFile().getPath();
    if (isEnforceFileExtensions()) {
      if (!filename.endsWith(".png")) {
        filename = filename + ".png";
      }
    }
    ChartUtils.saveChartAsPNG(new File(filename), getChart(), getWidth(), getHeight(),
        getChartRenderingInfo());
  }
}
 
Example 4
Source File: ChartRenderer.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Draw a JFreeChart to an image based on values from a MultiTable.
 * @param table MultiTable to retrieve values from
 * @param config chart configuration options
 */
public static void drawChartAsFile(MultiTable table, MultiTableChartConfig config) {
  
  JFreeChart chart = createChart(table, config);
  
  // Save the chart as a PNG image to the file system
  try {
    ChartUtils.saveChartAsPNG(new File(config.getFilename()), chart, config.getWidth(),
        config.getHeight());
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
Example 5
Source File: ChartRenderer.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Draw a JFreeChart to an image based on values from a MultiTable.
 * @param person Person to retrieve attributes from
 * @param config chart configuration options
 */
public static void drawChartAsFile(Person person, PersonChartConfig config) {
  
  JFreeChart chart = createChart(person, config);
  
  // Save the chart as a PNG image to the file system
  try {
    ChartUtils.saveChartAsPNG(new File(config.getFilename()), chart, config.getWidth(),
        config.getHeight());
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
Example 6
Source File: ChartExportUtil.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static void writeChartToPNG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName) throws IOException {
  ChartUtils.saveChartAsPNG(fileName, chart, width, height, info);
}
 
Example 7
Source File: ChartExportUtil.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static void writeChartToPNG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName) throws IOException {
  ChartUtils.saveChartAsPNG(fileName, chart, width, height, info);
}
 
Example 8
Source File: ChartExportUtil.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static void writeChartToPNG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName) throws IOException {
  ChartUtils.saveChartAsPNG(fileName, chart, width, height, info);
}