当前位置: 首页>>代码示例>>Java>>正文


Java ChartUtilities.saveChartAsPNG方法代码示例

本文整理汇总了Java中org.jfree.chart.ChartUtilities.saveChartAsPNG方法的典型用法代码示例。如果您正苦于以下问题:Java ChartUtilities.saveChartAsPNG方法的具体用法?Java ChartUtilities.saveChartAsPNG怎么用?Java ChartUtilities.saveChartAsPNG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jfree.chart.ChartUtilities的用法示例。


在下文中一共展示了ChartUtilities.saveChartAsPNG方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doSaveAs

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
 * 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.defaultDirectoryForSaveAs);
	ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png");
	fileChooser.addChoosableFileFilter(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";
			}
		}
		ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight());
	}

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:AbstractChartPanel.java

示例2: actionPerformed

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
         try{
            if(fileChooser.showSaveDialog(null)==JFileChooser.APPROVE_OPTION){
                   String SelectedFileName = fileChooser.getSelectedFile().getAbsolutePath();
             if(SelectedFileName.toUpperCase().endsWith(".JPG")||
                SelectedFileName.toUpperCase().endsWith(".JPEG")){                     
                   ChartUtilities.saveChartAsJPEG(new File(SelectedFileName),TEdit,500,500);
                                                        return;
                  }

             if(SelectedFileName.toUpperCase().endsWith(".PNG")){
                   ChartUtilities.saveChartAsPNG(new File(SelectedFileName),TEdit,500,500);
                                                        return; 
                      }
                   ChartUtilities.saveChartAsPNG(new File(SelectedFileName+".png"),TEdit,500,500);
                    
              }
          }
        catch(Exception Ex){
               System.out.println(Ex.toString());   
          }
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:23,代码来源:SaveAs_Action.java

示例3: saveChartAsPNG

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
 * Saves the chart as a PNG format file in the temporary directory and
 * populates the ChartRenderingInfo object which can be used to generate
 * an HTML image map.
 *
 * @param chart  the chart to be saved (<code>null</code> not permitted).
 * @param width  the width of the chart.
 * @param height  the height of the chart.
 * @param info  the ChartRenderingInfo object to be populated (<code>null</code> permitted).
 * @param session  the HttpSession of the client.
 *
 * @return the filename of the chart saved in the temporary directory.
 *
 * @throws IOException if there is a problem saving the file.
 */
public static String saveChartAsPNG(JFreeChart chart, int width, int height,
                                    ChartRenderingInfo info, HttpSession session)
        throws IOException {

    if (chart == null) {
        throw new IllegalArgumentException("Null 'chart' argument.");   
    }
    ServletUtilities.createTempDir();
    File tempFile = File.createTempFile(
        ServletUtilities.tempFilePrefix, ".png", 
        new File(System.getProperty("java.io.tmpdir"))
    );
    ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info);
    ServletUtilities.registerChartForDeletion(tempFile, session);
    return tempFile.getName();

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:33,代码来源:ServletUtilities.java

示例4: doSaveAs

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
 * 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.
 */
public void doSaveAs() throws IOException {
    FileDialog fileDialog = new FileDialog(canvas.getShell(), SWT.SAVE);
    String[] extensions = { "*.png" };
    fileDialog.setFilterExtensions(extensions);
    String filename = fileDialog.open();
    if (filename != null) {
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        //TODO replace getSize by getBounds ?
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart, 
                canvas.getSize().x, canvas.getSize().y);
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:ChartComposite.java

示例5: saveChartAsPNG

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
 * Saves the chart as a PNG format file in the temporary directory and
 * populates the {@link ChartRenderingInfo} object which can be used to 
 * generate an HTML image map.
 *
 * @param chart  the chart to be saved (<code>null</code> not permitted).
 * @param width  the width of the chart.
 * @param height  the height of the chart.
 * @param info  the ChartRenderingInfo object to be populated 
 *              (<code>null</code> permitted).
 * @param session  the HttpSession of the client (if <code>null</code>, the
 *                 temporary file is marked as "one-time" and deleted by 
 *                 the {@link DisplayChart} servlet right after it is
 *                 streamed to the client).
 *
 * @return The filename of the chart saved in the temporary directory.
 *
 * @throws IOException if there is a problem saving the file.
 */
public static String saveChartAsPNG(JFreeChart chart, int width, int height,
        ChartRenderingInfo info, HttpSession session) throws IOException {

    if (chart == null) {
        throw new IllegalArgumentException("Null 'chart' argument.");   
    }
    ServletUtilities.createTempDir();
    String prefix = ServletUtilities.tempFilePrefix;
    if (session == null) {
        prefix = ServletUtilities.tempOneTimeFilePrefix;
    }
    File tempFile = File.createTempFile(prefix, ".png", 
            new File(System.getProperty("java.io.tmpdir")));
    ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info);
    if (session != null) {
        ServletUtilities.registerChartForDeletion(tempFile, session);
    }
    return tempFile.getName();

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:ServletUtilities.java

示例6: GenerateRTMapPNG

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2) throws IOException {
    new File(Workfolder + "/RT_Mapping/").mkdir();
    String pngfile = Workfolder + "/RT_Mapping/" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1)) + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1)) + "_RT.png";

    XYSeries smoothline = new XYSeries("RT fitting curve");
    for (XYZData data : regression.PredictYList) {
        smoothline.add(data.getX(), data.getY());
    }
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2, "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName), "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:26,代码来源:RTAlignedPepIonMapping.java

