List of usage examples for org.jfree.chart JFreeChart setBorderVisible
public void setBorderVisible(boolean visible)
From source file:org.eevolution.form.CRPDetail.java
/** * Create Chart based on UOM// ww w. j ava 2 s .c o m * * @param dataset * @param title * @param uom * @return JFreeChart Chart based On UOM */ public JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) { JFreeChart chart = ChartFactory.createBarChart3D(title, Msg.translate(Env.getCtx(), "Day"), // X-Axis label Msg.translate(Env.getCtx(), (uom == null) ? "" : uom.getName()), // Y-Axis // label dataset, // Dataset PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); chart.setBackgroundPaint(Color.WHITE); chart.setAntiAlias(true); chart.setBorderVisible(true); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.GRAY); BarRenderer3D barrenderer = (BarRenderer3D) plot.getRenderer(); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelGenerator(new LabelGenerator()); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setSeriesPaint(0, new Color(10, 80, 150, 128)); barrenderer.setSeriesPaint(1, new Color(180, 60, 50, 128)); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_CENTER); barrenderer.setPositiveItemLabelPosition(itemlabelposition); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:org.deegree.graphics.charts.ChartsBuilder.java
/** * Initializes the chart with the values from the properties file config.properties * * @param chart/*w ww .j a v a2s .c o m*/ * @param chartConfigs * to configure the output chart * @return initialized chart */ protected JFreeChart configChart(JFreeChart chart, ChartConfig chartConfigs) { chart.setAntiAlias(chartConfigs.isGenAntiAliasing()); chart.setBorderVisible(chartConfigs.isGenBorderVisible()); String rectanglkeInsets = chartConfigs.getGenRectangleInsets(); if (!rectanglkeInsets.startsWith("!")) { String[] insets = rectanglkeInsets.split(","); if (insets.length == 4) { try { double top = Double.parseDouble(insets[0]); double left = Double.parseDouble(insets[1]); double buttom = Double.parseDouble(insets[2]); double right = Double.parseDouble(insets[3]); RectangleInsets rectInsets = new RectangleInsets(top, left, buttom, right); chart.setPadding(rectInsets); } catch (Exception e) { LOG.logError(Messages.getMessage("GRA_CHART_BAD_FORMAT_INSETS")); } } else { LOG.logError(Messages.getMessage("GRA_CHART_BAD_FORMAT_INSETS")); } } chart.setTextAntiAlias(chartConfigs.isGenTextAntiAlias()); chart.setBackgroundPaint(chartConfigs.getGenBackgroundColor()); chart.getPlot().setOutlineVisible(chartConfigs.isPlotOutlineVisible()); chart.getPlot().setForegroundAlpha((float) chartConfigs.getPlotForegroundOpacity()); chart.getPlot().setBackgroundPaint(chartConfigs.getPlotBackgroundColor()); return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
private void createGraphTab(final CTabFolder parentTabFolder) { plotTab = new CTabItem(parentTabFolder, SWT.NONE); plotTab.setText(Messages.ScatterPlotDialog_Graph); JFreeChart chart = new JFreeChart(EMPTY, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), 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.addChartMouseListener(new PlotMouseListener()); plotTab.setControl(chartComposite);// w w w. j a v a 2 s .c o m chartComposite.pack(); }
From source file:userinterface.StateNetworkAdminRole.StateReportsJPanel.java
private JFreeChart createDonorsReportsChart(CategoryDataset dataset) { JFreeChart barChart = ChartFactory.createBarChart("No Of Registered Donors", "Year", "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; }
From source file:dk.netarkivet.harvester.harvesting.monitor.StartedJobHistoryChartGen.java
/** * Generates a chart in PNG format./*from w w w . j a v a 2 s. c o m*/ * @param outputFile the output file, it should exist. * @param pxWidth the image width in pixels. * @param pxHeight the image height in pixels. * @param chartTitle the chart title, may be null. * @param xAxisTitle the x axis title * @param yDataSeriesRange the axis range (null for auto) * @param yDataSeriesTitles the Y axis titles. * @param timeValuesInSeconds the time values in seconds * @param yDataSeries the Y axis value series. * @param yDataSeriesColors the Y axis value series drawing colors. * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix * @param drawBorder draw, or not, the border. * @param backgroundColor the chart background color. */ final void generatePngChart(File outputFile, int pxWidth, int pxHeight, String chartTitle, String xAxisTitle, String[] yDataSeriesTitles, double[] timeValuesInSeconds, double[][] yDataSeriesRange, double[][] yDataSeries, Color[] yDataSeriesColors, String[] yDataSeriesTickSuffix, boolean drawBorder, Color backgroundColor) { // Domain axis NumberAxis xAxis = new NumberAxis(xAxisTitle); xAxis.setFixedDimension(CHART_AXIS_DIMENSION); xAxis.setLabelPaint(Color.black); xAxis.setTickLabelPaint(Color.black); double maxSeconds = getMaxValue(timeValuesInSeconds); TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds); xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep)); double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds); String tickSymbol = I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name()); xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'")); // First dataset String firstDataSetTitle = yDataSeriesTitles[0]; XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]); Color firstDataSetColor = yDataSeriesColors[0]; // First range axis NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle); firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(firstYAxis, yDataSeriesRange[0]); firstYAxis.setLabelPaint(firstDataSetColor); firstYAxis.setTickLabelPaint(firstDataSetColor); String firstAxisTickSuffix = yDataSeriesTickSuffix[0]; if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) { firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'")); } // Create the plot with domain axis and first range axis XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null); XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false); plot.setRenderer(firstRenderer); 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)); firstRenderer.setSeriesPaint(0, firstDataSetColor); // Now iterate on next axes for (int i = 1; i < yDataSeries.length; i++) { // Create axis String seriesTitle = yDataSeriesTitles[i]; Color seriesColor = yDataSeriesColors[i]; NumberAxis yAxis = new NumberAxis(seriesTitle); yAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(yAxis, yDataSeriesRange[i]); yAxis.setLabelPaint(seriesColor); yAxis.setTickLabelPaint(seriesColor); String yAxisTickSuffix = yDataSeriesTickSuffix[i]; if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) { yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'")); } // Create dataset and add axis to plot plot.setRangeAxis(i, yAxis); plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT); plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i])); plot.mapDatasetToRangeAxis(i, i); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, seriesColor); plot.setRenderer(i, renderer); } // Create the chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false); // Customize rendering chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); // Render image try { ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight); } catch (IOException e) { LOG.error("Chart export failed", e); } }
From source file:userinterface.StateNetworkAdminRole.StateReportsJPanel.java
private JFreeChart createpatientDonorReportsChart(CategoryDataset dataset) { JFreeChart barChart = ChartFactory.createBarChart("Patients:Donor in the state", "Year", "Number of Donors/Patients", 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; }
From source file:org.esa.beam.visat.toolviews.diag.TileCacheMonitor.java
/** * Creates a new monitor panel./*from w w w . ja v a 2s.c om*/ * * @return the monitor panel */ public JPanel createPanel() { JPanel mainPanel = new JPanel(new BorderLayout()); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.datasets = new TimeSeriesCollection[4]; this.datasets[0] = addSubPlot(plot, "#Tiles"); this.datasets[1] = addSubPlot(plot, "#Hits"); this.datasets[2] = addSubPlot(plot, "#Misses"); this.datasets[3] = addSubPlot(plot, "Mem (kB)"); JFreeChart chart = new JFreeChart(plot); LegendTitle legend = (LegendTitle) chart.getSubtitle(0); legend.setPosition(RectangleEdge.RIGHT); legend.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0, 4, 0, 4)); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds textarea = new JTextArea(); tableModel = new TileCacheTableModel(); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 470)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); tabbedPane = new JTabbedPane(); tabbedPane.add(CACHE_INFO_TAB, new JScrollPane(textarea)); tabbedPane.add(CACHE_CHART_TAB, chartPanel); tabbedPane.add(IMAGES_TAB, new JScrollPane(new JTable(tableModel))); tabbedPane.setSelectedIndex(0); mainPanel.add(tabbedPane); return mainPanel; }
From source file:userinterface.StateNetworkAdminRole.StateReportsJPanel.java
private JFreeChart createPatientReportsChart(CategoryDataset dataset) { JFreeChart barChart = ChartFactory.createBarChart("Average Waiting period of Patients", "Year", "Avg Waiting period(months)", 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; }
From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String xField, String yField) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);/* ww w .ja v a 2s . c o m*/ plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // 2. Setup Scatter plot // Create the scatter data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3)); plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot plotRenderer.setBaseToolTipGenerator(plotToolTip); // Set the scatter data, renderer, and axis into plot plot.setDataset(0, getScatterPlotData(features, xField, yField)); xPlotAxis.setAutoRangeIncludesZero(false); xPlotAxis.setAutoRange(false); double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX(); double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX(); double gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX()); } else { xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap); } yPlotAxis.setAutoRangeIncludesZero(false); yPlotAxis.setAutoRange(false); differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY(); differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY(); gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY()); } else { yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap); } plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); // AverageY XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$ horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY()); horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY()); lineDataset.addSeries(horizontal); // AverageX XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound()); vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(vertical); // Degree XYSeries degree = new XYSeries("Deegree"); //$NON-NLS-1$ degree.add(xPlotAxis.getRange().getLowerBound(), yPlotAxis.getRange().getLowerBound()); degree.add(xPlotAxis.getRange().getUpperBound(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(degree); plot.setDataset(1, lineDataset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY))); 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:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java
private void createGraphTab(final CTabFolder parentTabFolder) { plotTab = new CTabItem(parentTabFolder, SWT.NONE); plotTab.setText(Messages.MoranScatterPlotDialog_Graph); XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);/*ww w .j ava2s.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(); }