Java Code Examples for org.jfree.chart.plot.Plot#setBackgroundPaint()

The following examples show how to use org.jfree.chart.plot.Plot#setBackgroundPaint() . 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: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets basic configuration including title font, subtitle, background paint and
 * anti-alias on the given JFreeChart.
 */
private void setBasicConfig( JFreeChart jFreeChart, BaseChart chart )
{
    jFreeChart.getTitle().setFont( TITLE_FONT );

    jFreeChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    jFreeChart.setAntiAlias( true );

    if ( !chart.isHideTitle() )
    {
        jFreeChart.addSubtitle( getSubTitle( chart ) );
    }

    Plot plot = jFreeChart.getPlot();
    plot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    plot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR );
}
 
Example 2
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets basic configuration including title font, subtitle, background paint and
 * anti-alias on the given JFreeChart.
 */
private void setBasicConfig( JFreeChart jFreeChart, final Visualization visualization )
{
    jFreeChart.getTitle().setFont( TITLE_FONT );

    jFreeChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    jFreeChart.setAntiAlias( true );

    if ( !visualization.isHideTitle() )
    {
        jFreeChart.addSubtitle( getSubTitle( visualization ) );
    }

    Plot plot = jFreeChart.getPlot();
    plot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    plot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR );
}
 
Example 3
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Sets all the format options on the given chart like fonts, chart title, legend, legend
 * position etc.
 */
private void formatChart(JFreeChart chart) {
	Plot plot = chart.getPlot();
	PlotConfiguration currentPlotConfigurationClone = plotInstance.getCurrentPlotConfigurationClone();

	// set plot background color
	plot.setBackgroundPaint(currentPlotConfigurationClone.getPlotBackgroundColor());

	formatLegend(chart);

	// set chart background color
	chart.setBackgroundPaint(currentPlotConfigurationClone.getChartBackgroundColor());

	// add title to chart
	String text = currentPlotConfigurationClone.getTitleText();
	if (text == null) {
		chart.setTitle(text);
	} else {
		Font font = currentPlotConfigurationClone.getTitleFont();
		if (font == null) {
			font = FontTools.getFont(Font.DIALOG, Font.PLAIN, 10);
		}

		TextTitle textTitle = new TextTitle(text, font);
		textTitle.setPaint(currentPlotConfigurationClone.getTitleColor());

		chart.setTitle(textTitle);
	}
}
 
Example 4
Source File: MemInfo.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
private JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "", "", xydataset, true,
        true, false);
    Plot plot = (Plot) jfreechart.getPlot();
    xyplot = jfreechart.getXYPlot();
    // 纵坐标设定
    valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    valueaxis.setFixedAutoRange(60000D);
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 1048576D);
    plot.setBackgroundPaint(Color.black);
    return jfreechart;
}
 
Example 5
Source File: CpuInfo.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
private JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "", "", xydataset, true,
        true, false);
    Plot plot = (Plot) jfreechart.getPlot();
    xyplot = jfreechart.getXYPlot();
    // 纵坐标设定
    valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    valueaxis.setFixedAutoRange(60000D);
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 100D);
    plot.setBackgroundPaint(Color.black);
    return jfreechart;
}
 
Example 6
Source File: FpsInfo.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
private JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "", "", xydataset, true,
        true, false);
    Plot plot = (Plot) jfreechart.getPlot();
    xyplot = jfreechart.getXYPlot();
    // 纵坐标设定
    valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    valueaxis.setFixedAutoRange(60000D);
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 20D);
    plot.setBackgroundPaint(Color.black);
    return jfreechart;
}
 
Example 7
Source File: StandardChartTheme.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the attributes of this theme to a plot.
 *
 * @param plot  the plot (<code>null</code>).
 */
