List of usage examples for org.jfree.chart JFreeChart setBackgroundImage
public void setBackgroundImage(Image image)
From source file:sas.BarChart.java
public static JFreeChart createChart(CategoryDataset categorydataset, String name, String type, String t) { JFreeChart jfreechart = ChartFactory.createLineChart(name, null, type, categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.addSubtitle(new TextTitle(t)); TextTitle texttitle = new TextTitle(""); texttitle.setFont(new Font("SansSerif", 0, 10)); texttitle.setPosition(RectangleEdge.BOTTOM); texttitle.setHorizontalAlignment(HorizontalAlignment.CENTER); jfreechart.addSubtitle(texttitle);//w w w . ja va 2 s . co m CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinesVisible(false); java.net.URL url = (BarChart.class).getClassLoader().getResource("line_Chart_example.png"); if (url != null) { ImageIcon imageicon = new ImageIcon(url); jfreechart.setBackgroundImage(imageicon.getImage()); categoryplot.setBackgroundPaint(null); } NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartUtilities.applyCurrentTheme(jfreechart); LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setBaseFillPaint(Color.white); lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F)); lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F)); lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D)); return jfreechart; }
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);/*from ww w . ja v a 2 s. c om*/ 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:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample line chart. * * @return a line chart./* w w w . j a v a2 s.c o m*/ */ public JFreeChart createLineChart() { // create a default chart based on some sample data... final String title = this.resources.getString("other.line.title"); final String domain = this.resources.getString("other.line.domain"); final String range = this.resources.getString("other.line.range"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final JFreeChart chart = ChartFactory.createLineChart(title, domain, range, data, PlotOrientation.VERTICAL, true, true, false); // then customise it a little... chart.setBackgroundImage(JFreeChart.INFO.getLogo()); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green)); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundAlpha(0.65f); return chart; }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
protected void setChartStyles(JFreeChart chart, UIChart comp) { Plot plot = chart.getPlot();/*from www . ja v a 2s .c om*/ 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 o m*/ if (defaultBackgroundImageAlpha != null) { jfreeChart.setBackgroundImageAlpha(defaultBackgroundImageAlpha.floatValue()); } } }
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()); }//from w w w . jav a 2 s.c o 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:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
/** * Create a chart-object using dataset object. This method takes a dataset object, e.g. a DialWidgetDefinition, * and creates and returns a JFreeChart object from it. * //from w w w . j a va2 s .co m * @param dataset * The dataset * @param title * The title of the chart * @param units * The units of the chart value * @param width * The width of the image to create * @param height * The height of the image to create * @param logger * The logger to log any messages to * * @return JFreeChart the generated chart object */ public static JFreeChart getChart(final Dataset dataset, final String title, final String units, final int width, final int height, final ILogger logger) { JFreeChart chart = null; if (dataset instanceof DialWidgetDefinition) { chart = JFreeChartEngine.createDial((DialWidgetDefinition) dataset, title, units); } else if (dataset instanceof TimeSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createTimeSeriesCollectionChart((TimeSeriesCollectionChartDefinition) dataset); } else if (dataset instanceof TimeTableXYDatasetChartDefinition) { chart = JFreeChartEngine.createStackedTimeSeriesChart((TimeTableXYDatasetChartDefinition) dataset); } else if (dataset instanceof XYSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createXYSeriesCollectionChart((XYSeriesCollectionChartDefinition) dataset); } else if (dataset instanceof BarLineChartDefinition) { chart = JFreeChartEngine.createBarLineChart((BarLineChartDefinition) dataset); } else if (dataset instanceof CategoryDatasetChartDefinition) { chart = JFreeChartEngine.createCategoryDatasetChart((CategoryDatasetChartDefinition) dataset); } else if (dataset instanceof PieDatasetChartDefinition) { chart = JFreeChartEngine.createPieDatasetChart((PieDatasetChartDefinition) dataset); } else if (dataset instanceof XYZSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createXYZSeriesCollectionChart((XYZSeriesCollectionChartDefinition) dataset); } if (chart == null) { logger.error(Messages.getInstance().getString("ChartEngine.ERROR_0002_COULD_NOT_CREATE_CHART")); //$NON-NLS-1$ } else { // TODO implement the ability to have "ImageTitle"s for subtitles ChartDefinition chartDefinition = (ChartDefinition) dataset; Iterator iter = chartDefinition.getSubtitles().iterator(); while (iter.hasNext()) { chart.addSubtitle(new TextTitle(iter.next().toString())); } chart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint()); chart.setBackgroundImage(chartDefinition.getChartBackgroundImage()); chart.setBorderVisible(chartDefinition.isBorderVisible()); chart.setBorderPaint(chartDefinition.getBorderPaint()); if (chart.getTitle() != null) { chart.getTitle().setPosition(chartDefinition.getTitlePosition()); chart.getTitle().setFont(chartDefinition.getTitleFont()); } if (chartDefinition.getLegendFont() != null && chart.getLegend() != null) { chart.getLegend().setItemFont(chartDefinition.getLegendFont()); } if (!chartDefinition.isLegendBorderVisible() && chart.getLegend() != null) { chart.getLegend().setBorder(BlockBorder.NONE); } if (chartDefinition.getLegendPosition() != null && chart.getLegend() != null) { chart.getLegend().setPosition(chartDefinition.getLegendPosition()); } } return (chart); }
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); }//from w w w .j a va 2s . c om if (defaultBackgroundImageAlpha != null) { jfreeChart.setBackgroundImageAlpha(defaultBackgroundImageAlpha); } } }
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); }/*from ww w .j av a2s . c o m*/ Float backgroundImageAlpha = chartSettings.getBackgroundImageAlpha(); // if (getChart().getOwnMode() != null && getChart().getOwnMode() == ModeEnum.TRANSPARENT) // { // backgroundImageAlpha = 0f; // } if (backgroundImageAlpha != null) { jfreeChart.setBackgroundImageAlpha(backgroundImageAlpha); } } }