Java Code Examples for org.jfree.chart.JFreeChart#setBackgroundImageAlpha()

The following examples show how to use org.jfree.chart.JFreeChart#setBackgroundImageAlpha() . 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: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void setChartBackgroundImage(JFreeChart jfreeChart, 
		Image defaultBackgroundImage,
		Integer defaultBackgroundImageAlignment,
		Float defaultBackgroundImageAlpha)

{
	
	if (defaultBackgroundImage != null)
	{
		jfreeChart.setBackgroundImage(defaultBackgroundImage);
		if (defaultBackgroundImageAlignment != null)
		{
			jfreeChart.setBackgroundImageAlignment(defaultBackgroundImageAlignment);
		}
		if (defaultBackgroundImageAlpha != null)
		{
			jfreeChart.setBackgroundImageAlpha(defaultBackgroundImageAlpha);
		}
	}
}
 
Example 2
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
			}
			Float backgroundImageAlpha = chartSettings.getBackgroundImageAlpha();
//			if (getChart().getOwnMode() != null && getChart().getOwnMode() == ModeEnum.TRANSPARENT)
//			{
//				backgroundImageAlpha = 0f;
//			}
			if (backgroundImageAlpha != null)
			{
				jfreeChart.setBackgroundImageAlpha(backgroundImageAlpha);
			}
		}
	}
 
Example 3
Source File: NominalAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 * 
 * @return
 */
private JFreeChart createBarChart() {
	JFreeChart chart = ChartFactory.createBarChart(null, null, null, createBarDataset(), PlotOrientation.VERTICAL,
			false, false, false);
	AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	CategoryPlot plot = (CategoryPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	BarRenderer renderer = (BarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NOMINAL));
	renderer.setBarPainter(new StandardBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 4
Source File: BeltNominalColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createBarChart() {
	JFreeChart chart = ChartFactory.createBarChart(null, null, null, createBarDataset(), PlotOrientation.VERTICAL,
			false, false, false);
	setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	CategoryPlot plot = (CategoryPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	BarRenderer renderer = (BarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NOMINAL));
	renderer.setBarPainter(new StandardBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 5
Source File: BeltDateTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(final Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			PlotOrientation.VERTICAL, false, false, false);
	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;
}
 
Example 6
Source File: BeltNumericalColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			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.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 7
Source File: BeltTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(final Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			PlotOrientation.VERTICAL, false, false, false);
	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;
}
 
Example 8
Source File: DateTimeAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 *
 * @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;
}
 
Example 9
Source File: NumericalAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 *
 * @param exampleSet
 * @return
 */
private JFreeChart createHistogramChart(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.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 10
Source File: ChartExportUtil.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName, int resolution) throws IOException {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  if (((Color) saved).getAlpha() == 0) {
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(Color.WHITE);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);

    // apply bg
    chart.getPlot().setBackgroundPaint(Color.WHITE);
  }
  //
  if (resolution == 72)
    writeChartToJPEG(chart, width, height, fileName);
  else {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
    try {
      BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height,
          resolution, BufferedImage.TYPE_INT_RGB);
      EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
    } finally {
      out.close();
    }
  }
}
 
Example 11
Source File: ChartExportUtil.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName, int resolution) throws IOException {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  if (((Color) saved).getAlpha() == 0) {
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(Color.WHITE);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);

    // apply bg
    chart.getPlot().setBackgroundPaint(Color.WHITE);
  }
  //
  if (resolution == 72)
    writeChartToJPEG(chart, width, height, fileName);
  else {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
    try {
      BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height,
          resolution, BufferedImage.TYPE_INT_RGB);
      EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
    } finally {
      out.close();
    }
  }
}
 
Example 12
Source File: ChartExportUtil.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName, int resolution) throws IOException {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  if (((Color) saved).getAlpha() == 0) {
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(Color.WHITE);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);

    // apply bg
    chart.getPlot().setBackgroundPaint(Color.WHITE);
  }
  //
  if (resolution == 72)
    writeChartToJPEG(chart, width, height, fileName);
  else {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
    try {
      BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height,
          resolution, BufferedImage.TYPE_INT_RGB);
      EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
    } finally {
      out.close();
    }
  }
}
 
