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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
public void chart(OutputStream out, Object data)
throws IOException
{
if (dataset == null)
{
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)img.createGraphics();
g2.setBackground(Color.white);
g2.setColor(Color.white);
g2.fillRect(0, 0, 5, 5);
ImageIO.write(img,"png",out);
return;
}
String key = "reportanalyse_axisxdays";
if (unit.equals("unitday"))
key = "reportanalyse_axisxhours";
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"", // chart title
sessionBean.getString(key), // domain axis label
sessionBean.getString("reportanalyse_axisy"), // range axis label
dataset, // data
true, // include legend
false, // tooltips
false // urls
);
XYPlot xyplot = chart.getXYPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinesVisible(true);
xyplot.setDomainGridlinePaint(Color.GRAY);
xyplot.setDomainMinorGridlinesVisible(true);
xyplot.setDomainMinorGridlinePaint(Color.GRAY);
xyplot.setRangeGridlinesVisible(true);
xyplot.setRangeGridlinePaint(Color.GRAY);
xyplot.getRangeAxis().setAxisLinePaint(Color.white);
xyplot.getDomainAxis().setAxisLinePaint(Color.white);
XYLineAndShapeRenderer lasr = new XYLineAndShapeRenderer(true, true);
lasr.setSeriesPaint(0, Color.red);
lasr.setSeriesPaint(1, Color.blue);
lasr.setSeriesPaint(2, Color.green);
lasr.setSeriesPaint(3, Color.ORANGE);
//lasr.getBaseItemLabelGenerator().
xyplot.setRenderer(lasr);
DateAxis axis = (DateAxis)xyplot.getDomainAxis();
axis.setMinorTickMarksVisible(true);
if (period.equals(ReportBase.PERIOD_MONTH))
{
// axis.setMinimumDate(startDate.getTime());
axis.setMinorTickCount(7);
}
try
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(os, chart,700,300);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
BufferedImage img =ImageIO.read(is);
ImageIO.write(img,"png",out);
}
catch(Exception e)
{
e.printStackTrace();
}
} |
Partager