當前位置: 首頁>>代碼示例>>Java>>正文


Java ChartUtilities.encodeAsPNG方法代碼示例

本文整理匯總了Java中org.jfree.chart.ChartUtilities.encodeAsPNG方法的典型用法代碼示例。如果您正苦於以下問題:Java ChartUtilities.encodeAsPNG方法的具體用法?Java ChartUtilities.encodeAsPNG怎麽用?Java ChartUtilities.encodeAsPNG使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jfree.chart.ChartUtilities的用法示例。


在下文中一共展示了ChartUtilities.encodeAsPNG方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBarChartAsPNGByteArray

import org.jfree.chart.ChartUtilities; //導入方法依賴的package包/類
/**
 * Helper method that returns the JFreeChart as a PNG byte array.
 *
 * @param chartName a {@link java.lang.String} object.
 * @return a byte array
 * @throws org.exolab.castor.xml.MarshalException if any.
 * @throws org.exolab.castor.xml.ValidationException if any.
 * @throws java.io.IOException if any.
 * @throws java.sql.SQLException if any.
 */
public static byte[] getBarChartAsPNGByteArray(String chartName) throws MarshalException, ValidationException, IOException, SQLException {
    BarChart chartConfig = getBarChartConfigByName(chartName);
    JFreeChart chart = getBarChart(chartName);
    ImageSize imageSize = chartConfig.getImageSize();
    int hzPixels;
    int vtPixels;
    
    if (imageSize == null) {
        hzPixels = 400;
        vtPixels = 400;
    } else {            
        hzPixels = imageSize.getHzSize().getPixels();
        vtPixels = imageSize.getVtSize().getPixels();
    }
    return ChartUtilities.encodeAsPNG(chart.createBufferedImage(hzPixels, vtPixels));
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:27,代碼來源:ChartUtils.java

示例2: generateImageData

import org.jfree.chart.ChartUtilities; //導入方法依賴的package包/類
@Override
public boolean generateImageData() {
    // Create the dataset.
    DefaultCategoryDataset dataset = createDataset();

    if (dataset == null) {
        return false;
    }

    // Create the chart.
    JFreeChart lineChart = ChartFactory.createLineChart(
            title,
            nameX, nameY,
            dataset, PlotOrientation.VERTICAL,
            true, true, false);

    //final CategoryPlot plot = lineChart.getCategoryPlot();
    //((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter());

    // Generate the image.
    try {
        imageData = ChartUtilities.encodeAsPNG(lineChart.createBufferedImage(720, 480));
    } catch (IOException e) {
        return false;
    }

    return true;
}
 
開發者ID:OrfeasZ,項目名稱:AweSheet,代碼行數:29,代碼來源:LineChart.java

示例3: generateImageData

import org.jfree.chart.ChartUtilities; //導入方法依賴的package包/類
@Override
public boolean generateImageData() {
    // Create the dataset.
    DefaultCategoryDataset dataset = createDataset();

    if (dataset == null) {
        return false;
    }

    // Create the chart.
    JFreeChart barChart = ChartFactory.createBarChart(
            title,
            nameX, nameY,
            dataset, PlotOrientation.VERTICAL,
            true, true, false);

    final CategoryPlot plot = barChart.getCategoryPlot();
    ((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter());

    // Generate the image.
    try {
        imageData = ChartUtilities.encodeAsPNG(barChart.createBufferedImage(720, 480));
    } catch (IOException e) {
        return false;
    }

    return true;
}
 
開發者ID:OrfeasZ,項目名稱:AweSheet,代碼行數:29,代碼來源:BarChart.java

示例4: getImage

import org.jfree.chart.ChartUtilities; //導入方法依賴的package包/類
public static ImagePortObject getImage(JFreeChart chart, boolean asSvg, int width, int height) {
	if (asSvg) {
		SVGDocument document = (SVGDocument) new SVGDOMImplementation().createDocument(null, "svg", null);
		SVGGraphics2D g = new SVGGraphics2D(document);

		g.setSVGCanvasSize(new Dimension(width, height));

		if (chart != null) {
			chart.draw(g, new Rectangle2D.Double(0, 0, width, height));
		}

		g.dispose();
		document.replaceChild(g.getRoot(), document.getDocumentElement());
		return new ImagePortObject(new SvgImageContent(document), new ImagePortObjectSpec(SvgCell.TYPE));
	} else {
		try {
			BufferedImage img = chart != null ? chart.createBufferedImage(width, height)
					: new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

			return new ImagePortObject(new PNGImageContent(ChartUtilities.encodeAsPNG(img)),
					new ImagePortObjectSpec(PNGImageContent.TYPE));
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
}
 
開發者ID:SiLeBAT,項目名稱:BfROpenLab,代碼行數:28,代碼來源:ChartUtils.java


注:本文中的org.jfree.chart.ChartUtilities.encodeAsPNG方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。