Skip to content

Instantly share code, notes, and snippets.

@jto
Created August 19, 2010 19:50
Show Gist options
  • Save jto/538735 to your computer and use it in GitHub Desktop.
Save jto/538735 to your computer and use it in GitHub Desktop.
/*
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);
}
@jto
Copy link
Author

jto commented Aug 20, 2010

JfreeChart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment