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.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createStackedBarChart3D(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); CategoryItemRenderer renderer = new StackedBarRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); }//from www.j a v a 2 s . co m if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); if (orientation == PlotOrientation.HORIZONTAL) { // change rendering order to ensure that bar overlapping is the // right way around plot.setColumnRenderingOrder(SortOrder.DESCENDING); } // create the chart... JFreeChart chart = new JFreeChart("StackedBar Chart 3D Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 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); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:com.indicator_engine.controller.GraphController.java
private JFreeChart createBarChart(final CategoryDataset dataset, final String chartTitle) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title "Indicators", // domain axis label "Count", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );//w w w .j a va 2 s .c om // 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)); return chart; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample stacked vertical bar chart. * * @return a sample stacked vertical bar chart. *///from w w w. j a v a 2s. c om public JFreeChart createVerticalStackedBarChart() { // create a default chart based on some sample data... final String title = this.resources.getString("bar.vertical-stacked.title"); final String domain = this.resources.getString("bar.vertical-stacked.domain"); final String range = this.resources.getString("bar.vertical-stacked.range"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final JFreeChart chart = ChartFactory.createStackedBarChart(title, domain, range, data, PlotOrientation.VERTICAL, true, true, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red)); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java
private static JFreeChart createStackedAreaChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createStackedAreaChart("StackedArea 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 av a 2s .com chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); StackedAreaRenderer renderer = (StackedAreaRenderer) plot.getRenderer(); // renderer.setRenderAsPercentages(true); // 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); return chart; }
From source file:no.met.jtimeseries.chart.Utility.java
/** * Create a plot with an error message in case of error. * /*from ww w.j av a 2 s.c o m*/ * @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.gargoylesoftware.htmlunit.javascript.host.PropertiesTest.java
private void saveChart(final DefaultCategoryDataset dataset) throws IOException { final JFreeChart chart = ChartFactory.createBarChart( "HtmlUnit implemented properties and methods for " + browserVersion_.getNickname(), "Objects", "Count", dataset, PlotOrientation.HORIZONTAL, true, true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final LayeredBarRenderer renderer = new LayeredBarRenderer(); plot.setRenderer(renderer);//from w w w. j a va 2s . c o m plot.setRowRenderingOrder(SortOrder.DESCENDING); renderer.setSeriesPaint(0, new GradientPaint(0, 0, Color.green, 0, 0, new Color(0, 64, 0))); renderer.setSeriesPaint(1, new GradientPaint(0, 0, Color.blue, 0, 0, new Color(0, 0, 64))); renderer.setSeriesPaint(2, new GradientPaint(0, 0, Color.red, 0, 0, new Color(64, 0, 0))); ImageIO.write(chart.createBufferedImage(1200, 2400), "png", new File(getArtifactsDirectory() + "/properties-" + browserVersion_.getNickname() + ".png")); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample stacked vertical 3D bar chart. * * @return a sample stacked vertical 3D bar chart. *//*w ww .ja v a 2 s.c o m*/ public JFreeChart createVerticalStacked3DBarChart() { // create a default chart based on some sample data... final String title = this.resources.getString("bar.vertical-stacked3D.title"); final String domain = this.resources.getString("bar.vertical-stacked3D.domain"); final String range = this.resources.getString("bar.vertical-stacked3D.range"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final JFreeChart chart = ChartFactory.createStackedBarChart3D(title, domain, range, data, PlotOrientation.VERTICAL, true, true, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red)); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createLineChart(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); }/*from w w w. j a va2s. co m*/ if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Line Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setUseOutlinePaint(true); 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); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java
private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { String uri = request.getRequestURI(); String requestString = uri.split("test_images/")[1]; String[] requestParams = requestString.split("/"); String reportName = URLDecoder.decode(requestParams[0], charset); String categoryName = URLDecoder.decode(requestParams[1], charset); // String className = URLDecoder.decode(requestParams[2], charset); String testName = URLDecoder.decode(requestParams[3], charset); String agent = URLDecoder.decode(requestParams[4], charset); ReportDatabase db = ReportDatabase.getInstance(); Report report = db.getReport(reportName); List<Category> categories = report.getCategories(); Category category = getCategoryByName(categories, categoryName); List<Benchmark> benchmarks = category.getBenchmarks(); Benchmark benchmark = getBenchmarkByName(benchmarks, testName); List<Result> results = benchmark.getResults(); Result result = getResultsByAgent(results, agent); String title = BrowserInfo.getBrowser(agent); JFreeChart chart = createChart(testName, result, title, results); chart.getTitle().setFont(Font.decode("Verdana BOLD 12")); chart.setAntiAlias(true);/*from ww w.j ava 2 s. c om*/ chart.setBorderVisible(true); chart.setBackgroundPaint(new Color(241, 241, 241)); Plot plot = chart.getPlot(); plot.setDrawingSupplier(getDrawingSupplier()); plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 640, 480, new Color(200, 200, 200))); if (plot instanceof XYPlot) { XYPlot xyplot = (XYPlot) plot; Font labelFont = Font.decode("Verdana PLAIN"); xyplot.getDomainAxis().setLabelFont(labelFont); xyplot.getRangeAxis().setLabelFont(labelFont); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setStroke(new BasicStroke(4)); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setShapesVisible(true); xylineandshaperenderer.setShapesFilled(true); } } // Try to fit all the graphs into a 1024 window, with a min of 240 and a max // of 480 final int graphWidth = Math.max(240, Math.min(480, (1024 - 10 * results.size()) / results.size())); BufferedImage img = chart.createBufferedImage(graphWidth, 240); byte[] image = EncoderUtil.encode(img, ImageFormat.PNG); // The images have unique URLs; might as well set them to never expire. response.setHeader("Cache-Control", "max-age=0"); response.setHeader("Expires", "Fri, 2 Jan 1970 00:00:00 GMT"); response.setContentType("image/png"); response.setContentLength(image.length); OutputStream output = response.getOutputStream(); output.write(image); }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java
private static JFreeChart createWaterfallChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createWaterfallChart("Waterfall 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 . ja v a 2 s. c o m*/ chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); WaterfallBarRenderer renderer = (WaterfallBarRenderer) plot.getRenderer(); // 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.setFirstBarPaint(gp0); renderer.setLastBarPaint(gp2); renderer.setPositiveBarPaint(Color.orange); renderer.setNegativeBarPaint(Color.cyan); return chart; }