protected void applyToPlot(Plot plot) {
    ParamChecks.nullNotPermitted(plot, "plot");
    if (plot.getDrawingSupplier() != null) {
        plot.setDrawingSupplier(getDrawingSupplier());
    }
    if (plot.getBackgroundPaint() != null) {
        plot.setBackgroundPaint(this.plotBackgroundPaint);
    }
    plot.setOutlinePaint(this.plotOutlinePaint);

    // now handle specific plot types (and yes, I know this is some
    // really ugly code that has to be manually updated any time a new
    // plot type is added - I should have written something much cooler,
    // but I didn't and neither did anyone else).
    if (plot instanceof PiePlot) {
        applyToPiePlot((PiePlot) plot);
    }
    else if (plot instanceof MultiplePiePlot) {
        applyToMultiplePiePlot((MultiplePiePlot) plot);
    }
    else if (plot instanceof CategoryPlot) {
        applyToCategoryPlot((CategoryPlot) plot);
    }
    else if (plot instanceof XYPlot) {
        applyToXYPlot((XYPlot) plot);
    }
    else if (plot instanceof FastScatterPlot) {
        applyToFastScatterPlot((FastScatterPlot) plot);
    }
    else if (plot instanceof MeterPlot) {
        applyToMeterPlot((MeterPlot) plot);
    }
    else if (plot instanceof ThermometerPlot) {
        applyToThermometerPlot((ThermometerPlot) plot);
    }
    else if (plot instanceof SpiderWebPlot) {
        applyToSpiderWebPlot((SpiderWebPlot) plot);
    }
    else if (plot instanceof PolarPlot) {
        applyToPolarPlot((PolarPlot) plot);
    }
}
 
Example 8
Source File: StandardChartTheme.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the attributes of this theme to a plot.
 *
 * @param plot  the plot (<code>null</code>).
 */
protected void applyToPlot(Plot plot) {
    ParamChecks.nullNotPermitted(plot, "plot");
    if (plot.getDrawingSupplier() != null) {
        plot.setDrawingSupplier(getDrawingSupplier());
    }
    if (plot.getBackgroundPaint() != null) {
        plot.setBackgroundPaint(this.plotBackgroundPaint);
    }
    plot.setOutlinePaint(this.plotOutlinePaint);

    // now handle specific plot types (and yes, I know this is some
    // really ugly code that has to be manually updated any time a new
    // plot type is added - I should have written something much cooler,
    // but I didn't and neither did anyone else).
    if (plot instanceof PiePlot) {
        applyToPiePlot((PiePlot) plot);
    }
    else if (plot instanceof MultiplePiePlot) {
        applyToMultiplePiePlot((MultiplePiePlot) plot);
    }
    else if (plot instanceof CategoryPlot) {
        applyToCategoryPlot((CategoryPlot) plot);
    }
    else if (plot instanceof XYPlot) {
        applyToXYPlot((XYPlot) plot);
    }
    else if (plot instanceof FastScatterPlot) {
        applyToFastScatterPlot((FastScatterPlot) plot);
    }
    else if (plot instanceof MeterPlot) {
        applyToMeterPlot((MeterPlot) plot);
    }
    else if (plot instanceof ThermometerPlot) {
        applyToThermometerPlot((ThermometerPlot) plot);
    }
    else if (plot instanceof SpiderWebPlot) {
        applyToSpiderWebPlot((SpiderWebPlot) plot);
    }
    else if (plot instanceof PolarPlot) {
        applyToPolarPlot((PolarPlot) plot);
    }
}
 
Example 9
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void setPlotBackground(Plot p, JRChartPlot jrPlot)
{
	Paint defaultBackgroundPaint = (Paint)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_BACKGROUND_PAINT);
	Float defaultBackgroundAlpha = (Float)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_BACKGROUND_ALPHA);
	Float defaultForegroundAlpha = (Float)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_FOREGROUND_ALPHA);
	
	Image defaultBackgroundImage = (Image)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_BACKGROUND_IMAGE);
	Integer defaultBackgroundImageAlignment = (Integer)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_BACKGROUND_IMAGE_ALIGNMENT);
	Float defaultBackgroundImageAlpha = (Float)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_BACKGROUND_IMAGE_ALPHA);

	Paint backgroundPaint = jrPlot.getOwnBackcolor() != null ? jrPlot.getOwnBackcolor() : defaultBackgroundPaint;
	if (backgroundPaint != null)
	{
		p.setBackgroundPaint(backgroundPaint);
	}
	
	Float backgroundAlpha = jrPlot.getBackgroundAlphaFloat() != null ? 
			jrPlot.getBackgroundAlphaFloat() : 
			defaultBackgroundAlpha;
	if (backgroundAlpha != null)
		p.setBackgroundAlpha(backgroundAlpha);
	
	Float foregroundAlpha = jrPlot.getForegroundAlphaFloat() != null ? 
			jrPlot.getForegroundAlphaFloat() : 
			defaultForegroundAlpha;
	if (foregroundAlpha != null)
		p.setForegroundAlpha(foregroundAlpha);
	
	if (defaultBackgroundImage != null)
	{
		p.setBackgroundImage(defaultBackgroundImage);
		if (defaultBackgroundImageAlignment != null)
		{
			p.setBackgroundImageAlignment(defaultBackgroundImageAlignment);
		}
		if (defaultBackgroundImageAlpha != null)
		{
			p.setBackgroundImageAlpha(defaultBackgroundImageAlpha);
		}
	}
	
}
 
