List of usage examples for org.jfree.chart JFreeChart setBorderVisible
public void setBorderVisible(boolean visible)
From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java
private void createGraphTab(final CTabFolder parentTabFolder) { plotTab = new CTabItem(parentTabFolder, SWT.NONE); plotTab.setText(Messages.ScatterPlotDialog_Graph); CategoryPlot plot = new CategoryPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setRangePannable(false);/* www .j a v a2s .c o m*/ JFreeChart chart = new JFreeChart(EMPTY, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite = new ChartComposite(parentTabFolder, SWT.NONE | SWT.EMBEDDED, chart, true); chartComposite.setLayout(new FillLayout()); chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); chartComposite.setDomainZoomable(false); chartComposite.setRangeZoomable(false); // chartComposite.setMap(map); chartComposite.addChartMouseListener(new PlotMouseListener()); plotTab.setControl(chartComposite); chartComposite.pack(); }
From source file:com.esofthead.mycollab.ui.chart.PieChartWrapper.java
@Override protected JFreeChart createChart() { // create the chart... pieDataSet = createDataset();//from www . j a va2s.co m final JFreeChart chart = ChartFactory.createPieChart3D("", // chart // title pieDataSet, // data false, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.getTitle().setPaint(new Color(0x5E5E5E)); chart.setBorderVisible(false); // set the background color for the chart... final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setOutlineVisible(false); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setStartAngle(290); plot.setBackgroundPaint(Color.white); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); plot.setLabelGenerator(new JFreeChartLabelCustom()); final List keys = pieDataSet.getKeys(); for (int i = 0; i < keys.size(); i++) { final Comparable key = (Comparable) keys.get(i); int colorIndex = i % CHART_COLOR_STR.size(); plot.setSectionPaint(key, Color.decode("0x" + CHART_COLOR_STR.get(colorIndex))); } // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String[] fields) { // Setup Box plot int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; CategoryAxis xPlotAxis = new CategoryAxis(EMPTY); // Type xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 12)); NumberAxis yPlotAxis = new NumberAxis("Value"); // Value //$NON-NLS-1$ yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); yPlotAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMedianVisible(true);//from w ww .j a v a 2 s . co m renderer.setMeanVisible(false); renderer.setFillBox(true); renderer.setSeriesFillPaint(0, java.awt.Color.CYAN); renderer.setBaseFillPaint(java.awt.Color.CYAN); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); // Set the scatter data, renderer, and axis into plot CategoryDataset dataset = getDataset(features, fields); CategoryPlot plot = new CategoryPlot(dataset, xPlotAxis, yPlotAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setRangePannable(false); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setForegroundAlpha(0.85f); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup Selection /***************************************************************************************** * CategoryAxis xSelectionAxis = new CategoryAxis(EMPTY); * xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); * * NumberAxis ySelectionAxis = new NumberAxis(EMPTY); * ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); * * BoxAndWhiskerRenderer selectionRenderer = new BoxAndWhiskerRenderer(); * selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); * selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot * * plot.setDataset(2, new DefaultBoxAndWhiskerCategoryDataset()); plot.setRenderer(2, * selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, * ySelectionAxis); * * // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, * 0); plot.mapDatasetToRangeAxis(2, 0); *****************************************************************************************/ // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:com.manydesigns.portofino.chart.ChartBarGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);//ww w.j a v a 2 s . c om Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper x = new ComparableWrapper((Comparable) current[0]); ComparableWrapper y = new ComparableWrapper((Comparable) current[1]); if (current.length > 3) { x.setLabel(current[3].toString()); } if (current.length > 4) { y.setLabel(current[4].toString()); } dataset.setValue((Number) current[2], x, y); } PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL; if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) { plotOrientation = PlotOrientation.VERTICAL; } JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation); chart.setAntiAlias(antiAlias); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno chart.setBorderVisible(borderVisible); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression()); renderer.setBaseItemURLGenerator(urlGenerator); } else { renderer.setBaseItemURLGenerator(null); } renderer.setBaseOutlinePaint(Color.BLACK); // /////////////// if (renderer instanceof BarRenderer || renderer instanceof BarRenderer3D) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setDrawBarOutline(true); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new StandardBarPainter()); // hongliangpan add barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barRenderer.setBaseItemLabelsVisible(true); // ? setSeriesItemLabelGenerator barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // bar??? barRenderer.setMinimumBarLength(0.02); // barRenderer.setMaximumBarWidth(0.05); // ????? // ??90,??/3.14 ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D); // ??labelposition // barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback); // barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback); barRenderer.setItemLabelsVisible(true); // ? barRenderer.setBaseOutlinePaint(Color.BLACK); // ??? barRenderer.setDrawBarOutline(true); // ??? barRenderer.setItemMargin(0.0); // ? barRenderer.setIncludeBaseInRange(true); barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barRenderer.setBaseItemLabelsVisible(true); // ? plot.setForegroundAlpha(1.0f); } // /////////////// // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})")); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // Category axis CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setAxisLinePaint(Color.BLACK); categoryAxis.setLabelFont(axisFont); categoryAxis.setAxisLineVisible(true); // impostiamo la rotazione dell'etichetta if (plot.getOrientation() == PlotOrientation.VERTICAL) { CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0, CategoryLabelWidthType.CATEGORY, 100); CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos); categoryAxis.setCategoryLabelPositions(positions); categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f); height = 333; } else { categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f); // recuperiamo 8 pixel a sinistra plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0)); height = 74; // contiamo gli elementi nel dataset height += 23 * dataset.getColumnCount(); height += 57; } Axis rangeAxis = plot.getRangeAxis(); rangeAxis.setAxisLinePaint(Color.BLACK); rangeAxis.setLabelFont(axisFont); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }
From source file:com.rapidminer.template.gui.RoleRequirementSelector.java
private JFreeChart makeChart(ExampleSet exampleSet, Attribute att) { DefaultPieDataset pieDataset = new DefaultPieDataset(); if (att.isNominal()) { for (String val : att.getMapping().getValues()) { pieDataset.setValue(val, exampleSet.getStatistics(att, Statistics.COUNT, val)); }/*w w w .ja v a 2 s . c o m*/ } JFreeChart chart = ChartFactory.createPieChart(null, pieDataset, true, false, false); chart.setBackgroundPaint(Color.WHITE); chart.getLegend().setFrame(BlockBorder.NONE); chart.setBackgroundImageAlpha(0.0f); chart.setBorderVisible(false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(null); plot.setShadowPaint(null); plot.setOutlineVisible(false); plot.setBackgroundPaint(new Color(255, 255, 255, 0)); plot.setBackgroundImageAlpha(0.0f); plot.setCircular(true); return chart; }
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 w ww.j a va 2 s. 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); }
From source file:com.manydesigns.portofino.chart.ChartStackedBarGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);//from w ww . ja v a 2 s . c o m Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper x = new ComparableWrapper((Comparable) current[0]); ComparableWrapper y = new ComparableWrapper((Comparable) current[1]); if (current.length > 3) { x.setLabel(current[3].toString()); } if (current.length > 4) { y.setLabel(current[4].toString()); } dataset.setValue((Number) current[2], x, y); } PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL; if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) { plotOrientation = PlotOrientation.VERTICAL; } JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation); chart.setAntiAlias(antiAlias); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno chart.setBorderVisible(borderVisible); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression()); renderer.setBaseItemURLGenerator(urlGenerator); } else { renderer.setBaseItemURLGenerator(null); } renderer.setBaseOutlinePaint(Color.BLACK); // /////////////// if (renderer instanceof BarRenderer) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setDrawBarOutline(true); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new StandardBarPainter()); // hongliangpan add // ? barRenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); // bar??? barRenderer.setMinimumBarLength(0.02); // barRenderer.setMaximumBarWidth(0.06); } if (renderer instanceof StackedBarRenderer3D || renderer instanceof StackedBarRenderer) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setDrawBarOutline(true); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new StandardBarPainter()); // hongliangpan add // ? setSeriesItemLabelGenerator barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // bar??? barRenderer.setMinimumBarLength(0.02); // barRenderer.setMaximumBarWidth(0.06); // ????? ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D); // ??labelposition barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback); barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback); barRenderer.setItemLabelsVisible(true); barRenderer.setItemMargin(10); } // /////////////// // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})")); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // Category axis CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setAxisLinePaint(Color.BLACK); categoryAxis.setLabelFont(axisFont); categoryAxis.setAxisLineVisible(true); // impostiamo la rotazione dell'etichetta if (plot.getOrientation() == PlotOrientation.VERTICAL) { CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0, CategoryLabelWidthType.CATEGORY, 100); CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos); categoryAxis.setCategoryLabelPositions(positions); categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f); height = 333; } else { categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f); // recuperiamo 8 pixel a sinistra plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0)); height = 74; // contiamo gli elementi nel dataset height += 23 * dataset.getColumnCount(); height += 57; } Axis rangeAxis = plot.getRangeAxis(); rangeAxis.setAxisLinePaint(Color.BLACK); rangeAxis.setLabelFont(axisFont); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java
private void createGraphTab(final CTabFolder parentTabFolder) { plotTab = new CTabItem(parentTabFolder, SWT.NONE); plotTab.setText(Messages.ScatterPlotDialog_Graph); XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);//from w w w . j a v a 2 s . co m plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart(EMPTY, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite = new ChartComposite2(parentTabFolder, SWT.NONE | SWT.EMBEDDED, chart, true); chartComposite.setLayout(new FillLayout()); chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); chartComposite.setDomainZoomable(false); chartComposite.setRangeZoomable(false); chartComposite.setMap(map); chartComposite.addChartMouseListener(new PlotMouseListener()); plotTab.setControl(chartComposite); chartComposite.pack(); }
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 w w w. j ava2s . co m 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:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java
private JFreeChart createDonorsByStateReportsChart(CategoryDataset dataset) { JFreeChart barChart = ChartFactory.createBarChart("No Of Registered Donors by State", "State", " No Of Registered Donors", dataset, PlotOrientation.VERTICAL, true, true, false); barChart.setBackgroundPaint(Color.white); // Set the background color of the chart barChart.getTitle().setPaint(Color.DARK_GRAY); barChart.setBorderVisible(true); // Adjust the color of the title CategoryPlot plot = barChart.getCategoryPlot(); plot.getRangeAxis().setLowerBound(0.0); // Get the Plot object for a bar graph plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.blue); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.decode("#00008B")); //return chart; return barChart; }