List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
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. */// ww w .j av a 2s . c o 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:com.athena.chameleon.engine.utils.PDFWriterUtil.java
/** * /*from w ww . j a v a 2 s . co m*/ * chart * * @param section chart section ? * @param e chart element * @throws Exception */ public static void setChart(PdfWriter writer, Section section, Element e) throws Exception { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Element e1 : e.getChildren()) { if (!e1.getChild("column").getText().equals(FileType.DIRECTORY.toString()) && !e1.getChild("column").getText().equals(FileType.SUM.toString())) { dataset.setValue(Integer.parseInt(e1.getChild("value").getText()), e.getAttributeValue("title"), e1.getChild("column").getText()); } } JFreeChart chart = ChartFactory.createBarChart3D(e.getAttributeValue("title"), "", "", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); java.awt.Font labelFont = chart.getCategoryPlot().getDomainAxis().getLabelFont(); plot.getDomainAxis().setLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6)); plot.getDomainAxis().setTickLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6)); PdfContentByte cb = writer.getDirectContent(); PdfTemplate bar = cb.createTemplate(500, 150); Graphics2D g2d2 = new PdfGraphics2D(bar, 500, 150); Rectangle2D r2d2 = new Rectangle2D.Double(0, 0, 500, 150); chart.draw(g2d2, r2d2); g2d2.dispose(); Image image = Image.getInstance(bar); image.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); section.add(image); }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * DOC bZhou Comment method "decorateCategoryPlot". * /*from w w w . j a v a 2 s . c om*/ * @param chart */ public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) { CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer render = plot.getRenderer(); CategoryAxis domainAxis = plot.getDomainAxis(); // ADD msjian TDQ-5111 2012-4-9: set something look it well domainAxis.setCategoryMargin(0.1); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); domainAxis.setCategoryLabelPositionOffset(10); // TDQ-5111~ ValueAxis valueAxis = plot.getRangeAxis(); Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$ render.setBaseItemLabelFont(font); // MOD zshen 10998: change the font name 2010-01-16 font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setLabelFont(font); font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ valueAxis.setLabelFont(font); font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setTickLabelFont(font); valueAxis.setTickLabelFont(font); setLegendFont(chart); font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$ TextTitle title = chart.getTitle(); if (title != null) { title.setFont(font); } font = null; if (render instanceof BarRenderer) { CategoryDataset dataset = chart.getCategoryPlot().getDataset(); if (dataset != null) { int rowCount = dataset.getRowCount(); List<?> columnKeys = dataset.getColumnKeys(); if (!isContainCJKCharacter(columnKeys.toArray())) { domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));//$NON-NLS-1$ } ((BarRenderer) render).setItemMargin(-0.40 * rowCount); // TDQ-12621 add Tooltip for Lable for (Object colKey : columnKeys) { domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString()); } } domainAxis.setUpperMargin(0.1); // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..." domainAxis.setMaximumCategoryLabelLines(1); // ADD msjian TDQ-5111 2012-4-9: set Bar Width and let it look well // not do this when the bar is horizontal Orientation if (orientation == null) { ((BarRenderer) render).setMaximumBarWidth(0.2); } // TDQ-5111~ } // ~10998 }
From source file:j2se.jfreechart.barchart.BarChartDemo1.java
/** * Creates a sample chart./*w w w . j a v a 2 s . co m*/ * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
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 . ja v a 2 s.c om 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:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private static Image createExtensionsChartImage(List<CdrGraphBean> extensions, String xAxisLabel, String yAxisLabel) {//from w ww .j av a2 s . c o m // Create a dataset... DefaultCategoryDataset data = new DefaultCategoryDataset(); // Fill dataset with beans data for (CdrGraphBean extension : extensions) { data.setValue(extension.getCount(), extension.getKey(), extension.getKey()); } // Create a chart with the dataset JFreeChart barChart = ChartFactory.createBarChart3D(EMPTY_TITLE, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, true, true, true); barChart.setBackgroundPaint(Color.lightGray); barChart.getTitle().setPaint(Color.BLACK); CategoryPlot p = barChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.red); // Create and return the image with the size specified in the XML design return barChart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private static Image createMinutesOutgoingCallsChartImage(List<CdrMinutesGraphBean> minutesOutgoingCalls, String xAxisLabel, String yAxisLabel) { // Create a dataset... DefaultCategoryDataset data = new DefaultCategoryDataset(); // Fill dataset with beans data for (CdrMinutesGraphBean minutesOutgoingCall : minutesOutgoingCalls) { data.setValue(minutesOutgoingCall.getMinutes() / 60000, minutesOutgoingCall.getExtension(), minutesOutgoingCall.getExtension()); }//from www . jav a 2 s .c om // Create a chart with the dataset JFreeChart barChart = ChartFactory.createBarChart3D(EMPTY_TITLE, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, true, true, true); barChart.setBackgroundPaint(Color.lightGray); barChart.getTitle().setPaint(Color.BLACK); CategoryPlot p = barChart.getCategoryPlot(); p.setRangeGridlinePaint(Color.red); // Create and return the image with the size specified in the XML design return barChart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * Decorate the benford law chart. in this method the line chart will be overlay on top of bar chart. * // www . j av a 2 s . c o m * @param dataset * @param barChart * @param title * @param categoryAxisLabel * @param dotChartLabels * @param formalValues * @return JFreeChart */ @SuppressWarnings("deprecation") public static JFreeChart decorateBenfordLawChartByKCD(CategoryDataset dataset, Object customerDataset, JFreeChart barChart, String title, String categoryAxisLabel, List<String> dotChartLabels, double[] formalValues) { CategoryPlot barplot = barChart.getCategoryPlot(); decorateBarChart(barChart, new BenfordLawLineAndShapeRenderer()); // display percentage on top of the bar DecimalFormat df = new DecimalFormat(PERCENT_FORMAT); barplot.getRenderer().setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df)); //$NON-NLS-1$ barplot.getRenderer().setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); // set the display of Y axis NumberAxis numAxis = (NumberAxis) barplot.getRangeAxis(); numAxis.setNumberFormatOverride(df); CategoryDataset lineDataset = getLineDataset(dotChartLabels, formalValues); JFreeChart lineChart = ChartFactory.createLineChart(null, title, categoryAxisLabel, lineDataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot plot = lineChart.getCategoryPlot(); if (customerDataset != null) { barplot.setDataset(2, new EncapsulationCumstomerDataset(dataset, customerDataset)); } // show the value on the right axis of the chart(keep the comment) // NumberAxis numberaxis = new NumberAxis(DefaultMessagesImpl.getString("TopChartFactory.Value")); // plot.setRangeAxis(10, numberaxis); NumberAxis vn = (NumberAxis) plot.getRangeAxis(); vn.setNumberFormatOverride(df); // set points format LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setPaint(COLOR_LIST.get(1)); renderer.setSeriesShape(1, new Rectangle2D.Double(-1.5, -1.5, 3, 3)); renderer.setShapesVisible(true); // show the point shape renderer.setBaseLinesVisible(false);// do not show the line // add the bar chart into the line chart CategoryItemRenderer barChartRender = barplot.getRenderer(); barplot.setDataset(0, lineDataset); barplot.setRenderer(0, plot.getRenderer()); barplot.setDataset(1, dataset); barplot.setRenderer(1, barChartRender); return barChart; }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of a Comparative Response Model * Histogram./*from w w w . j ava 2 s . c o m*/ * * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param dataBefore * The array of values before the response. * @param dataAfter * The array of values after the response. * @return a chart panel with the graphical representation. */ public static ChartPanel createDailyResponseHistogram(String title, String x, String y, double[] dataBefore, double[] dataAfter) { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < dataBefore.length; i++) { dataset.addValue(dataBefore[i], "Basic Scheme", "" + i + ""); if (i < dataAfter.length) dataset.addValue(dataAfter[i], "New Scheme", "" + i + ""); else dataset.addValue(0, "New Scheme", "" + i + ""); } JFreeChart chart = ChartFactory.createBarChart3D(title, // chart title x, // domain axis label y, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(1.0f); // left align the category labels... final CategoryAxis axis = plot.getDomainAxis(); final CategoryLabelPositions p = axis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f); axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); return new ChartPanel(chart); }
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 av a2 s .c o m*/ 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); }