List of usage examples for org.jfree.chart ChartUtilities writeChartAsPNG
public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height) throws IOException
From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java
/** * Write p-value histogram thumbnail image. *//*from ww w. jav a 2 s. c o m*/ private boolean writePValueHistThumbnailImage(OutputStream os, ExpressionExperiment ee, Long analysisId, Long rsId, String factorName, int size) throws IOException { XYSeries series = this.getDiffExPvalueHistXYSeries(ee, analysisId, rsId, factorName); if (series == null) { return false; } series.add(-0.01, 0.0); XYSeriesCollection xySeriesCollection = new XYSeriesCollection(series); ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart chart = ChartFactory.createXYLineChart("", "", "", xySeriesCollection, PlotOrientation.VERTICAL, false, false, false); chart.getXYPlot().setBackgroundPaint(new Color(230, 230, 230)); chart.getXYPlot().setRangeGridlinesVisible(false); chart.getXYPlot().setDomainGridlinesVisible(false); chart.getXYPlot().setOutlineVisible(false); // around the plot chart.getXYPlot().getRangeAxis().setTickMarksVisible(false); chart.getXYPlot().getRangeAxis().setTickLabelsVisible(false); chart.getXYPlot().getRangeAxis().setAxisLineVisible(false); chart.getXYPlot().getDomainAxis().setTickMarksVisible(false); chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false); chart.getXYPlot().getDomainAxis().setAxisLineVisible(false); chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.RED); // chart.getXYPlot().getRenderer().setSeriesStroke( 0, new BasicStroke( 1 ) ); // Make the chart a bit bigger to account for the empty space around the generated image. // If we can find a way to remove this empty space, we don't need to make the chart bigger. ChartUtilities.writeChartAsPNG(os, chart, size + 16, size + 9); return true; }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport() { if (impReport.getTable() == null) { fileName = null;// w w w .j av a 2s. c o m return; } if (impReport.getColWidth().length != impReport.getTableHead().length) { SysLogger.error("colWidth[].length != tableHead[].length"); return; } WritableWorkbook wb = null; try { fileName = ResourceCenter.getInstance().getSysPath() + "temp/dhcnms_report.xls"; // fileName = CommonAppUtil.getAppName() + // "/temp/dhcnms_report.xls"; wb = Workbook.createWorkbook(new File(fileName)); WritableSheet sheet = wb.createSheet("", 0); WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD, false); WritableCellFormat labelFormat = new WritableCellFormat(labelFont); Label tmpLabel = null; tmpLabel = new Label(1, 0, impReport.getHead(), labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp()); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, impReport.getNote()); sheet.addCell(tmpLabel); int row = impReport.getTable().length; int col = impReport.getTableHead().length; for (int i = 0; i < col; i++) { Label label = new Label(i, 3, impReport.getTableHead()[i], labelFormat); sheet.addCell(label); } for (int i = 0; i < row; i++) for (int j = 0; j < col; j++) { Label label = new Label(j, i + 4, impReport.getTable()[i][j]); sheet.addCell(label); } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } WritableImage wi = new WritableImage(2, row + 5, 8, 12, baos.toByteArray()); sheet.addImage(wi); } wb.write(); } catch (Exception e) { SysLogger.error("Error in ExcelReport.createReport()", e); } finally { try { if (wb != null) wb.close(); } catch (Exception e) { SysLogger.error("", e); } } }
From source file:fmiquerytest.Coordinates.java
static String drawTempRainChart(List<stepWeather> stepDataBase, Map routeWeather) { //First, fetch the real data List<Double> times = new ArrayList<>(); List<Double> temps = new ArrayList<>(); List<Double> rains = new ArrayList<>(); List<Double> lights = new ArrayList<>(); for (int i = 0; i < stepDataBase.size(); ++i) { stepWeather step = stepDataBase.get(i); stepWeather nextstep = step;/*from w w w . jav a 2 s . co m*/ if (i < stepDataBase.size() - 1) { nextstep = stepDataBase.get(i + 1); } times.add(step.timeAsDouble); temps.add(getParameterAverage(routeWeather, step, nextstep, "Temperature")); rains.add(getParameterAverage(routeWeather, step, nextstep, "Precipitation1h")); lights.add(Math.pow(Math.abs(step.timeAsDouble % 24 - ((step.sunRise + step.sunSet) / 2)) / ((step.sunSet - step.sunRise) / 2), 5)); } double zeroPoint = times.get(0); // Make first dataset final TimeSeriesCollection dataset = new TimeSeriesCollection(); final TimeSeries s1 = new TimeSeries("Temperature C", Minute.class); // Make second dataset final TimeSeriesCollection dataset2 = new TimeSeriesCollection(); final TimeSeries s2 = new TimeSeries("Rain (mm)", Minute.class); // Make third dataset //final TimeSeriesCollection dataset3 = new TimeSeriesCollection(); final TimeSeries s3 = new TimeSeries("Darkness", Minute.class); // Show data per minute RegularTimePeriod start = new Minute(new Date(FmiQueryTest.startTimeMillis)); for (int i = 0; i < times.size() - 1; ++i) { double time = times.get(i); double nexttime = times.get(i + 1); int firstMinute = intValue((time - zeroPoint) * 60); int currentMinute = firstMinute; int lastMinute = intValue((nexttime - zeroPoint) * 60); while (currentMinute < lastMinute) { s1.add(start, temps.get(i) + ((double) currentMinute - firstMinute) / (lastMinute - firstMinute) * (temps.get(i + 1) - temps.get(i))); s2.add(start, (rains.get(i) + rains.get(i + 1)) / 2); //+((double)currentMinute-firstMinute)/(lastMinute-firstMinute)*(rains.get(i+1)-rains.get(i))); s3.add(start, lights.get(i) + ((double) currentMinute - firstMinute) / (lastMinute - firstMinute) * (lights.get(i + 1) - lights.get(i))); ++currentMinute; start = start.next(); } } dataset.addSeries(s1); dataset2.addSeries(s3); dataset2.addSeries(s2); // Initialize chart final JFreeChart chart = ChartFactory.createTimeSeriesChart("Temperature and rain", "Time", "Temperature C", dataset, true, // legend? true, // tooltips? false // URLs? ); final XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); // configure the range axis to display first dataset... final ValueAxis rangeAxis = (ValueAxis) plot.getRangeAxis(); rangeAxis.setRange(-30, 30); final TickUnits units = new TickUnits(); units.add(new NumberTickUnit(10.0)); units.add(new NumberTickUnit(1.0)); units.add(new NumberTickUnit(0.1)); rangeAxis.setStandardTickUnits(units); //rangeAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 16)); // add the secondary dataset/renderer/axis plot.setRangeAxis(rangeAxis); final XYItemRenderer renderer2 = new XYAreaRenderer(); final ValueAxis axis2 = new NumberAxis("Rain (mm) "); axis2.setRange(0, 2); axis2.setStandardTickUnits(units); //axis2.setTickLabelFont(new Font("SansSerif", Font.BOLD, 16)); renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128)); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setRangeAxis(1, axis2); plot.mapDatasetToRangeAxis(1, 1); final XYItemRenderer renderer3 = new XYAreaRenderer(); renderer3.setSeriesPaint(0, new Color(0, 0, 0, 64)); //plot.setDataset(1, dataset2); plot.setRenderer(1, renderer3); plot.setRangeAxis(1, axis2); plot.mapDatasetToRangeAxis(1, 1); chart.setBackgroundPaint(Color.white); //plot.setBackgroundPaint(Color.lightGray); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); // final TextTitle subtitle = new TextTitle("An area chart demonstration. We use this " // + "subtitle as an example of what happens when you get a really long title or " // + "subtitle."); // subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); // subtitle.setPosition(RectangleEdge.TOP); //// subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05)); // subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); // chart.addSubtitle(subtitle); // Produce chart // ChartFrame frame = new ChartFrame("Tamperature and rain", chart); // frame.pack(); // RefineryUtilities.centerFrameOnScreen(frame); // frame.setVisible(true); ByteArrayOutputStream bas = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(bas, chart, 600, 400); } catch (IOException ex) { Logger.getLogger(WeatherTools.class.getName()).log(Level.SEVERE, null, ex); } byte[] byteArray = bas.toByteArray(); String baseCode = Base64.encode(byteArray); return "<img width=\"480\" alt=\"Temperature and rain\" src=\"data:image/png;base64," + baseCode.trim() + "\" />"; }
From source file:edu.ku.brc.specify.web.SpecifyExplorer.java
/** * @param response/* w w w . j a va 2 s .c o m*/ * @param type * @param alphaList * @param title * @param xTitle * @param yTitle */ protected void createChart(final HttpServletResponse response, final String type, final Vector<NameId> alphaList, final String title, final String xTitle, final String yTitle) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (NameId nis : alphaList) { dataset.addValue(nis.getId(), nis.getName(), ""); } JFreeChart chart = null; if (StringUtils.isEmpty(type) || type.equals("bar")) { chart = ChartFactory.createBarChart(title, xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, true, false); } else if (type.equals("line")) { chart = ChartFactory.createLineChart(title, xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, true, false); } //chart.getCategoryPlot().setRenderer(new CustomColorBarChartRenderer()); chart.setBackgroundPaint(new Color(228, 243, 255)); response.setContentType("image/png"); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 700, 600); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createExcelReport_disk(String filename) { if (impReport.getTable() == null) { fileName = null;//from w w w . j a v a2s . c o m return; } WritableWorkbook wb = null; try { // fileName = ResourceCenter.getInstance().getSysPath() + // "temp\\dhcnms_report.xls"; // fileName = CommonAppUtil.getAppName() + // "/temp/hostnms_report.xls"; fileName = ResourceCenter.getInstance().getSysPath() + filename; wb = Workbook.createWorkbook(new File(fileName)); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); String hostname = (String) reportHash.get("equipname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip); WritableSheet sheet = wb.createSheet(hostname + "", 0); Hashtable CPU = (Hashtable) reportHash.get("CPU"); if (CPU == null) CPU = new Hashtable(); String Ping = (String) reportHash.get("Ping"); // Calendar colTime = (Calendar) reportHash.get("time"); // Date cc = colTime.getTime(); Hashtable Memory = (Hashtable) reportHash.get("Memory"); Hashtable Disk = (Hashtable) reportHash.get("Disk"); Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash"); Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String[] memoryItemch = { "", "", "", "" }; String[] memoryItem = { "Capability", "Utilization" }; String[] diskItem = { "AllSize", "UsedSize", "Utilization" }; String[] diskItemch = { "", "", "" }; WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD, false); WritableCellFormat labelFormat = new WritableCellFormat(labelFont); WritableCellFormat _labelFormat = new WritableCellFormat(); _labelFormat.setBackground(jxl.format.Colour.GRAY_25); WritableCellFormat p_labelFormat = new WritableCellFormat(); p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE); WritableCellFormat b_labelFormat = new WritableCellFormat(); b_labelFormat.setBackground(jxl.format.Colour.GRAY_50); Label tmpLabel = null; tmpLabel = new Label(1, 0, hostname + "", labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp()); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " + starttime + " " + totime); sheet.addCell(tmpLabel); // File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); // sheet,0,0,5,1,,, // allRow = allRow+2; // sheet.addImage(new WritableImage(1, 6, 7, 7, file)); // allRow = allRow+7; int allRow = 4; if (Disk != null && Disk.size() > 0) { // memoryRow = Disk.size(); // allRow = allRow + 1 + 7; tmpLabel = new Label(0, allRow, "", b_labelFormat); sheet.addCell(tmpLabel); // allRow = allRow; Label label = new Label(1, allRow, "", _labelFormat); // CellFormat cf = new CellFormat(); // label.setCellFormat(cf) sheet.addCell(label); for (int i = 0; i < diskItemch.length; i++) { label = new Label(i + 2, allRow, diskItemch[i], _labelFormat); sheet.addCell(label); } // for (int i = 0; i < Disk.size(); i++) { Hashtable diskhash = (Hashtable) (Disk.get(new Integer(i))); String name = (String) diskhash.get("name"); allRow = allRow + 1; label = new Label(1, allRow, name); sheet.addCell(label); for (int j = 0; j < diskItem.length; j++) { String value = ""; if (diskhash.get(diskItem[j]) != null) { value = (String) diskhash.get(diskItem[j]); } label = new Label(j + 2, allRow, value, p_labelFormat); sheet.addCell(label); } } // end // file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "disk" + ".png"); // sheet,0,0,5,1,,, sheet.addImage(new WritableImage(1, allRow + 2, 9, 9, file)); } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray()); sheet.addImage(wi); } wb.write(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } finally { try { if (wb != null) wb.close(); } catch (Exception e) { } } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_hostWithoutClose(String filename, WritableWorkbook wb) { if (impReport.getTable() == null) { fileName = null;/*from w ww .j a v a2 s .c o m*/ return; } try { // fileName = ResourceCenter.getInstance().getSysPath() + // "temp\\dhcnms_report.xls"; // fileName = CommonAppUtil.getAppName() + // "/temp/hostnms_report.xls"; fileName = ResourceCenter.getInstance().getSysPath() + filename; // wb = Workbook.createWorkbook(new File(fileName)); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); String hostname = (String) reportHash.get("equipname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip); WritableSheet sheet = wb.createSheet(hostname + "", 0); Hashtable CPU = (Hashtable) reportHash.get("CPU"); if (CPU == null) CPU = new Hashtable(); String Ping = (String) reportHash.get("Ping"); Calendar colTime = (Calendar) reportHash.get("time"); Date cc = colTime.getTime(); Hashtable Memory = (Hashtable) reportHash.get("Memory"); Hashtable Disk = (Hashtable) reportHash.get("Disk"); Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash"); Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String[] memoryItemch = { "", "", "", "" }; String[] memoryItem = { "Capability", "Utilization" }; String[] diskItem = { "AllSize", "UsedSize", "Utilization" }; String[] diskItemch = { "", "", "" }; WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD, false); WritableCellFormat labelFormat = new WritableCellFormat(labelFont); WritableCellFormat _labelFormat = new WritableCellFormat(); _labelFormat.setBackground(jxl.format.Colour.GRAY_25); WritableCellFormat p_labelFormat = new WritableCellFormat(); p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE); WritableCellFormat b_labelFormat = new WritableCellFormat(); b_labelFormat.setBackground(jxl.format.Colour.GRAY_50); Label tmpLabel = null; tmpLabel = new Label(1, 0, hostname + "", labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp()); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " + starttime + " " + totime); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 4, "", b_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 5, Ping + "%", p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 5, (String) maxping.get("pingmax"), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 5, (String) maxping.get("avgpingcon"), p_labelFormat); sheet.addCell(tmpLabel); // File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); // sheet,0,0,5,1,,, // allRow = allRow+2; sheet.addImage(new WritableImage(1, 6, 7, 7, file)); // allRow = allRow+7; String cpu = ""; if (CPU.get("cpu") != null) cpu = (String) CPU.get("cpu"); String cpumax = ""; if (CPU.get("cpumax") != null) cpumax = (String) CPU.get("cpumax"); String avgcpu = ""; if (CPU.get("avgcpu") != null) avgcpu = (String) CPU.get("avgcpu"); tmpLabel = new Label(0, 14, "CPU", b_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 14, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 14, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 14, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 15, cpu + "%", p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 15, cpumax, p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 15, avgcpu, p_labelFormat); sheet.addCell(tmpLabel); int allRow = 15; // file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png"); // sheet,0,0,5,1,,, allRow = allRow + 2; sheet.addImage(new WritableImage(1, allRow, 7, 7, file)); allRow = allRow + 6; if (Memory != null && Memory.size() > 0) { allRow = allRow + 2; tmpLabel = new Label(0, allRow, "", b_labelFormat); sheet.addCell(tmpLabel); // allRow = allRow; Label label = new Label(1, allRow, "", _labelFormat); sheet.addCell(label); for (int i = 0; i < memoryItemch.length; i++) { label = new Label(i + 2, allRow, memoryItemch[i], _labelFormat); sheet.addCell(label); } // for (int i = 0; i < Memory.size(); i++) { Hashtable mhash = (Hashtable) (Memory.get(new Integer(i))); String name = (String) mhash.get("name"); allRow = allRow + 1; label = new Label(1, allRow, name); sheet.addCell(label); for (int j = 0; j < memoryItem.length; j++) { String value = ""; if (mhash.get(memoryItem[j]) != null) { value = (String) mhash.get(memoryItem[j]); } label = new Label(j + 2, allRow, value, p_labelFormat); sheet.addCell(label); } String value = ""; if (memMaxHash.get(name) != null) { value = (String) memMaxHash.get(name); label = new Label(memoryItem.length + 2, allRow, value, p_labelFormat); sheet.addCell(label); } String avgvalue = ""; if (memAvgHash.get(name) != null) { avgvalue = (String) memAvgHash.get(name); label = new Label(memoryItem.length + 3, allRow, avgvalue, p_labelFormat); sheet.addCell(label); } } // end // file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "memory" + ".png"); // sheet,0,0,5,1,,, allRow = allRow + 2; sheet.addImage(new WritableImage(1, allRow, 7, 7, file)); } else { allRow = allRow + 2; tmpLabel = new Label(0, allRow, "", b_labelFormat); sheet.addCell(tmpLabel); // allRow = allRow; Label label = new Label(1, allRow, "", _labelFormat); sheet.addCell(label); for (int i = 0; i < memoryItemch.length; i++) { label = new Label(i + 2, allRow, memoryItemch[i], _labelFormat); sheet.addCell(label); } // String[] names = null; HostNodeDao dao = new HostNodeDao(); HostNode node = (HostNode) dao.findByCondition("ip_address", ip).get(0); // Monitoriplist monitor = monitorManager.getByIpaddress(ip); if (node.getSysOid().startsWith("1.3.6.1.4.1.311")) { names = new String[] { "PhysicalMemory", "VirtualMemory" }; } else { names = new String[] { "PhysicalMemory", "SwapMemory" }; } for (int i = 0; i < names.length; i++) { // Hashtable mhash = (Hashtable)(Memory.get(new // Integer(i))); String name = names[i]; // String[] unixs = {"PhysicalMemory","VirtualMemory"}; allRow = allRow + 1; label = new Label(1, allRow, names[i]); sheet.addCell(label); for (int j = 0; j < memoryItem.length; j++) { // String value = ""; label = new Label(j + 2, allRow, value, p_labelFormat); sheet.addCell(label); } String value = ""; if (memMaxHash.get(name) != null) { value = (String) memMaxHash.get(name); label = new Label(memoryItem.length + 2, allRow, value, p_labelFormat); sheet.addCell(label); } else { label = new Label(memoryItem.length + 2, allRow, value, p_labelFormat); sheet.addCell(label); } String avgvalue = ""; if (memAvgHash.get(name) != null) { avgvalue = (String) memAvgHash.get(name); label = new Label(memoryItem.length + 3, allRow, avgvalue, p_labelFormat); sheet.addCell(label); } else { label = new Label(memoryItem.length + 3, allRow, avgvalue, p_labelFormat); sheet.addCell(label); } } // end // file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "memory" + ".png"); // sheet,0,0,5,1,,, allRow = allRow + 2; sheet.addImage(new WritableImage(1, allRow, 7, 7, file)); } if (Disk != null && Disk.size() > 0) { // memoryRow = Disk.size(); allRow = allRow + 1 + 7; tmpLabel = new Label(0, allRow, "", b_labelFormat); sheet.addCell(tmpLabel); // allRow = allRow; Label label = new Label(1, allRow, "", _labelFormat); // CellFormat cf = new CellFormat(); // label.setCellFormat(cf) sheet.addCell(label); for (int i = 0; i < diskItemch.length; i++) { label = new Label(i + 2, allRow, diskItemch[i], _labelFormat); sheet.addCell(label); } // for (int i = 0; i < Disk.size(); i++) { Hashtable diskhash = (Hashtable) (Disk.get(new Integer(i))); String name = (String) diskhash.get("name"); allRow = allRow + 1; label = new Label(1, allRow, name); sheet.addCell(label); for (int j = 0; j < diskItem.length; j++) { String value = ""; if (diskhash.get(diskItem[j]) != null) { value = (String) diskhash.get(diskItem[j]); } label = new Label(j + 2, allRow, value, p_labelFormat); sheet.addCell(label); } } // end // file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "disk" + ".png"); // sheet,0,0,5,1,,, sheet.addImage(new WritableImage(1, allRow + 2, 9, 9, file)); } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray()); sheet.addImage(wi); } // wb.write(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } /* * finally { try { if (wb != null) wb.close(); } catch (Exception e) { } } */ }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_host(String filename) { if (impReport.getTable() == null) { fileName = null;//from w w w. j a v a 2 s . c o m return; } WritableWorkbook wb = null; try { String hostname = (String) reportHash.get("equipname"); String ip = (String) reportHash.get("ip"); fileName = ResourceCenter.getInstance().getSysPath() + filename; wb = Workbook.createWorkbook(new File(fileName)); WritableSheet sheet = wb.createSheet(hostname + "", 0); createReportTitle(sheet, reportHash); createPingAndCpu(sheet, ip, reportHash); createMemory(sheet, ip, reportHash); createDisk(sheet, ip, reportHash); if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { SysLogger.error("", ioe); } WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray()); sheet.addImage(wi); } wb.write(); } catch (Exception e) { SysLogger.error("", e); } finally { try { if (wb != null) wb.close(); } catch (Exception e) { SysLogger.error("", e); } } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_hostevent(String filename) { if (impReport.getTable() == null) { fileName = null;/* w w w.ja v a2 s .c o m*/ return; } WritableWorkbook wb = null; try { fileName = ResourceCenter.getInstance().getSysPath() + filename; wb = Workbook.createWorkbook(new File(fileName)); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); WritableSheet sheet = wb.createSheet("", 0); List memlist = (List) reportHash.get("eventlist"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // WritableFont labelFont = new // WritableFont(WritableFont.createFont(""), 12, // WritableFont.BOLD, false); // WritableCellFormat labelFormat = new // WritableCellFormat(labelFont); // // WritableCellFormat _labelFormat = new WritableCellFormat(); // _labelFormat.setBackground(jxl.format.Colour.GRAY_25); // // WritableCellFormat p_labelFormat = new WritableCellFormat(); // p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE); // // WritableCellFormat b_labelFormat = new WritableCellFormat(); // b_labelFormat.setBackground(jxl.format.Colour.GRAY_50); Label tmpLabel = null; tmpLabel = new Label(0, 0, "", labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp(), labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " + starttime + " " + totime, labelFormat); sheet.addCell(tmpLabel); sheet.mergeCells(0, 0, 11, 0); sheet.mergeCells(0, 1, 11, 1); sheet.mergeCells(0, 2, 11, 2); tmpLabel = new Label(0, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 4, "IP", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(4, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(5, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(6, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(7, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(8, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(9, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(10, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(11, 4, "CPU", _labelFormat); sheet.addCell(tmpLabel); // I_MonitorIpList monitorManager=new MonitoriplistManager(); int row = 5; if (memlist != null && memlist.size() > 0) { for (int i = 0; i < memlist.size(); i++) { p_labelFormat = super.colorChange(i); List mlist = (List) memlist.get(i); row = row + (i); tmpLabel = new Label(0, 5 + i, i + 1 + "", p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 5 + i, (String) mlist.get(0), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 5 + i, (String) mlist.get(1), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 5 + i, (String) mlist.get(2), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(4, 5 + i, (String) mlist.get(3), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(5, 5 + i, (String) mlist.get(4), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(6, 5 + i, (String) mlist.get(5), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(7, 5 + i, (String) mlist.get(6), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(8, 5 + i, (String) mlist.get(7), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(9, 5 + i, (String) mlist.get(8), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(10, 5 + i, (String) mlist.get(9), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(11, 5 + i, (String) mlist.get(10), p_labelFormat); sheet.addCell(tmpLabel); } } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray()); sheet.addImage(wi); } wb.write(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } finally { try { if (wb != null) wb.close(); } catch (Exception e) { } } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_netlocationevent(String filename) { if (impReport.getTable() == null) { fileName = null;/*w ww . j a va2 s .co m*/ return; } WritableWorkbook wb = null; try { fileName = ResourceCenter.getInstance().getSysPath() + filename; wb = Workbook.createWorkbook(new File(fileName)); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); WritableSheet sheet = wb.createSheet("", 0); List memlist = (List) reportHash.get("eventlist"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD, false); WritableCellFormat labelFormat = new WritableCellFormat(labelFont); WritableCellFormat _labelFormat = new WritableCellFormat(); _labelFormat.setBackground(jxl.format.Colour.GRAY_25); WritableCellFormat p_labelFormat = new WritableCellFormat(); p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE); WritableCellFormat b_labelFormat = new WritableCellFormat(); b_labelFormat.setBackground(jxl.format.Colour.GRAY_50); Label tmpLabel = null; tmpLabel = new Label(1, 0, "", labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp()); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " + starttime + " " + totime); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(4, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(5, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(6, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(7, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(8, 4, "", _labelFormat); sheet.addCell(tmpLabel); // I_MonitorIpList monitorManager=new MonitoriplistManager(); int row = 5; if (memlist != null && memlist.size() > 0) { for (int i = 0; i < memlist.size(); i++) { List mlist = (List) memlist.get(i); row = row + (i); tmpLabel = new Label(0, 5 + i, i + 1 + "", p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 5 + i, (String) mlist.get(0), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 5 + i, (String) mlist.get(1), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 5 + i, (String) mlist.get(2), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(4, 5 + i, (String) mlist.get(3), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(5, 5 + i, (String) mlist.get(4), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(6, 5 + i, (String) mlist.get(5), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(7, 5 + i, (String) mlist.get(6), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(8, 5 + i, (String) mlist.get(7), p_labelFormat); sheet.addCell(tmpLabel); } } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray()); sheet.addImage(wi); } wb.write(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } finally { try { if (wb != null) wb.close(); } catch (Exception e) { } } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_operatorevent(String filename) { if (impReport.getTable() == null) { fileName = null;// w ww. j a va 2 s. c om return; } WritableWorkbook wb = null; try { fileName = ResourceCenter.getInstance().getSysPath() + filename; wb = Workbook.createWorkbook(new File(fileName)); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); WritableSheet sheet = wb.createSheet("", 0); List memlist = (List) reportHash.get("eventlist"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD, false); WritableCellFormat labelFormat = new WritableCellFormat(labelFont); WritableCellFormat _labelFormat = new WritableCellFormat(); _labelFormat.setBackground(jxl.format.Colour.GRAY_25); WritableCellFormat p_labelFormat = new WritableCellFormat(); p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE); WritableCellFormat b_labelFormat = new WritableCellFormat(); b_labelFormat.setBackground(jxl.format.Colour.GRAY_50); Label tmpLabel = null; tmpLabel = new Label(1, 0, "", labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp()); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " + starttime + " " + totime); sheet.addCell(tmpLabel); tmpLabel = new Label(0, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(4, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(5, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(6, 4, "", _labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(7, 4, "", _labelFormat); sheet.addCell(tmpLabel); // I_MonitorIpList monitorManager=new MonitoriplistManager(); int row = 5; if (memlist != null && memlist.size() > 0) { for (int i = 0; i < memlist.size(); i++) { List mlist = (List) memlist.get(i); row = row + (i); tmpLabel = new Label(0, 5 + i, i + 1 + "", p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(1, 5 + i, (String) mlist.get(0), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(2, 5 + i, (String) mlist.get(1), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(3, 5 + i, (String) mlist.get(2), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(4, 5 + i, (String) mlist.get(3), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(5, 5 + i, (String) mlist.get(4), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(6, 5 + i, (String) mlist.get(5), p_labelFormat); sheet.addCell(tmpLabel); tmpLabel = new Label(7, 5 + i, (String) mlist.get(6), p_labelFormat); sheet.addCell(tmpLabel); } } if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray()); sheet.addImage(wi); } wb.write(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } finally { try { if (wb != null) wb.close(); } catch (Exception e) { } } }