示例7: doSaveAs

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
 * 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.
 */
public void doSaveAs() throws IOException {
    FileDialog fileDialog = new FileDialog(this.canvas.getShell(),
            SWT.SAVE);
    String[] extensions = {"*.png"};
    fileDialog.setFilterExtensions(extensions);
    String filename = fileDialog.open();
    if (filename != null) {
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        //TODO replace getSize by getBounds ?
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
                this.canvas.getSize().x, this.canvas.getSize().y);
    }
}
 
开发者ID:mdzio,项目名称:ccu-historian,代码行数:24,代码来源:ChartComposite.java

示例8: writeJChartToFile

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
static String writeJChartToFile(JFreeChart chart, File file, FileTypes fileType) throws IOException, DocumentException {
    String fileName = file.getPath();
    switch (fileType) {
        case svg:
            Tools.exportChartAsSVG(chart, new Rectangle(1000, 1000), file);
            break;
        case pdf:
            Tools.exportChartAsPDF(chart, new Rectangle(500, 400), file);
            break;
        case jchart:
            break;
        case csv:
            Tools.exportChartAsCSV(chart, file);
            break;
        default:
            ChartUtilities.saveChartAsPNG(file, chart, 1000, 1000);
            break;
    }
    return fileName;
}
 
开发者ID:IARC-CSU,项目名称:CanReg5,代码行数:21,代码来源:Tools.java

示例9: buildChart

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
private static void buildChart(File mOutputFile, InformationCriterion ic) {
		
		/* This line prevents Swing exceptions on headless environments */
		if (GraphicsEnvironment.isHeadless()) { return; }
		
		int width = 500;
		int height = 300;
		try {
			if (!IMAGES_DIR.exists()) {
				IMAGES_DIR.mkdir();
			}
			ChartUtilities.saveChartAsPNG(new File(IMAGES_DIR.getPath() + File.separator + mOutputFile.getName() + "_rf_" + ic + ".png"), 
					RFHistogram.buildRFHistogram(ic),
					width, height);
			ChartUtilities.saveChartAsPNG(new File(IMAGES_DIR.getPath() + File.separator + mOutputFile.getName() + "_eu_" + ic + ".png"), 
					RFHistogram.buildEuclideanHistogram(ic),
					width, height);
		} catch (IOException e) {
//			e.printStackTrace();
		}
	}
 
开发者ID:ddarriba,项目名称:jmodeltest2,代码行数:22,代码来源:HtmlReporter.java

示例10: saveChartAsPNG

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
 * Saves the chart as a PNG format file in the temporary directory and
 * populates the {@link ChartRenderingInfo} object which can be used to
 * generate an HTML image map.
 *
 * @param chart  the chart to be saved (<code>null</code> not permitted).
 * @param width  the width of the chart.
 * @param height  the height of the chart.
 * @param info  the ChartRenderingInfo object to be populated
 *              (<code>null</code> permitted).
 * @param session  the HttpSession of the client (if <code>null</code>, the
 *                 temporary file is marked as "one-time" and deleted by
 *                 the {@link DisplayChart} servlet right after it is
 *                 streamed to the client).
 *
 * @return The filename of the chart saved in the temporary directory.
 *
 * @throws IOException if there is a problem saving the file.
 */
public static String saveChartAsPNG(JFreeChart chart, int width, int height,
        ChartRenderingInfo info, HttpSession session) throws IOException {

    if (chart == null) {
        throw new IllegalArgumentException("Null 'chart' argument.");
    }
    ServletUtilities.createTempDir();
    String prefix = ServletUtilities.tempFilePrefix;
    if (session == null) {
        prefix = ServletUtilities.tempOneTimeFilePrefix;
    }
    File tempFile = File.createTempFile(prefix, ".png",
            new File(System.getProperty("java.io.tmpdir")));
    ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info);
    if (session != null) {
        ServletUtilities.registerChartForDeletion(tempFile, session);
    }
    return tempFile.getName();

}
 
开发者ID:SOCR,项目名称:HTML5_WebSite,代码行数:40,代码来源:ServletUtilities.java

示例11: generate

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public static void generate(ClusterTimeSeriesReport report, String reportDir, String fileName) throws IOException {
   File root = new File(reportDir);
   if (!root.exists()) {
      if (!root.mkdirs()) {
         log.warn("Could not create root dir : " + root.getAbsolutePath()
               + " This might result in reports not being generated");
      } else {
         log.info("Created root file: " + root);
      }
   }
   File chartFile = new File(root, fileName + ".png");
   Utils.backupFile(chartFile);

   ChartUtilities.saveChartAsPNG(chartFile, createChart(report), 1024, 768);

   log.info("Chart saved as " + chartFile);
}
 