Example 13
Source File: ChartExportUtil.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
   * This method is used to save all image formats. it uses the specific methods for each file
   * format
   *
   * @param chart
   * @param sett
   * @param info
   */
  private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett,
      ChartRenderingInfo info) throws Exception {
    // Background color
    Paint saved = chart.getBackgroundPaint();
//    Color awtColor = FxColorUtil.fxColorToAWT(sett.getColorWithAlpha());
//    chart.setBackgroundPaint(awtColor);
//    chart.setBackgroundImageAlpha((float) sett.getTransparency());
//    if (chart.getLegend() != null)
//      chart.getLegend().setBackgroundPaint(awtColor);
    // legends and stuff
//    for (int i = 0; i < chart.getSubtitleCount(); i++)
//      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
//        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(awtColor);

    // apply bg
//    chart.getPlot().setBackgroundPaint(awtColor);

    // create folder
    File f = sett.getFullpath();
    if (!f.exists()) {
      if (f.getParentFile() != null) {
        f.getParentFile().mkdirs();
      }
      // f.createNewFile();
    }

    Dimension size = sett.getPixelSize();
    // Format
    switch (sett.getFormat()) {
      case "PDF":
        writeChartToPDF(chart, size.width, size.height, f);
        break;
      case "PNG":
        writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI());
        break;
      case "JPG":
        writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI());
        break;
      case "EPS":
        writeChartToEPS(chart, size.width, size.height, f);
        break;
      case "SVG":
        writeChartToSVG(chart, size.width, size.height, f);
        break;
      case "EMF":
        writeChartToEMF(chart, size.width, size.height, f);
        break;
    }
    //
    chart.setBackgroundPaint(saved);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(saved);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved);

    // apply bg
    chart.getPlot().setBackgroundPaint(saved);
  }
 
Example 14
Source File: ChartExportUtil.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is used to save all image formats. it uses the specific methods for each file
 * format
 * 
 * @param chart
 * @param sett
 * @param chartRenderingInfo
 */
private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett,
    ChartRenderingInfo info) throws Exception {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  chart.setBackgroundPaint(sett.getColorWithAlpha());
  chart.setBackgroundImageAlpha((float) sett.getTransparency());
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(sett.getColorWithAlpha());
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(sett.getColorWithAlpha());

  // apply bg
  chart.getPlot().setBackgroundPaint(sett.getColorWithAlpha());

  // create folder
  File f = sett.getFullpath();
  if (!f.exists()) {
    if (f.getParentFile() != null)
      f.getParentFile().mkdirs();
    // f.createNewFile();
  }

  Dimension size = sett.getPixelSize();
  // Format
  switch (sett.getFormat()) {
    case "PDF":
      writeChartToPDF(chart, size.width, size.height, f);
      break;
    case "PNG":
      writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "JPG":
      writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "EPS":
      writeChartToEPS(chart, size.width, size.height, f);
      break;
    case "SVG":
      writeChartToSVG(chart, size.width, size.height, f);
      break;
    case "EMF":
      writeChartToEMF(chart, size.width, size.height, f);
      break;
  }
  //
  chart.setBackgroundPaint(saved);
  chart.setBackgroundImageAlpha(255);
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(saved);
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved);

  // apply bg
  chart.getPlot().setBackgroundPaint(saved);
}
 
Example 15
Source File: ChartExportUtil.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is used to save all image formats. it uses the specific methods for each file
 * format
 * 
 * @param chart
 * @param sett
 * @param chartRenderingInfo
 */
private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett,
    ChartRenderingInfo info) throws Exception {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  chart.setBackgroundPaint(sett.getColorWithAlpha());
  chart.setBackgroundImageAlpha((float) sett.getTransparency());
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(sett.getColorWithAlpha());
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(sett.getColorWithAlpha());

  // apply bg
  chart.getPlot().setBackgroundPaint(sett.getColorWithAlpha());

  // create folder
  File f = sett.getFullpath();
  if (!f.exists()) {
    if (f.getParentFile() != null)
      f.getParentFile().mkdirs();
    // f.createNewFile();
  }

  Dimension size = sett.getPixelSize();
  // Format
  switch (sett.getFormat()) {
    case "PDF":
      writeChartToPDF(chart, size.width, size.height, f);
      break;
    case "PNG":
      writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "JPG":
      writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "EPS":
      writeChartToEPS(chart, size.width, size.height, f);
      break;
    case "SVG":
      writeChartToSVG(chart, size.width, size.height, f);
      break;
    case "EMF":
      writeChartToEMF(chart, size.width, size.height, f);
      break;
  }
  //
  chart.setBackgroundPaint(saved);
  chart.setBackgroundImageAlpha(255);
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(saved);
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved);

  // apply bg
  chart.getPlot().setBackgroundPaint(saved);
}