Created
August 19, 2010 19:50
-
-
Save jto/538735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Before to use this, U need to place 2 jar file in lib folder of your | |
play project. | |
jcommon-xx.jar | |
jfreechart-xx.jar | |
( These File can found in JFreeChart Download Package lib folder) | |
Here is Code in controller Method. | |
*/ | |
public static void chart() throws IOException { | |
DefaultPieDataset data = new DefaultPieDataset(); | |
data.setValue("Category 1", 250); | |
data.setValue("Category 2", 500); | |
data.setValue("Category 3", 310); | |
JFreeChart chart = ChartFactory.createPieChart( | |
"Sample Pie Chart", | |
data, | |
true, // legend? | |
true, // tooltips? | |
false // URLs? | |
); | |
BufferedImage bf = chart.createBufferedImage(500, 500); | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
ImageIO.write(bf, "jpg", baos); | |
baos.flush(); | |
byte[] imageInByte = baos.toByteArray(); | |
baos.close(); | |
InputStream is = new ByteArrayInputStream(imageInByte); | |
response.contentType = "image/jpg"; | |
renderBinary(is); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JfreeChart