Example 10
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void setPlotBackground(Plot plot, JRChartPlot jrPlot)
{
	PlotSettings plotSettings = getPlotSettings();
	Paint backgroundPaint = jrPlot.getOwnBackcolor();
	if (backgroundPaint == null && plotSettings.getBackgroundPaint() != null)
	{
		backgroundPaint = plotSettings.getBackgroundPaint().getPaint();
	}
	if (backgroundPaint == null)
	{
		backgroundPaint = ChartThemesConstants.TRANSPARENT_PAINT;
	}
	plot.setBackgroundPaint(backgroundPaint);
	
	Float backgroundAlpha = jrPlot.getBackgroundAlphaFloat();
	if (backgroundAlpha == null)
	{
		backgroundAlpha = plotSettings.getBackgroundAlpha();
	}
	if (backgroundAlpha != null)
		plot.setBackgroundAlpha(backgroundAlpha);
	
	Float foregroundAlpha = jrPlot.getForegroundAlphaFloat();
	if (foregroundAlpha == null)
	{
		foregroundAlpha = plotSettings.getForegroundAlpha();
	}
	if (foregroundAlpha != null)
		plot.setForegroundAlpha(foregroundAlpha);
	
	Image backgroundImage = plotSettings.getBackgroundImage() == null ? null : plotSettings.getBackgroundImage().getImage(getChartContext().getJasperReportsContext());
	if (backgroundImage != null)
	{
		plot.setBackgroundImage(backgroundImage);
		Integer backgroundImageAlignment = plotSettings.getBackgroundImageAlignment();
		if (backgroundImageAlignment != null)
		{
			plot.setBackgroundImageAlignment(backgroundImageAlignment);
		}
		Float backgroundImageAlpha = plotSettings.getBackgroundImageAlpha();
		if (backgroundImageAlpha != null)
		{
			plot.setBackgroundImageAlpha(backgroundImageAlpha);
		}
	}
}
 
Example 11
Source File: StandardChartTheme.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the attributes of this theme to a plot.
 *
 * @param plot  the plot (<code>null</code>).
 */
protected void applyToPlot(Plot plot) {
    ParamChecks.nullNotPermitted(plot, "plot");
    if (plot.getDrawingSupplier() != null) {
        plot.setDrawingSupplier(getDrawingSupplier());
    }
    if (plot.getBackgroundPaint() != null) {
        plot.setBackgroundPaint(this.plotBackgroundPaint);
    }
    plot.setOutlinePaint(this.plotOutlinePaint);

    // now handle specific plot types (and yes, I know this is some
    // really ugly code that has to be manually updated any time a new
    // plot type is added - I should have written something much cooler,
    // but I didn't and neither did anyone else).
    if (plot instanceof PiePlot) {
        applyToPiePlot((PiePlot) plot);
    }
    else if (plot instanceof MultiplePiePlot) {
        applyToMultiplePiePlot((MultiplePiePlot) plot);
    }
    else if (plot instanceof CategoryPlot) {
        applyToCategoryPlot((CategoryPlot) plot);
    }
    else if (plot instanceof XYPlot) {
        applyToXYPlot((XYPlot) plot);
    }
    else if (plot instanceof FastScatterPlot) {
        applyToFastScatterPlot((FastScatterPlot) plot);
    }
    else if (plot instanceof MeterPlot) {
        applyToMeterPlot((MeterPlot) plot);
    }
    else if (plot instanceof ThermometerPlot) {
        applyToThermometerPlot((ThermometerPlot) plot);
    }
    else if (plot instanceof SpiderWebPlot) {
        applyToSpiderWebPlot((SpiderWebPlot) plot);
    }
    else if (plot instanceof PolarPlot) {
        applyToPolarPlot((PolarPlot) plot);
    }
}
 
