JFreeChart & Image

Is it possible to make an image / BufferedImage for JFreeChart?

+4
source share
3 answers

Casting an image in JFree is not possible. To create an image from JFreechart, you can do the following:

BufferedImage objBufferedImage=objJFreechart.createBufferedImage(600,800); ByteArrayOutputStream bas = new ByteArrayOutputStream(); try { ImageIO.write(objBufferedImage, "png", bas); } catch (IOException e) { e.printStackTrace(); } byte[] byteArray=bas.toByteArray(); 

This creates a byte [].

Now you need to create an image from byte []. This does the following.

 InputStream in = new ByteArrayInputStream(obj); BufferedImage image = ImageIO.read(in); File outputfile = new File("image.png"); ImageIO.write(image, "png", outputfile); 

The image is created at the project creation location (local disk).

+14
source

JfreeChart first takes the data and generates the image using the general ChartUtilities class or any customized utility class.

 ChartUtilities.writeChartAsPNG(outputstream,getDataset(), width,height); 

Perhaps this may help you: here

+14
source

The JFreeChart object JFreeChart designed to create images, it does not consume them, and images cannot be converted to a JFreeChart object. See: http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

+3
source

Source: https://habr.com/ru/post/1343312/


All Articles