List of usage examples for java.awt GradientPaint GradientPaint
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)
From source file:org.jfree.chart.demo.selection.SelectionDemo5Category.java
private static JFreeChart createChart(CategoryDataset dataset, DatasetSelectionExtension<CategoryCursor<String, String>> ext) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1", "Category", "Value", dataset); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairPaint(Color.blue); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false);/*from w w w. ja v a 2 s . c o m*/ // 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); renderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}")); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); //add selection specific rendering IRSUtilities.setSelectedItemPaint(renderer, ext, Color.WHITE); //register plot as selection change listener ext.addChangeListener(plot); 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 *//* ww w . j a va 2 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:graphs.ResultsGraphs.java
/** * Creates a sample chart./* w w w. ja v a 2 s. c om*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Mashup Language Sentiment Algorithm Performance ", // chart title "Performance Metric", // 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... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); 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... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.jfree.expdemo.SelectionDemo5Category.java
private static JFreeChart createChart(CategoryDataset dataset, DatasetSelectionExtension ext) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from w w w.j a v a 2 s . c o m*/ CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairPaint(Color.blue); // set the range axis to display integers only... 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); renderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}")); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); //add selection specific rendering IRSUtilities.setSelectedItemPaint(renderer, ext, Color.WHITE); //register plot as selection change listener ext.addSelectionChangeListener(plot); return chart; }
From source file:fitmon.Chart.java
/** * Creates a sample chart.//from w w w .ja va 2 s . co m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final 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... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); 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... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.jfree.chart.demo.CombinedXYPlotDemo3.java
/** * Creates a combined XYPlot chart./*from w ww . jav a2 s . com*/ * * @return the combined chart. */ private JFreeChart createCombinedChart() { // create a default chart based on some sample data... final TimeSeriesCollection dataset0 = new TimeSeriesCollection(); final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries(); dataset0.addSeries(eur); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(); final TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30); dataset1.addSeries(eur); dataset1.addSeries(mav); final TimeSeriesCollection dataset2 = new TimeSeriesCollection(); dataset2.addSeries(eur); JFreeChart chart = null; // make a common vertical axis for all the sub-plots final NumberAxis valueAxis = new NumberAxis("Value"); valueAxis.setAutoRangeIncludesZero(false); // override default // make a horizontally combined plot final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis); // add subplot 1... final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis("Date 1"), null, new StandardXYItemRenderer()); parent.add(subplot1, 1); // add subplot 2... final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null, new StandardXYItemRenderer()); parent.add(subplot2, 1); // add subplot 3... final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"), null, new XYBarRenderer(0.20)); parent.add(subplot3, 1); // now make the top level JFreeChart chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true); // then customise it a little... final TextTitle subtitle = new TextTitle("This is a subtitle", new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }
From source file:org.amanzi.splash.chart.Charts.java
/** * This method creates a chart.// ww w . j a va 2 s . c o m * * @param dataset. dataset provides the data to be displayed in the chart. The parameter is * provided by the 'createDataset()' method. * @return A chart. */ public static JFreeChart createBarChart(DefaultCategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("", // chart title "", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... 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)); renderer.setSeriesPaint(0, gp0); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreateBarChartView.java
/** * Returns an array of paint objects that will be used for the bar colors. * // w w w. ja v a 2 s . co m * @return An array of paint objects. */ private static Paint[] createPaint() { Paint[] colors = new Paint[5]; colors[0] = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); colors[1] = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); colors[2] = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); colors[3] = new GradientPaint(0f, 0f, Color.orange, 0.0f, 0.0f, new Color(250, 128, 114)); colors[4] = new GradientPaint(0f, 0f, Color.yellow, 0.0f, 0.0f, new Color(255, 215, 0)); return colors; }
From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java
/** Generate CGI chart output. */ @Override/*from w ww .jav a 2s . com*/ protected void writeContents() throws IOException { buildData(); // get the data for display chromeless = (parameters.get("chromeless") != null); JFreeChart chart = createChart(); int width = getIntSetting("width"); int height = getIntSetting("height"); Color initGradColor = getColorSetting("initGradColor"); Color finalGradColor = getColorSetting("finalGradColor"); chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor)); if (parameters.get("hideOutline") != null) chart.getPlot().setOutlinePaint(INVISIBLE); String title = getSetting("title"); if (chromeless || title == null || title.length() == 0) chart.setTitle((TextTitle) null); else { chart.setTitle(Translator.translate(title)); String titleFontSize = getSetting("titleFontSize"); if (titleFontSize != null) try { float fontSize = Float.parseFloat(titleFontSize); TextTitle t = chart.getTitle(); t.setFont(t.getFont().deriveFont(fontSize)); } catch (Exception tfe) { } } if (chromeless || parameters.get("hideLegend") != null) chart.removeLegend(); else { LegendTitle l = chart.getLegend(); String legendFontSize = getSetting("legendFontSize"); if (l != null && legendFontSize != null) try { float fontSize = Float.parseFloat(legendFontSize); l.setItemFont(l.getItemFont().deriveFont(fontSize)); } catch (Exception lfe) { } } chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message")); Axis xAxis = getHorizontalAxis(chart); if (xAxis != null) { if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) { xAxis.setTickLabelsVisible(false); } else if (parameters.get("tickLabelFontSize") != null || parameters.get("xTickLabelFontSize") != null) { String tfs = getParameter("xTickLabelFontSize"); if (tfs == null) tfs = getParameter("tickLabelFontSize"); float fontSize = Float.parseFloat(tfs); xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize)); } } Axis yAxis = getVerticalAxis(chart); if (yAxis != null) { if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) { yAxis.setTickLabelsVisible(false); } else if (parameters.get("tickLabelFontSize") != null || parameters.get("yTickLabelFontSize") != null) { String tfs = getParameter("yTickLabelFontSize"); if (tfs == null) tfs = getParameter("tickLabelFontSize"); float fontSize = Float.parseFloat(tfs); yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize)); } } String axisFontSize = getSetting("axisLabelFontSize"); if (axisFontSize != null) try { float fontSize = Float.parseFloat(axisFontSize); if (xAxis != null) xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize)); if (yAxis != null) yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize)); } catch (Exception afs) { } ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); if ("auto".equals(getSetting("titleFontSize"))) maybeAdjustTitleFontSize(chart, g2, width); chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info); g2.dispose(); String outputFormat = getSetting("outputFormat"); OutputStream imgOut; if (isHtmlMode()) { imgOut = PngCache.getOutputStream(); } else { imgOut = outStream; } ImageIO.write(img, outputFormat, imgOut); imgOut.flush(); imgOut.close(); if (isHtmlMode()) writeImageHtml(width, height, imgOut.hashCode(), info); }
From source file:j2se.jfreechart.barchart.BarChartDemo1.java
/** * Creates a sample chart.// w w w .ja v a 2 s . c om * * @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; }