Example 12
Source File: ChartJFreeChartOutput.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initChart(final IScope scope, final String chartname) {
	super.initChart(scope, chartname);

	initRenderer(scope);
	final Plot plot = chart.getPlot();

	chart.setBorderVisible(false);
	plot.setOutlineVisible(false);
	chart.setTitle(this.getName());
	chart.getTitle().setVisible(true);
	chart.getTitle().setFont(getTitleFont());
	if (!this.getTitleVisible(scope)) {
		chart.getTitle().setVisible(false);
	}
	if (textColor != null) {
		chart.getTitle().setPaint(textColor);
	}

	if (backgroundColor == null) {
		plot.setBackgroundPaint(null);
		chart.setBackgroundPaint(null);
		chart.setBorderPaint(null);
		if (chart.getLegend() != null) {
			chart.getLegend().setBackgroundPaint(null);
		}
	} else {
		final Color bg = backgroundColor;
		chart.setBackgroundPaint(bg);
		plot.setBackgroundPaint(bg);
		chart.setBorderPaint(bg);
		if (chart.getLegend() != null) {
			chart.getLegend().setBackgroundPaint(bg);
		}
	}
	if (chart.getLegend() != null) {
		chart.getLegend().setItemFont(getLegendFont());
		chart.getLegend().setFrame(BlockBorder.NONE);
		if (textColor != null) {
			chart.getLegend().setItemPaint(textColor);
		}
	}

	chart.addProgressListener(this);

}
 
Example 13
Source File: StandardChartTheme.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Applies the attributes of this theme to a plot.
 *
 * @param plot  the plot (<code>null</code>).
 */
protected void applyToPlot(Plot plot) {
    ParamChecks.nullNotPermitted(plot, "plot");
    if (plot.getDrawingSupplier() != null) {
        plot.setDrawingSupplier(getDrawingSupplier());
    }
    if (plot.getBackgroundPaint() != null) {
        plot.setBackgroundPaint(this.plotBackgroundPaint);
    }
    plot.setOutlinePaint(this.plotOutlinePaint);

    // now handle specific plot types (and yes, I know this is some
    // really ugly code that has to be manually updated any time a new
    // plot type is added - I should have written something much cooler,
    // but I didn't and neither did anyone else).
    if (plot instanceof PiePlot) {
        applyToPiePlot((PiePlot) plot);
    }
    else if (plot instanceof MultiplePiePlot) {
        applyToMultiplePiePlot((MultiplePiePlot) plot);
    }
    else if (plot instanceof CategoryPlot) {
        applyToCategoryPlot((CategoryPlot) plot);
    }
    else if (plot instanceof XYPlot) {
        applyToXYPlot((XYPlot) plot);
    }
    else if (plot instanceof FastScatterPlot) {
        applyToFastScatterPlot((FastScatterPlot) plot);
    }
    else if (plot instanceof MeterPlot) {
        applyToMeterPlot((MeterPlot) plot);
    }
    else if (plot instanceof ThermometerPlot) {
        applyToThermometerPlot((ThermometerPlot) plot);
    }
    else if (plot instanceof SpiderWebPlot) {
        applyToSpiderWebPlot((SpiderWebPlot) plot);
    }
    else if (plot instanceof PolarPlot) {
        applyToPolarPlot((PolarPlot) plot);
    }
}
 
Example 14
Source File: StandardChartTheme.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Applies the attributes of this theme to a plot.
 *
 * @param plot  the plot (<code>null</code>).
 */
protected void applyToPlot(Plot plot) {
    if (plot == null) {
        throw new IllegalArgumentException("Null 'plot' argument.");
    }
    if (plot.getDrawingSupplier() != null) {
        plot.setDrawingSupplier(getDrawingSupplier());
    }
    if (plot.getBackgroundPaint() != null) {
        plot.setBackgroundPaint(this.plotBackgroundPaint);
    }
    plot.setOutlinePaint(this.plotOutlinePaint);

    // now handle specific plot types (and yes, I know this is some
    // really ugly code that has to be manually updated any time a new
    // plot type is added - I should have written something much cooler,
    // but I didn't and neither did anyone else).
    if (plot instanceof PiePlot) {
        applyToPiePlot((PiePlot) plot);
    }
    else if (plot instanceof MultiplePiePlot) {
        applyToMultiplePiePlot((MultiplePiePlot) plot);
    }
    else if (plot instanceof CategoryPlot) {
        applyToCategoryPlot((CategoryPlot) plot);
    }
    else if (plot instanceof XYPlot) {
        applyToXYPlot((XYPlot) plot);
    }
    else if (plot instanceof FastScatterPlot) {
        applyToFastScatterPlot((FastScatterPlot) plot);
    }
    else if (plot instanceof MeterPlot) {
        applyToMeterPlot((MeterPlot) plot);
    }
    else if (plot instanceof ThermometerPlot) {
        applyToThermometerPlot((ThermometerPlot) plot);
    }
    else if (plot instanceof SpiderWebPlot) {
        applyToSpiderWebPlot((SpiderWebPlot) plot);
    }
    else if (plot instanceof PolarPlot) {
        applyToPolarPlot((PolarPlot) plot);
    }
}
 
