List of usage examples for org.jfree.chart.servlet ServletUtilities saveChartAsPNG
public static String saveChartAsPNG(JFreeChart chart, int width, int height, HttpSession session) throws IOException
From source file:org.tolven.web.ChartAction.java
/** * This function will return height chart. * //from w ww. j av a2s . c o m * @author Suja * added on 02/01/2011 * @return * @throws IOException */ public String getGrowthChartHeight() throws IOException { JFreeChart chart = createChart(1); String filename = ServletUtilities.saveChartAsPNG(chart, 1000, 700, null); graphURL = "my.graph?filename=" + URLEncoder.encode(filename, "UTF-8"); TolvenLogger.info("Graph URL: " + graphURL, MenuAction.class); return graphURL; }
From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java
/** * Lead pipeline. Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard * Note that this counts all the leads in the system for now. *///from www .j a va 2 s. co m public static String createLeadPipelineChart(Delegator delegator, Locale locale) throws GenericEntityException, IOException { Map uiLabelMap = UtilMessage.getUiLabels(locale); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // get all LEAD statuses that are not CONVERTED, or DEAD List<GenericValue> leadStatuses = ReportHelper.findLeadStatusesForDashboardReporting(delegator); // report number of leads for each status for (GenericValue status : leadStatuses) { String statusId = status.getString("statusId"); long count = delegator.findCountByCondition("PartyAndStatus", EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null); dataset.addValue(count, "", (String) status.get("description", locale)); } // set up the chart JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmLeadPipeline"), null, null, dataset, PlotOrientation.HORIZONTAL, false, true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // get the bar renderer to put effects on the bars final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // disable bar outlines // set up gradient paint on bar final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(227, 246, 206), 0.0f, 0.0f, new Color(153, 204, 102)); renderer.setSeriesPaint(0, gp); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, 360, 200, null); }
From source file:org.tolven.web.ChartAction.java
/** * This function will return weight chart. * /*from www . ja v a 2s .c om*/ * @author Suja * added on 02/01/2011 * @return * @throws IOException */ public String getGrowthChartWeight() throws IOException { JFreeChart chart = createChart(2); String filename = ServletUtilities.saveChartAsPNG(chart, 1000, 700, null); graphURL = "my.graph?filename=" + URLEncoder.encode(filename, "UTF-8"); TolvenLogger.info("Graph URL: " + graphURL, MenuAction.class); return graphURL; }
From source file:org.tolven.graph.GraphMenuEventHandler.java
public void displayGraph() throws Exception { JFreeChart chart = createChart();// w w w .ja va 2 s. c o m int width = 600; int height = 400; String filename = ServletUtilities.saveChartAsPNG(chart, width, height, getRequest().getSession()); String graphURL = "my.graph?filename=" + URLEncoder.encode(filename, "UTF-8"); StringBuffer sbuffer = new StringBuffer(); sbuffer.append("<html xmlns=\"http://www.w3.org/1999/xhtml\""); sbuffer.append("xmlns:ui=\"http://java.sun.com/jsf/facelets\""); sbuffer.append("xmlns:f=\"http://java.sun.com/jsf/core\""); sbuffer.append("xmlns:h=\"http://java.sun.com/jsf/html\""); sbuffer.append("xmlns:c=\"http://java.sun.com/jsp/jstl/core\">"); sbuffer.append("<img width=\"" + width + "\" height=\"" + height + "\" src=\"" + graphURL + "\"/>"); sbuffer.append("<input type=\"button\" value=\"Close\" onclick=\"closeGraphDiv();\" /> "); sbuffer.append("</html>"); getWriter().write(sbuffer.toString()); }
From source file:com.opensourcestrategies.financials.reports.JFreeFinancialCharts.java
/** * Liquidity snapshot chart. Documentation is at http://www.opentaps.org/docs/index.php/Financials_Home_Screen * * Because a user might not have permission to view balances in all areas, this method takes into consideration * the ability to view various bars in the chart. * * @param accountsMap Map of accounts keyed by the glAccountType * @return String filename pointing to the chart, to be used with showChart URI request *///from w w w . j a va2 s.c o m public static String createLiquiditySnapshotChart(Map<String, GenericValue> accountsMap, List<GenericValue> creditCardAccounts, Locale locale, boolean hasReceivablesPermission, boolean hasPayablesPermission, boolean hasInventoryPermission) throws GenericEntityException, IOException { Map<String, Object> uiLabelMap = UtilMessage.getUiLabels(locale); // create the dataset DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // compile the four bars if (hasReceivablesPermission) { double cashBalance = 0.0; cashBalance += getPostedBalance(accountsMap.get("UNDEPOSITED_RECEIPTS")); cashBalance += getPostedBalance(accountsMap.get("BANK_STLMNT_ACCOUNT")); dataset.addValue(cashBalance, "", (String) uiLabelMap.get("FinancialsCashEquivalents")); double receivablesBalance = 0.0; receivablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_RECEIVABLE")); // merchant account settlement balances are receivable receivablesBalance += getPostedBalance(accountsMap.get("MRCH_STLMNT_ACCOUNT")); dataset.addValue(receivablesBalance, "", (String) uiLabelMap.get("FinancialsReceivables")); } if (hasInventoryPermission) { double inventoryBalance = 0.0; inventoryBalance += getPostedBalance(accountsMap.get("INVENTORY_ACCOUNT")); inventoryBalance += getPostedBalance(accountsMap.get("RAWMAT_INVENTORY")); inventoryBalance += getPostedBalance(accountsMap.get("WIP_INVENTORY")); dataset.addValue(inventoryBalance, "", (String) uiLabelMap.get("WarehouseInventory")); } if (hasPayablesPermission) { double payablesBalance = 0.0; payablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_PAYABLE")); payablesBalance += getPostedBalance(accountsMap.get("COMMISSIONS_PAYABLE")); payablesBalance += getPostedBalance(accountsMap.get("UNINVOICED_SHIP_RCPT")); dataset.addValue(payablesBalance, "", (String) uiLabelMap.get("FinancialsPayables")); } // set up the chart JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("FinancialsLiquiditySnapshot"), // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // get the bar renderer to put effects on the bars final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // disable bar outlines // set up gradient paint on bar final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.GREEN, 0.0f, 0.0f, Color.GRAY); renderer.setSeriesPaint(0, gp); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // tilt the category labels so they fit CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, 400, 300, null); }
From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java
/** * Opportunities by stage. Description at * http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard * Note that this counts all the opportunities in the system for now. *//*w w w.j a v a 2s . c om*/ public static String createOpportunitiesbyStageChart(Delegator delegator, Locale locale) throws GenericEntityException, IOException { Map uiLabelMap = UtilMessage.getUiLabels(locale); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String currency = UtilConfig.getPropertyValue("crmsfa", "defaultCurrencyUomId"); // get all sales opportunity stages that are not closed, or lost List<GenericValue> salesOpportunityStages = ReportHelper .findSalesOpportunityStagesForDashboardReporting(delegator); // report number of leads for each status for (GenericValue stage : salesOpportunityStages) { String opportunityStageId = stage.getString("opportunityStageId"); EntityCondition conditions = EntityCondition.makeCondition(EntityOperator.AND, EntityCondition.makeCondition("opportunityStageId", EntityOperator.EQUALS, opportunityStageId), EntityCondition.makeCondition("currencyUomId", EntityOperator.EQUALS, currency)); List<GenericValue> salesOpportunityEstimatedAmountTotals = delegator .findByConditionCache("SalesOpportunityEstimatedAmountTotalByStage", conditions, null, null); if (salesOpportunityEstimatedAmountTotals != null && !salesOpportunityEstimatedAmountTotals.isEmpty()) { GenericValue salesOpportunityEstimatedAmountTotal = salesOpportunityEstimatedAmountTotals.get(0); dataset.addValue(salesOpportunityEstimatedAmountTotal.getDouble("estimatedAmountTotal"), "", (String) stage.get("description", locale)); } else { dataset.addValue(0, "", (String) stage.get("description", locale)); } } // set up the chart JFreeChart chart = ChartFactory.createBarChart( (String) UtilMessage.expandLabel("CrmOpportunitiesbyStage", locale, UtilMisc.toMap("currency", currency)), null, null, dataset, PlotOrientation.HORIZONTAL, false, true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // get the bar renderer to put effects on the bars final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // disable bar outlines // set up gradient paint on bar final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(206, 246, 245), 0.0f, 0.0f, new Color(51, 204, 204)); renderer.setSeriesPaint(0, gp); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, 360, 200, null); }
From source file:i2p.bote.web.PeerInfoTag.java
private String createDhtChart(DhtPeerStats dhtStats) throws IOException { RingPlot plot;/* w w w.j a va 2s.c om*/ int numDhtPeers = dhtStats.getData().size(); if (numDhtPeers == 0) { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("", 100); plot = new RingPlot(dataset); plot.setSectionPaint("", Color.gray); } else { int reachable = 0; for (List<String> row : dhtStats.getData()) { if (_t("No").equals(row.get(4))) reachable += 1; } int unreachable = numDhtPeers - reachable; DefaultPieDataset dataset = new DefaultPieDataset(); if (reachable > 0) dataset.setValue(_t("Reachable"), reachable); if (unreachable > 0) dataset.setValue(_t("Unreachable"), unreachable); plot = new RingPlot(dataset); plot.setSectionPaint(_t("Reachable"), Color.green); plot.setSectionPaint(_t("Unreachable"), Color.red); } plot.setLabelGenerator(null); plot.setShadowGenerator(null); JFreeChart dhtChart = new JFreeChart(_t("Kademlia Peers:"), JFreeChart.DEFAULT_TITLE_FONT, plot, numDhtPeers == 0 ? false : true); return ServletUtilities.saveChartAsPNG(dhtChart, 400, 300, null); }
From source file:i2p.bote.web.PeerInfoTag.java
private String createRelayChart(RelayPeer[] relayPeers) throws IOException { RingPlot plot;//from w w w.j av a2 s . com if (relayPeers.length == 0) { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("", 100); plot = new RingPlot(dataset); plot.setSectionPaint("", Color.gray); } else { int good = 0; int untested = 0; for (RelayPeer relayPeer : relayPeers) { int reachability = relayPeer.getReachability(); if (reachability == 0) untested += 1; else if (reachability > 80) good += 1; } int bad = relayPeers.length - good - untested; DefaultPieDataset dataset = new DefaultPieDataset(); if (good > 0) dataset.setValue(_t("Good"), good); if (bad > 0) dataset.setValue(_t("Unreliable"), bad); if (untested > 0) dataset.setValue(_t("Untested"), untested); plot = new RingPlot(dataset); plot.setSectionPaint(_t("Good"), Color.green); plot.setSectionPaint(_t("Unreliable"), Color.red); plot.setSectionPaint(_t("Untested"), Color.orange); } plot.setLabelGenerator(null); plot.setShadowGenerator(null); JFreeChart chart = new JFreeChart(_t("Relay Peers:"), JFreeChart.DEFAULT_TITLE_FONT, plot, relayPeers.length == 0 ? false : true); return ServletUtilities.saveChartAsPNG(chart, 400, 300, null); }
From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java
/** * Open Cases snapshot. Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard * Note that this counts all the cases in the system for now. */// w w w . j av a 2 s .c o m public static String createOpenCasesChart(Delegator delegator, Locale locale) throws GenericEntityException, IOException { Map uiLabelMap = UtilMessage.getUiLabels(locale); // create the dataset DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // get all case statuses that are not "closed" (this is dynamic because statuses may be added at run time) List<GenericValue> statuses = ReportHelper.findCasesStagesForDashboardReporting(delegator); // Report number of cases for each status for (GenericValue status : statuses) { String statusId = status.getString("statusId"); long count = delegator.findCountByCondition("CustRequest", EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null); dataset.addValue(count, "", (String) status.get("description", locale)); } // set up the chart JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmOpenCases"), // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // get the bar renderer to put effects on the bars final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // disable bar outlines // set up gradient paint on bar final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(246, 227, 206), 0.0f, 0.0f, new Color(204, 153, 102)); renderer.setSeriesPaint(0, gp); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // tilt the category labels so they fit CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, 360, 300, null); }
From source file:com.opensourcestrategies.activities.reports.ActivitiesChartsService.java
private String createPieChart(DefaultPieDataset dataset, String title) throws InfrastructureException, IOException { Debug.logInfo("Charting dashboard [" + title + "]", MODULE); // set up the chart JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, // include legend true, // tooltips false // urls );//from ww w . j av a2s . c o m chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customization... final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1} / {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); Color[] colors = { Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NEW_COLOR)), Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_OLD_COLOR)), Color.decode("#" + infrastructure.getConfigurationValue( OpentapsConfigurationTypeConstants.ACTIVITIES_DASHBOARD_LEADS_NO_ACTIVITY_COLOR)) }; for (int i = 0; i < dataset.getItemCount(); i++) { Comparable<?> key = dataset.getKey(i); plot.setSectionPaint(key, colors[i]); } // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, chartWidth, chartHeight, null); }