List of usage examples for org.jfree.chart JFreeChart setBackgroundImageAlpha
public void setBackgroundImageAlpha(float alpha)
From source file:com.rapidminer.gui.viewer.metadata.model.DateTimeAttributeStatisticsModel.java
/** * Creates the histogram chart.// w w w . ja va 2 s. c om * * @param exampleSet * @return */ private JFreeChart createHistogramChart(final ExampleSet exampleSet) { JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet), PlotOrientation.VERTICAL, false, false, false); AbstractAttributeStatisticsModel.setDefaultChartFonts(chart); chart.setBackgroundPaint(null); chart.setBackgroundImageAlpha(0.0f); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setOutlineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setDomainZeroBaselineVisible(false); plot.getDomainAxis().setTickLabelsVisible(false); plot.setBackgroundPaint(COLOR_INVISIBLE); plot.setBackgroundImageAlpha(0.0f); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME)); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); return chart; }
From source file:com.compomics.pepshell.view.statistics.CleavingProbabilityPane.java
@Override public void setGraphData(PepshellProtein aPepshellProtein) { //obligatory checks if (aPepshellProtein != null && experiment.getProteins().contains(aPepshellProtein)) { if (aPepshellProtein != currentPepshellProtein) { //TODO: run this outside of the gui thread currentPepshellProtein = experiment.getProteins() .get(experiment.getProteins().indexOf(aPepshellProtein)); XYSeriesCollection xYSeriesCollection = new XYSeriesCollection(); fillSeries(currentPepshellProtein).forEach(xYSeriesCollection::addSeries); JFreeChart CPDTchart = ChartFactory.createXYLineChart("probability of cleaving", "aminoacids of " + currentPepshellProtein.getVisibleAccession(), "probability", xYSeriesCollection, PlotOrientation.VERTICAL, false, true, false); prettifyChart(CPDTchart);/* w w w . java2s . c o m*/ CPDTchart.getXYPlot().getRangeAxis().setLowerBound(cutoff - 0.05); for (int i = 0; i < CPDTchart.getXYPlot().getSeriesCount(); i++) { CPDTchart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(5)); } if (!aPepshellProtein.getDomains().isEmpty()) { CPDTchart.setBackgroundImageAlpha(0.18f); CPDTchart.getXYPlot().getDomainAxis().setRange(0, aPepshellProtein.getProteinSequence().length()); BufferedImage anImage = new BufferedImage(this.getHeight(), this.getWidth(), BufferedImage.TYPE_INT_ARGB); for (FeatureWithLocation aDomain : aPepshellProtein.getDomains()) { anImage.getGraphics().drawRect(aDomain.getStartPosition(), 0, aDomain.getEndPosition(), this.getHeight()); } CPDTchart.setBackgroundImage(anImage); } chart.setChart(CPDTchart); } } else { chart.setChart(null); this.getGraphics().drawString("missing data", 0, 0); } }
From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java
/** * Initialize the graph/*from w ww.j a va2 s . co m*/ */ private void initGraph() { this.series = new BasicSeries("FFT"); XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart graph = ChartFactory.createXYLineChart(null, // title "", // no x-axis label "", // no y-axis label dataset, // data PlotOrientation.VERTICAL, false, // no legend false, // no tooltips false // no URLs ); graph.setBorderVisible(false); graph.setPadding(new RectangleInsets(-5, 0, 0, 0)); graph.setBackgroundPaint(null); graph.setBackgroundImageAlpha(0.0f); graph.setAntiAlias(true); plot = (XYPlot) graph.getPlot(); powerAxis = new PowerAxis(); plot.setRangeAxis(powerAxis); frequencyAxis = new FrequencyAxis(); frequencyAxis.setTickLabelInsets(new RectangleInsets(10, 0, 0, 0)); plot.setDomainAxis(frequencyAxis); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(true); renderer.setSeriesPaint(0, Common.EPIQ_GREEN); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); } plot.setBackgroundAlpha(0.0f); plot.setBackgroundPaint(null); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // X-axis setup plot.getDomainAxis().setAutoRange(false); plot.getDomainAxis().setVisible(true); plot.getDomainAxis().setRange(0, FMCUartClient.BLOCK_SIZE - 1); plot.setDomainCrosshairVisible(false); plot.setDomainCrosshairPaint(new Color(46, 46, 46)); // Y-axis setup plot.getRangeAxis().setAutoRange(false); plot.getRangeAxis().setVisible(true); plot.getRangeAxis().setRange(-50, 70); plot.setRangeCrosshairVisible(false); markerAnnotation.setVisible(false); plot.addAnnotation(markerAnnotation); plot.addAnnotation(markerTextAnnotation); this.markerTitle.setFont(new Font("Tahoma", Font.BOLD, 12)); this.markerTitle.setFrame(new BlockBorder(new Color(46, 46, 46))); this.markerTitle.setBackgroundPaint(new Color(200, 200, 255, 100)); this.markerTitle.setText(""); this.markerTitle.setPadding(5, 15, 5, 15); this.markerTitle.setExpandToFitSpace(false); this.markerTitle.setBounds(new Rectangle2D.Double(0, 0, 100, 30)); chartPanel = new ChartPanel(graph, false); chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); chartPanel.setMinimumDrawWidth(0); chartPanel.setMinimumDrawHeight(0); chartPanel.setMouseZoomable(true); chartPanel.setOpaque(false); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { markerLocked = !markerLocked; } @Override public void chartMouseMoved(ChartMouseEvent event) { updateMouseMarker(event); } }); chartPanel.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { if (!markerLocked) { markerAnnotation.setVisible(false); plot.setDomainCrosshairVisible(false); markerTitle.setVisible(false); markerTitle.setText(""); } } }); chartPanel.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int clicks = e.getWheelRotation(); plot.getRangeAxis().setUpperBound(plot.getRangeAxis().getUpperBound() + clicks); plot.getRangeAxis().setLowerBound(plot.getRangeAxis().getLowerBound() + clicks); } }); }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
protected void setChartStyles(JFreeChart chart, UIChart comp) { Plot plot = chart.getPlot();/*from w ww .jav a2s. co m*/ RectangleInsets insets = plot.getInsets(); Double tm = comp.getTopMargin(); Double lm = comp.getLeftMargin(); Double bm = comp.getBottomMargin(); Double rm = comp.getRightMargin(); if (tm == null || tm < 0) tm = insets.getTop(); if (lm == null || lm < 0) lm = insets.getLeft(); if (bm == null || bm < 0) bm = insets.getBottom(); if (rm == null || rm < 0) rm = insets.getRight(); plot.setInsets(new RectangleInsets(tm, lm, bm, rm)); Paint color = comp.getBackgroundColor(); if (color != null) { chart.setBackgroundPaint(color); } Image image = loadImage(comp.getBackgroundImage()); if (image != null) { chart.setBackgroundImage(image); chart.setBackgroundImageAlignment(getImageAlign(comp.getBackgroundImagePosition())); chart.setBackgroundImageAlpha(comp.getBackgroundImageAlpha()); } color = comp.getPlotColor(); if (color != null) { plot.setBackgroundPaint(color); } Float alpha; if ((alpha = comp.getBackgroundAlpha()) != null) { plot.setBackgroundAlpha(alpha); } if ((alpha = comp.getForegroundAlpha()) != null) { plot.setForegroundAlpha(alpha); } image = loadImage(comp.getPlotImage()); if (image != null) { plot.setBackgroundImage(image); plot.setBackgroundImageAlignment(getImageAlign(comp.getPlotImagePosition())); plot.setBackgroundImageAlpha(comp.getBackgroundImageAlpha()); } Paint[] colorPalette = comp.getColorPalette(); if (colorPalette != null) { plot.setDrawingSupplier(new CustomDrawingSupplier(colorPalette)); } else { plot.setDrawingSupplier(new CustomDrawingSupplier()); } }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void setChartBackgroundImage(JFreeChart jfreeChart, Image defaultBackgroundImage, Integer defaultBackgroundImageAlignment, Float defaultBackgroundImageAlpha) { if (defaultBackgroundImage != null) { jfreeChart.setBackgroundImage(defaultBackgroundImage); if (defaultBackgroundImageAlignment != null) { jfreeChart.setBackgroundImageAlignment(defaultBackgroundImageAlignment.intValue()); }// w w w .j a v a2 s . c om if (defaultBackgroundImageAlpha != null) { jfreeChart.setBackgroundImageAlpha(defaultBackgroundImageAlpha.floatValue()); } } }
From source file:org.gbif.portal.web.controller.dataset.IndexingHistoryController.java
/** * Create a time series graphic to display indexing processes. * /*from w ww . j av a 2 s . co m*/ * @param dataProvider * @param dataResource * @param activities * @param fileNamePrefix * @return */ public String timeSeriesTest(DataProviderDTO dataProvider, DataResourceDTO dataResource, List<LoggedActivityDTO> loggedActivities, String fileNamePrefix, int minProcessingTimeToRender) { List<LoggedActivityDTO> activities = new ArrayList<LoggedActivityDTO>(); for (LoggedActivityDTO la : loggedActivities) { if (la.getDataResourceKey() != null && la.getDataResourceName() != null && la.getEventName() != null) activities.add(la); } //if no activities to render, return if (activities.isEmpty()) return null; Map<String, Integer> drActualCount = new HashMap<String, Integer>(); Map<String, Integer> drCount = new HashMap<String, Integer>(); //record the actual counts for (LoggedActivityDTO laDTO : activities) { if (laDTO.getStartDate() != null && laDTO.getEndDate() != null && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) { if (drActualCount.get(laDTO.getDataResourceName()) == null) { drActualCount.put(laDTO.getDataResourceName(), new Integer(4)); drCount.put(laDTO.getDataResourceName(), new Integer(0)); } else { Integer theCount = drActualCount.get(laDTO.getDataResourceName()); theCount = new Integer(theCount.intValue() + 4); drActualCount.remove(laDTO.getDataResourceName()); drActualCount.put(laDTO.getDataResourceName(), theCount); } } } StringBuffer fileNameBuffer = new StringBuffer(fileNamePrefix); if (dataResource != null) { fileNameBuffer.append("-resource-"); fileNameBuffer.append(dataResource.getKey()); } else if (dataProvider != null) { fileNameBuffer.append("-provider-"); fileNameBuffer.append(dataProvider.getKey()); } fileNameBuffer.append(".png"); String fileName = fileNameBuffer.toString(); String filePath = System.getProperty("java.io.tmpdir") + File.separator + fileName; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName; } TimeSeriesCollection dataset = new TimeSeriesCollection(); boolean generateChart = false; int count = 1; int dataResourceCount = 1; Collections.sort(activities, new Comparator<LoggedActivityDTO>() { public int compare(LoggedActivityDTO o1, LoggedActivityDTO o2) { if (o1 == null || o2 == null || o1.getDataResourceKey() != null || o2.getDataResourceKey() != null) return -1; return o1.getDataResourceKey().compareTo(o2.getDataResourceKey()); } }); String currentDataResourceKey = activities.get(0).getDataResourceKey(); for (LoggedActivityDTO laDTO : activities) { if (laDTO.getStartDate() != null && laDTO.getEndDate() != null && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) { if (currentDataResourceKey != null && !currentDataResourceKey.equals(laDTO.getDataResourceKey())) { dataResourceCount++; count = count + 1; currentDataResourceKey = laDTO.getDataResourceKey(); } TimeSeries s1 = new TimeSeries(laDTO.getDataResourceName(), "Process time period", laDTO.getEventName(), Hour.class); s1.add(new Hour(laDTO.getStartDate()), count); s1.add(new Hour(laDTO.getEndDate()), count); dataset.addSeries(s1); generateChart = true; } } if (!generateChart) return null; // create a pie chart... final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = chart.getXYPlot(); plot.setWeight(10); plot.getRangeAxis().setAutoRange(false); plot.getRangeAxis().setRange(0, drCount.size() + 1); plot.getRangeAxis().setAxisLineVisible(false); plot.getRangeAxis().setAxisLinePaint(Color.WHITE); plot.setDomainCrosshairValue(1); plot.setRangeGridlinesVisible(false); plot.getRangeAxis().setVisible(false); plot.getRangeAxis().setLabel("datasets"); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setItemLabelsVisible(true); MyXYItemLabelGenerator labelGenerator = new MyXYItemLabelGenerator(); labelGenerator.setDataResourceActualCount(drActualCount); labelGenerator.setDataResourceCount(drCount); renderer.setItemLabelGenerator(labelGenerator); List<TimeSeries> seriesList = dataset.getSeries(); for (TimeSeries series : seriesList) { if (((String) series.getRangeDescription()).startsWith("extraction")) { renderer.setSeriesPaint(seriesList.indexOf(series), Color.RED); } else { renderer.setSeriesPaint(seriesList.indexOf(series), Color.BLUE); } renderer.setSeriesStroke(seriesList.indexOf(series), new BasicStroke(7f)); } int imageHeight = 30 * dataResourceCount; if (imageHeight < 100) { imageHeight = 100; } else { imageHeight = imageHeight + 100; } final BufferedImage image = new BufferedImage(900, imageHeight, 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, 900, imageHeight); // draw chart.draw(g2, chartArea, null, null); //styling chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); try { FileOutputStream fOut = new FileOutputStream(filePath); ChartUtilities.writeChartAsPNG(fOut, chart, 900, imageHeight); return fileName; } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
protected void setChartBackgroundImage(JFreeChart jfreeChart, Image defaultBackgroundImage, Integer defaultBackgroundImageAlignment, Float defaultBackgroundImageAlpha) { if (defaultBackgroundImage != null) { jfreeChart.setBackgroundImage(defaultBackgroundImage); if (defaultBackgroundImageAlignment != null) { jfreeChart.setBackgroundImageAlignment(defaultBackgroundImageAlignment); }// w w w. j av a2 s .co m if (defaultBackgroundImageAlpha != null) { jfreeChart.setBackgroundImageAlpha(defaultBackgroundImageAlpha); } } }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected void setChartBackgroundImage(JFreeChart jfreeChart) { ChartSettings chartSettings = getChartSettings(); Image backgroundImage = chartSettings.getBackgroundImage() == null ? null : chartSettings.getBackgroundImage().getImage(); if (backgroundImage != null) { jfreeChart.setBackgroundImage(backgroundImage); Integer backgroundImageAlignment = chartSettings.getBackgroundImageAlignment(); if (backgroundImageAlignment != null) { jfreeChart.setBackgroundImageAlignment(backgroundImageAlignment.intValue()); }// w ww. j a v a 2 s . co m Float backgroundImageAlpha = chartSettings.getBackgroundImageAlpha(); // if(getChart().getOwnMode() != null && getChart().getOwnMode().byteValue() == ModeEnum.TRANSPARENT) // { // backgroundImageAlpha = new Float(0); // } if (backgroundImageAlpha != null) { jfreeChart.setBackgroundImageAlpha(backgroundImageAlpha.floatValue()); } } }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
protected void setChartBackgroundImage(JFreeChart jfreeChart) { ChartSettings chartSettings = getChartSettings(); Image backgroundImage = chartSettings.getBackgroundImage() == null ? null : chartSettings.getBackgroundImage().getImage(getChartContext().getJasperReportsContext()); if (backgroundImage != null) { jfreeChart.setBackgroundImage(backgroundImage); Integer backgroundImageAlignment = chartSettings.getBackgroundImageAlignment(); if (backgroundImageAlignment != null) { jfreeChart.setBackgroundImageAlignment(backgroundImageAlignment); }/* w ww . ja va2 s. c o m*/ Float backgroundImageAlpha = chartSettings.getBackgroundImageAlpha(); // if (getChart().getOwnMode() != null && getChart().getOwnMode() == ModeEnum.TRANSPARENT) // { // backgroundImageAlpha = 0f; // } if (backgroundImageAlpha != null) { jfreeChart.setBackgroundImageAlpha(backgroundImageAlpha); } } }