Example 15
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the attributes of this theme to a plot.
 *
 * @param plot  the plot (<code>null</code>).
 */
protected void applyToPlot(Plot plot) {
    ParamChecks.nullNotPermitted(plot, "plot");
    if (plot.getDrawingSupplier() != null) {
        plot.setDrawingSupplier(getDrawingSupplier());
    }
    if (plot.getBackgroundPaint() != null) {
        plot.setBackgroundPaint(this.plotBackgroundPaint);
    }
    plot.setOutlinePaint(this.plotOutlinePaint);

    // now handle specific plot types (and yes, I know this is some
    // really ugly code that has to be manually updated any time a new
    // plot type is added - I should have written something much cooler,
    // but I didn't and neither did anyone else).
    if (plot instanceof PiePlot) {
        applyToPiePlot((PiePlot) plot);
    }
    else if (plot instanceof MultiplePiePlot) {
        applyToMultiplePiePlot((MultiplePiePlot) plot);
    }
    else if (plot instanceof CategoryPlot) {
        applyToCategoryPlot((CategoryPlot) plot);
    }
    else if (plot instanceof XYPlot) {
        applyToXYPlot((XYPlot) plot);
    }
    else if (plot instanceof FastScatterPlot) {
        applyToFastScatterPlot((FastScatterPlot) plot);
    }
    else if (plot instanceof MeterPlot) {
        applyToMeterPlot((MeterPlot) plot);
    }
    else if (plot instanceof ThermometerPlot) {
        applyToThermometerPlot((ThermometerPlot) plot);
    }
    else if (plot instanceof SpiderWebPlot) {
        applyToSpiderWebPlot((SpiderWebPlot) plot);
    }
    else if (plot instanceof PolarPlot) {
        applyToPolarPlot((PolarPlot) plot);
    }
}
 
Example 16
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the attributes of this theme to a plot.
 *
 * @param plot  the plot (<code>null</code>).
 */
protected void applyToPlot(Plot plot) {
    ParamChecks.nullNotPermitted(plot, "plot");
    if (plot.getDrawingSupplier() != null) {
        plot.setDrawingSupplier(getDrawingSupplier());
    }
    if (plot.getBackgroundPaint() != null) {
        plot.setBackgroundPaint(this.plotBackgroundPaint);
    }
    plot.setOutlinePaint(this.plotOutlinePaint);

    // now handle specific plot types (and yes, I know this is some
    // really ugly code that has to be manually updated any time a new
    // plot type is added - I should have written something much cooler,
    // but I didn't and neither did anyone else).
    if (plot instanceof PiePlot) {
        applyToPiePlot((PiePlot) plot);
    }
    else if (plot instanceof MultiplePiePlot) {
        applyToMultiplePiePlot((MultiplePiePlot) plot);
    }
    else if (plot instanceof CategoryPlot) {
        applyToCategoryPlot((CategoryPlot) plot);
    }
    else if (plot instanceof XYPlot) {
        applyToXYPlot((XYPlot) plot);
    }
    else if (plot instanceof FastScatterPlot) {
        applyToFastScatterPlot((FastScatterPlot) plot);
    }
    else if (plot instanceof MeterPlot) {
        applyToMeterPlot((MeterPlot) plot);
    }
    else if (plot instanceof ThermometerPlot) {
        applyToThermometerPlot((ThermometerPlot) plot);
    }
    else if (plot instanceof SpiderWebPlot) {
        applyToSpiderWebPlot((SpiderWebPlot) plot);
    }
    else if (plot instanceof PolarPlot) {
        applyToPolarPlot((PolarPlot) plot);
    }
}