List of usage examples for org.jfree.chart JFreeChart setBorderVisible
public void setBorderVisible(boolean visible)
From source file:org.jfree.chart.swt.demo.SWTMultipleAxisDemo1.java
/** * Creates the demo chart.// w ww.j av a 2s . c o m * * @return The chart. */ private static JFreeChart createChart() { XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); TextTitle subtitle = new TextTitle("Four datasets and four range axes."); chart.addSubtitle(subtitle); XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); // AXIS 2 NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); // AXIS 3 NumberAxis axis3 = new NumberAxis("Range Axis 3"); axis3.setLabelPaint(Color.blue); axis3.setTickLabelPaint(Color.blue); //axis3.setPositiveArrowVisible(true); plot.setRangeAxis(2, axis3); XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 2); XYItemRenderer renderer3 = new StandardXYItemRenderer(); renderer3.setSeriesPaint(0, Color.blue); plot.setRenderer(2, renderer3); // AXIS 4 NumberAxis axis4 = new NumberAxis("Range Axis 4"); axis4.setLabelPaint(Color.green); axis4.setTickLabelPaint(Color.green); plot.setRangeAxis(3, axis4); XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200); plot.setDataset(3, dataset4); plot.mapDatasetToRangeAxis(3, 3); XYItemRenderer renderer4 = new StandardXYItemRenderer(); renderer4.setSeriesPaint(0, Color.green); plot.setRenderer(3, renderer4); return chart; }
From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java
/** * Creates the demo chart.//from w ww .jav a 2 s. c o m * * @return The chart. */ private static JFreeChart createChart() { XYDataset dataset1 = createDataset("Series 1", 100.0, new Day(), 200); JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); TextTitle subtitle = new TextTitle("Four datasets and four range axes."); chart.addSubtitle(subtitle); XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); // AXIS 2 NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); XYDataset dataset2 = createDataset("Series 2", 1000.0, new Day(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); // AXIS 3 NumberAxis axis3 = new NumberAxis("Range Axis 3"); axis3.setLabelPaint(Color.blue); axis3.setTickLabelPaint(Color.blue); // axis3.setPositiveArrowVisible(true); plot.setRangeAxis(2, axis3); XYDataset dataset3 = createDataset("Series 3", 10000.0, new Day(), 170); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 2); XYItemRenderer renderer3 = new StandardXYItemRenderer(); renderer3.setSeriesPaint(0, Color.blue); plot.setRenderer(2, renderer3); // AXIS 4 NumberAxis axis4 = new NumberAxis("Range Axis 4"); axis4.setLabelPaint(Color.green); axis4.setTickLabelPaint(Color.green); plot.setRangeAxis(3, axis4); XYDataset dataset4 = createDataset("Series 4", 25.0, new Day(), 200); plot.setDataset(3, dataset4); plot.mapDatasetToRangeAxis(3, 3); XYItemRenderer renderer4 = new StandardXYItemRenderer(); renderer4.setSeriesPaint(0, Color.green); plot.setRenderer(3, renderer4); return chart; }
From source file:com.projity.pm.graphic.chart.ChartHelper.java
public static JFreeChart createChart(final XYDataset dataset, boolean bar, final XYDataset secondDataset) { JFreeChart chart; if (secondDataset != null) chart = createBarLineChart(dataset, secondDataset); else//from w w w.j a va2s. c o m chart = bar ? createBarChart(dataset) : createLineChart(dataset); chart.setAntiAlias(false);// faster chart.setBorderVisible(false); return chart; }
From source file:no.met.jtimeseries.chart.Utility.java
/** * Create a plot with an error message in case of error. * /* www .j a v a2 s . c om*/ * @param width * The width of the plot * @return The JFreeChart error plot */ public static JFreeChart createErrorChart(int width) { XYPlot plot = new XYPlot(); plot.setBackgroundPaint(null); plot.setBackgroundImage(Symbols.getImage("/error.png")); JFreeChart jchart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); jchart.setBorderVisible(false); Paint paint = new GradientPaint(0, 0, Color.WHITE, width, 0, Color.WHITE); jchart.setBackgroundPaint(paint); return jchart; }
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 v a2s . 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:org.gbif.portal.web.util.ChartUtils.java
/** * Writes out the image using the supplied file name. * //from www. j a v a 2s. co m * @param legend * @param fileName * @return */ public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) { String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName + defaultExtension; } final DefaultPieDataset data = new DefaultPieDataset(); Set<String> keys = legend.keySet(); for (String key : keys) { logger.info("Adding key : " + key); data.setValue(key, legend.get(key)); } // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false); PiePlot piePlot = (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10)); piePlot.setLabelBackgroundPaint(Color.WHITE); LegendTitle lt = chart.getLegend(); lt.setBackgroundPaint(Color.WHITE); lt.setWidth(300); lt.setBorder(0, 0, 0, 0); lt.setItemFont(new Font("Arial", Font.PLAIN, 11)); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB); KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter(); adapter.setQuality(1); try { adapter.encode(image); } catch (IOException e) { logger.error(e.getMessage(), e); } final Graphics2D g2 = image.createGraphics(); g2.setFont(new Font("Arial", Font.PLAIN, 11)); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250); // draw chart.draw(g2, chartArea, null, null); try { FileOutputStream fOut = new FileOutputStream(fileToCheck); ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250); return fileToCheck.getName(); } catch (IOException e) { logger.error(e.getMessage(), e); return null; } }
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 ww w . j a v a 2 s . co 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 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); }
From source file:cl.apr.pdf.chart.BarChartAviso.java
public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) { BufferedImage bi = null;// w ww . j av a 2s .c o m try { ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme()); //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme()); /* Step - 1: Define the data for the bar chart */ DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset(); int i = 0; for (BarChartItem barChartItem : barChartItems) { if (barChartItem.getNombre().equals("-")) { my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + ""); } else my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre()); } // my_bar_chart_dataset.addValue(34, "mes", "Ene"); // my_bar_chart_dataset.addValue(25, "mes", "Feb"); // my_bar_chart_dataset.addValue(22, "mes", "Mar"); // my_bar_chart_dataset.addValue(12, "mes", "Abr"); // my_bar_chart_dataset.addValue(40, "mes", "May"); // my_bar_chart_dataset.addValue(30, "mes", "jun"); // my_bar_chart_dataset.addValue(2, "mes", "Jul"); // my_bar_chart_dataset.addValue(15, "mes", "Ago"); /* Step -2:Define the JFreeChart object to create bar chart */ //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false); JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset, PlotOrientation.VERTICAL, true, true, false); //chart.setBackgroundPaint(Color.lightGray); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer renderer = new CustomRenderer(); renderer.setSeriesPaint(0, Color.DARK_GRAY); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); chart.setBorderVisible(false); chart.setBackgroundPaint(Color.white); chart.setBorderStroke(null); chart.getLegend().visible = false; /* Step -3: Write the output as PNG file with bar chart information */ int width = 480; /* Width of the image */ int height = 250; /* Height of the image */ bi = chart.createBufferedImage(width, height); /* File BarChart=new File("output_chart.png"); ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); */ } catch (Exception i) { System.out.println(i); } return bi; }
From source file:ec.util.chart.swing.Charts.java
/** * A sparkline is a type of information graphic characterized by its small * size and high data density. Sparklines present trends and variations * associated with some measurement, such as average temperature or stock * market activity, in a simple and condensed way. Several sparklines are * often used together as elements of a small multiple.<br> * * {@link http://en.wikipedia.org/wiki/Sparkline} * * @param dataset//from ww w .jav a 2 s .c o m * @return * @author Philippe Charles */ @Nonnull public static JFreeChart createSparkLineChart(@Nonnull XYDataset dataset) { JFreeChart result = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); result.setBorderVisible(false); result.setBackgroundPaint(null); result.setAntiAlias(true); XYPlot plot = result.getXYPlot(); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setOutlineVisible(false); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); plot.setBackgroundPaint(null); ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false); return result; }