开发者ID:ppdai,项目名称:blacksmith,代码行数:18,代码来源:TimeSeriesReportGenerator.java

示例12: generateChart

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public void generateChart(String dir) throws Exception {
   long nrReads = 0;
   long nrWrites = 0;
   if(reportDesc.getItems().size() > 0) {
      for (ReportItem item : reportDesc.getItems()) {
         getData.addValue(item.getReadsPerSec(), item.description(), "GET");
         nrReads += item.getNoReads();
         putData.addValue(item.getWritesPerSec(), item.description(), "PUT");
         nrWrites += item.getNoWrites();
      }
      File localGetFile = new File(dir, "local_gets_" + reportDesc.getReportName() + ".png");
      Utils.backupFile(localGetFile);

      ChartUtilities.saveChartAsPNG(localGetFile, createChart("Report: Comparing Cache GET (READ) performance", getData, (int) (nrReads / reportDesc.getItems().size()), "(GETS)"), 800, 800);

      File localPutFile = new File(dir, "local_puts_" + reportDesc.getReportName() + ".png");
      Utils.backupFile(localPutFile);

      ChartUtilities.saveChartAsPNG(localPutFile, createChart("Report: Comparing Cache PUT (WRITE) performance", putData, (int) (nrWrites / reportDesc.getItems().size()), "(PUTS)"), 800, 800);
   }
}
 
开发者ID:ppdai,项目名称:blacksmith,代码行数:22,代码来源:LocalChartGenerator.java

示例13: generateChart

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
private static void generateChart(String benchmark, DefaultCategoryDataset dataset, int benchmarkCount) {
	JFreeChart chart = ChartFactory.createBarChart(
			benchmark, "framework", "throughput", dataset,
			PlotOrientation.HORIZONTAL, true, false, false);

	CategoryPlot plot = chart.getCategoryPlot();
	BarRenderer renderer = (BarRenderer) plot.getRenderer();
	renderer.setItemMargin(0);
	notSoUglyPlease(chart);
	
	String pngFile = getOutputName(benchmark);
	
	try {
		int height = 100 + benchmarkCount * 20;
		ChartUtilities.saveChartAsPNG(new File(pngFile), chart, 700, height);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:junkdog,项目名称:entity-system-benchmarks,代码行数:20,代码来源:ChartWriterFactory.java

示例14: saveChartAsFile

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
/**
 * @description:保存jfreechart 数据为图片并上传至分布式文件系统,返回文件地址
 * @date:2014-5-30 下午12:03:31
 * @version:v1.0
 * @param chart
 * @param showName:chart name
 * @param width
 * @param height
 * @return
 */
public static String saveChartAsFile(JFreeChart chart, String showName,int width,int height){
	FileInputStream fin = null;
	String fileId = "";
	try {
		//创建临时文件
		File tempFile = File.createTempFile(System.currentTimeMillis() + showName , "png");
		ChartUtilities.saveChartAsPNG(tempFile, chart, width, height);
		//图片存储到图片服务器
		fin = new FileInputStream(tempFile);
		byte[] data = new byte[fin.available()];
		fin.read(data);
		fin.close();
		//图片上传到分布式文件系统
		fileId = FileUpDownLoadHandler.postFile("cynthia" + showName + System.currentTimeMillis(), data);
		tempFile.delete();  //删除临时文件
		
	} catch (IOException e) {
		e.printStackTrace();
	}finally{
		StreamCloser.closeInputStream(fin);
	}
	
	return downloadURL + fileId;
}
 
开发者ID:afrous,项目名称:Cynthia,代码行数:35,代码来源:FileUpDownLoadHandler.java

示例15: DynamicImageController

import org.jfree.chart.ChartUtilities; //导入方法依赖的package包/类
public DynamicImageController() {
       try {
           //Graphic Text
           BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);
           Graphics2D g2 = bufferedImg.createGraphics();
           g2.drawString("This is a text", 0, 10);
           ByteArrayOutputStream os = new ByteArrayOutputStream();
           ImageIO.write(bufferedImg, "png", os);
           graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png"); 

           //Chart
           JFreeChart jfreechart = ChartFactory.createPieChart("Turkish Cities", createDataset(), true, true, false);
           File chartFile = new File("dynamichart");
           ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 375, 300);
           chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png");

           //Barcode
		File barcodeFile = new File("dynamicbarcode");
		BarcodeImageHandler.saveJPEG(BarcodeFactory.createCode128("PRIMEFACES"), barcodeFile);
		barcode = new DefaultStreamedContent(new FileInputStream(barcodeFile), "image/jpeg");
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:websphere,项目名称:PrimefacesShowcase,代码行数:25,代码来源:DynamicImageController.java


注:本文中的org.jfree.chart.ChartUtilities.saveChartAsPNG方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。