Java Code Examples for org.jfree.chart.plot.XYPlot#setForegroundAlpha()

The following examples show how to use org.jfree.chart.plot.XYPlot#setForegroundAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistogramChartFactory.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogram(XYSeries series, double barwidth, String yAxisLabel) {
  XYSeriesCollection xydata = new XYSeriesCollection(series);
  XYBarDataset dataset = new XYBarDataset(xydata, barwidth);
  JFreeChart chart = ChartFactory.createXYBarChart("", yAxisLabel, false, "n", dataset,
      PlotOrientation.VERTICAL, true, true, false);

  XYPlot xyplot = chart.getXYPlot();
  chart.setBackgroundPaint(new Color(230, 230, 230));
  chart.getLegend().setVisible(false);
  xyplot.setForegroundAlpha(0.7F);
  xyplot.setBackgroundPaint(Color.WHITE);
  xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
  xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
  xyplot.getDomainAxis().setVisible(true);
  xyplot.getRangeAxis().setVisible(yAxisLabel != null);
  XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
  xybarrenderer.setShadowVisible(false);
  xybarrenderer.setBarPainter(new StandardXYBarPainter());
  xybarrenderer.setDrawBarOutline(false);
  return chart;
}
 
Example 2
Source File: HistogramChartFactory.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 3
Source File: HistogramChartFactory.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogram(XYSeries series, double barwidth, String yAxisLabel) {
  XYSeriesCollection xydata = new XYSeriesCollection(series);
  XYBarDataset dataset = new XYBarDataset(xydata, barwidth);
  JFreeChart chart = ChartFactory.createXYBarChart("", yAxisLabel, false, "n", dataset,
      PlotOrientation.VERTICAL, true, true, false);

  XYPlot xyplot = chart.getXYPlot();
  chart.setBackgroundPaint(new Color(230, 230, 230));
  chart.getLegend().setVisible(false);
  xyplot.setForegroundAlpha(0.7F);
  xyplot.setBackgroundPaint(Color.WHITE);
  xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
  xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
  xyplot.getDomainAxis().setVisible(true);
  xyplot.getRangeAxis().setVisible(yAxisLabel != null);
  XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
  xybarrenderer.setShadowVisible(false);
  xybarrenderer.setBarPainter(new StandardXYBarPainter());
  xybarrenderer.setDrawBarOutline(false);
  return chart;
}
 
Example 4
Source File: HistogramChartFactory.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 5
Source File: HistogramChartFactory.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogram(XYSeries series, double barwidth, String yAxisLabel) {
  XYSeriesCollection xydata = new XYSeriesCollection(series);
  XYBarDataset dataset = new XYBarDataset(xydata, barwidth);
  JFreeChart chart = ChartFactory.createXYBarChart("", yAxisLabel, false, "n", dataset,
      PlotOrientation.VERTICAL, true, true, false);

  XYPlot xyplot = chart.getXYPlot();
  chart.setBackgroundPaint(new Color(230, 230, 230));
  chart.getLegend().setVisible(false);
  xyplot.setForegroundAlpha(0.7F);
  xyplot.setBackgroundPaint(Color.WHITE);
  xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
  xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
  xyplot.getDomainAxis().setVisible(true);
  xyplot.getRangeAxis().setVisible(yAxisLabel != null);
  XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
  xybarrenderer.setShadowVisible(false);
  xybarrenderer.setBarPainter(new StandardXYBarPainter());
  xybarrenderer.setDrawBarOutline(false);
  return chart;
}
 
Example 6
Source File: HistogramChartFactory.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 7
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an area chart using an {@link XYDataset}.
 * <P>
 * The chart object returned by this method uses an {@link XYPlot} instance
 * as the plot, with a {@link NumberAxis} for the domain axis, a
 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as
 * the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return An XY area chart.
 */
public static JFreeChart createXYAreaChart(String title, String xAxisLabel,
        String yAxisLabel, XYDataset dataset, boolean legend) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setForegroundAlpha(0.5f);
    XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    plot.setRenderer(renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 8
Source File: HistogramPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private ChartPanel createChartPanel(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();

    plot.setForegroundAlpha(0.85f);
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

    ChartPanel chartPanel = new ChartPanel(chart);

    MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this,
                                                                                     chartPanel,
                                                                                     "histogram_plot_area",
                                                                                     "Mask generated from selected histogram plot area",
                                                                                     Color.RED,
                                                                                     PlotAreaSelectionTool.AreaType.X_RANGE) {

        @Override
        protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) {
            Rectangle2D bounds = shape.getBounds2D();
            return createMaskExpression(bounds.getMinX(), bounds.getMaxX());
        }

        protected String createMaskExpression(double x1, double x2) {
            String bandName = BandArithmetic.createExternalName(getRaster().getName());
            HistogramPanelModel.HistogramConfig currentConfig = createHistogramConfig();
            return String.format("%s >= %s && %s <= %s",
                                 bandName,
                                 model.hasStx(currentConfig) ? model.getStx(currentConfig).getHistogramScaling().scaleInverse(x1) : x1,
                                 bandName,
                                 model.hasStx(currentConfig) ? model.getStx(currentConfig).getHistogramScaling().scaleInverse(x2) : x2);
        }
    };

    chartPanel.getPopupMenu().addSeparator();
    chartPanel.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem());
    chartPanel.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem());
    chartPanel.getPopupMenu().addSeparator();
    chartPanel.getPopupMenu().add(createCopyDataToClipboardMenuItem());
    return chartPanel;
}
 
Example 9
Source File: SimpleScatter.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public JFreeChart createChart(DatasetMap datasets) {

		DefaultXYDataset dataset=(DefaultXYDataset)datasets.getDatasets().get("1");

		JFreeChart chart = ChartFactory.createScatterPlot(
				name, yLabel, xLabel, dataset, 
				PlotOrientation.HORIZONTAL, false, true, false);

		Font font = new Font("Tahoma", Font.BOLD, titleDimension);
		//TextTitle title = new TextTitle(name, font);
		TextTitle title =setStyleTitle(name, styleTitle);
		chart.setTitle(title);
		chart.setBackgroundPaint(Color.white);
		if(subName!= null && !subName.equals("")){
			TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
			chart.addSubtitle(subTitle);
		}
		
		XYPlot plot = (XYPlot) chart.getPlot();
		plot.setForegroundAlpha(0.65f);

		XYItemRenderer renderer = plot.getRenderer();


		int seriesN=dataset.getSeriesCount();
		if(colorMap!=null){
			for (int i = 0; i < seriesN; i++) {
				String serieName=(String)dataset.getSeriesKey(i);
				Color color=(Color)colorMap.get(serieName);
				if(color!=null){
					renderer.setSeriesPaint(i, color);
				}	
			}
		}

		// increase the margins to account for the fact that the auto-range 
		// doesn't take into account the bubble size...
		NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
		domainAxis.setAutoRange(true);
		domainAxis.setRange(yMin, yMax);
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setAutoRange(true);
		rangeAxis.setRange(xMin,xMax);
		
		if(legend==true){
			drawLegend(chart);
		}
		return chart;
	}