本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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;
}
}
}