1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
JFreeChart jfreechart = ChartFactory.createPieChart3D("Ventes Globales ", defaultPieDataset, true, true, false);
PiePlot3D piePlot3d = (PiePlot3D)jfreechart.getPlot();
piePlot3d.setStartAngle(290D);
piePlot3d.setDirection(Rotation.ANTICLOCKWISE);
piePlot3d.setForegroundAlpha(0.60f);
piePlot3d.setInteriorGap(0.33);
piePlot3d.setNoDataMessage("No data to display");
piePlot3d.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
piePlot3d.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1} ({2})"));
TextTitle textTitle = jfreechart.getTitle() ;
textTitle.setFont(new Font("Arial", Font.BOLD, 15));
int largeur = 1000 ;
int hauteur = 400 ;
ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
String filename = ServletUtilities.saveChartAsJPEG(jfreechart, largeur, hauteur, chartRenderingInfo, request.getSession());
Graphe graphe = this.initImage(request, chartRenderingInfo, filename);
// sauvgarder le graph en PDF sur le serveur
File fileName = new File( "d:\\temp\\jfreechart.pdf");
saveChartAsPDF(fileName, jfreechart, 400, 300, new DefaultFontMapper());
//sauvgarder le graph sur le client
String leNomDeFichier="d:\\temp\\jfreechart.pdf";
File file = new File(leNomDeFichier);
response.setContentType("unknown/unknown");
response.setHeader("Content-Disposition", "attachment; filename= \"" + leNomDeFichier + "\"+");
InputStream in = new FileInputStream(file);
ServletOutputStream out = response.getOutputStream();
try
{
int bit = in.read();
while( (bit) >= 0 )
{
out.write(bit);
bit = in.read();
}
}
catch (Throwable t)
{
}
out.flush();
out.close();
in.close();
return mapping.findForward("s");
} |
Partager