use of org.jfree.data.time.Minute in project dubbo by alibaba.
the class SimpleMonitorService method createChart.
private static void createChart(String key, String service, String method, String date, String[] types, Map<String, long[]> data, double[] summary, String path) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
DecimalFormat numberFormat = new DecimalFormat("###,##0.##");
TimeSeriesCollection xydataset = new TimeSeriesCollection();
for (int i = 0; i < types.length; i++) {
String type = types[i];
TimeSeries timeseries = new TimeSeries(type);
for (Map.Entry<String, long[]> entry : data.entrySet()) {
try {
timeseries.add(new Minute(dateFormat.parse(date + entry.getKey())), entry.getValue()[i]);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
}
xydataset.addSeries(timeseries);
}
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("max: " + numberFormat.format(summary[0]) + (summary[1] >= 0 ? " min: " + numberFormat.format(summary[1]) : "") + " avg: " + numberFormat.format(summary[2]) + (summary[3] >= 0 ? " sum: " + numberFormat.format(summary[3]) : ""), toDisplayService(service) + " " + method + " " + toDisplayDate(date), key, xydataset, true, true, false);
jfreechart.setBackgroundPaint(Color.WHITE);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinePaint(Color.GRAY);
xyplot.setRangeGridlinePaint(Color.GRAY);
xyplot.setDomainGridlinesVisible(true);
xyplot.setRangeGridlinesVisible(true);
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
BufferedImage image = jfreechart.createBufferedImage(600, 300);
try {
if (logger.isInfoEnabled()) {
logger.info("write chart: " + path);
}
File methodChartFile = new File(path);
File methodChartDir = methodChartFile.getParentFile();
if (methodChartDir != null && !methodChartDir.exists()) {
methodChartDir.mkdirs();
}
FileOutputStream output = new FileOutputStream(methodChartFile);
try {
ImageIO.write(image, "png", output);
output.flush();
} finally {
output.close();
}
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
Aggregations