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

The following examples show how to use org.jfree.chart.JFreeChart#setAntiAlias() . 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: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException
{	
	ChartSettings chartSettings = getChartSettings();
	setChartBackground(jfreeChart);
	setChartTitle(jfreeChart);
	setChartSubtitles(jfreeChart);
	setChartLegend(jfreeChart);
	setChartBorder(jfreeChart);
	
	Boolean chartAntiAlias = chartSettings.getAntiAlias();
	if (chartAntiAlias != null)
		jfreeChart.setAntiAlias(chartAntiAlias);
	
	Boolean textAntiAlias = chartSettings.getTextAntiAlias();
	if (textAntiAlias != null)
		jfreeChart.setTextAntiAlias((boolean)textAntiAlias);
	
	RectangleInsets padding = chartSettings.getPadding();
	if (padding != null)
	{
		jfreeChart.setPadding(padding);//FIXMETHEME consider using linebox
	}
	configurePlot(jfreeChart.getPlot(), jrPlot);
}
 
Example 3
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException
{	
	Integer defaultBaseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
	
	setChartBackground(jfreeChart);
	setChartTitle(jfreeChart, defaultBaseFontSize);
	setChartSubtitles(jfreeChart, defaultBaseFontSize);
	setChartLegend(jfreeChart, defaultBaseFontSize);
	setChartBorder(jfreeChart);
	
	Boolean isAntiAlias = (Boolean)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_ANTI_ALIAS);
	if (isAntiAlias != null)
		jfreeChart.setAntiAlias(isAntiAlias);
	
	Double padding = (Double)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_PADDING);
	UnitType unitType = (UnitType)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.UNIT_TYPE);
	if (padding != null && unitType != null)
	{
		jfreeChart.setPadding(new RectangleInsets(unitType, padding, padding, padding, padding));
	}
	configurePlot(jfreeChart.getPlot(), jrPlot);
}
 
Example 4
Source File: DefaultChartEditor.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the properties of a chart to match the properties defined on the
 * panel.
 *
 * @param chart  the chart.
 */
@Override
public void updateChart(JFreeChart chart) {
    this.titleEditor.setTitleProperties(chart);
    this.plotEditor.updatePlotProperties(chart.getPlot());
    chart.setAntiAlias(getAntiAlias());
    chart.setBackgroundPaint(getBackgroundPaint());
}
 
Example 5
Source File: DefaultChartEditor.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the properties of a chart to match the properties defined on the
 * panel.
 *
 * @param chart  the chart.
 */
@Override
public void updateChart(JFreeChart chart) {
    this.titleEditor.setTitleProperties(chart);
    this.plotEditor.updatePlotProperties(chart.getPlot());
    chart.setAntiAlias(getAntiAlias());
    chart.setBackgroundPaint(getBackgroundPaint());
}
 
Example 6
Source File: DefaultChartEditor.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the properties of a chart to match the properties defined on the
 * panel.
 *
 * @param chart  the chart.
 */
@Override
public void updateChart(JFreeChart chart) {
    this.titleEditor.setTitleProperties(chart);
    this.plotEditor.updatePlotProperties(chart.getPlot());
    chart.setAntiAlias(getAntiAlias());
    chart.setBackgroundPaint(getBackgroundPaint());
}
 
Example 7
Source File: DefaultChartEditor.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the properties of a chart to match the properties defined on the
 * panel.
 *
 * @param chart  the chart.
 */
@Override
public void updateChart(JFreeChart chart) {
    this.titleEditor.setTitleProperties(chart);
    this.plotEditor.updatePlotProperties(chart.getPlot());
    chart.setAntiAlias(getAntiAlias());
    chart.setBackgroundPaint(getBackgroundPaint());
}
 
Example 8
Source File: DefaultChartEditor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the properties of a chart to match the properties defined on the
 * panel.
 *
 * @param chart  the chart.
 */
public void updateChart(JFreeChart chart) {

    this.titleEditor.setTitleProperties(chart);
    this.plotEditor.updatePlotProperties(chart.getPlot());

    chart.setAntiAlias(getAntiAlias());
    chart.setBackgroundPaint(getBackgroundPaint());
}
 
Example 9
Source File: SWTOtherEditor.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the chart.
 *
 * @param chart  the chart.
 */
public void updateChartProperties(JFreeChart chart) {
    chart.setAntiAlias(this.antialias.getSelection());
    chart.setBackgroundPaint(SWTUtils.toAwtColor(
            this.backgroundPaintCanvas.getColor()));
}
 
Example 10
Source File: SWTOtherEditor.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the chart.
 *
 * @param chart  the chart.
 */
public void updateChartProperties(JFreeChart chart) {
    chart.setAntiAlias(this.antialias.getSelection());
    chart.setBackgroundPaint(SWTUtils.toAwtColor(
            this.backgroundPaintCanvas.getColor()));
}
 
Example 11
Source File: SWTOtherEditor.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Updates the chart.
 *
 * @param chart  the chart.
 */
public void updateChartProperties(JFreeChart chart) {
    chart.setAntiAlias(this.antialias.getSelection());
    chart.setBackgroundPaint(SWTUtils.toAwtColor(
            this.backgroundPaintCanvas.getColor()));
}
 
Example 12
Source File: JPanelAnalysisSpeed.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYAreaChart("",
			// x axis label
			bundle.getString("JPanelAnalysisSpeed.labelX"), // "Distance",
			// y axis label
			bundle.getString("JPanelAnalysisSpeed.labelY"), // "Speed"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	chart.setBackgroundPaint(Color.white); // Panel background color
	chart.setAntiAlias(true);

	XYPlot plot = chart.getXYPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis();
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);

	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 13
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] createToolAnalysisChart (int width, int height)
{
	CategoryDataset dataset = getToolAnalysisDataSet ();
	
	if (dataset == null) {
		return generateNoDataChart(width, height);
	}
			
	JFreeChart chart = ChartFactory.createBarChart (
			null, // chart title
			null, // domain axis label
			null, // range axis label
			dataset, // data
			PlotOrientation.HORIZONTAL, // the plot orientation
			false, // legend
			false, // tooltips
			false // urls
	);
	
	// set background
	chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ()));

	// set chart border
	chart.setPadding (new RectangleInsets (10, 5, 5, 5));
	chart.setBorderVisible (true);
	chart.setBorderPaint (parseColor ("#cccccc"));

	// set anti alias
	chart.setAntiAlias (true);

	CategoryPlot plot = (CategoryPlot) chart.getPlot ();

	// set transparency
	plot.setForegroundAlpha (0.7f);
	plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0));
	plot.setBackgroundPaint (Color.lightGray);
	plot.setDomainGridlinesVisible (false);
	plot.setRangeGridlinesVisible (true);
	plot.setRangeGridlinePaint (Color.white);
	
       CategoryAxis domainAxis = plot.getDomainAxis();
       domainAxis.setVisible(false);
       domainAxis.setUpperMargin (0);
       domainAxis.setLowerMargin (0);
       
       NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
       rangeAxis.setUpperMargin(0.20);
	rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());
       
       BarRenderer renderer = (BarRenderer) plot.getRenderer();
       CategoryItemLabelGenerator generator 
           = new StandardCategoryItemLabelGenerator("{1}", 
                   NumberFormat.getInstance(new ResourceLoader().getLocale()));
       renderer.setDefaultItemLabelGenerator(generator);
       renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 9));
       renderer.setDefaultItemLabelsVisible(true);
       renderer.setItemMargin (0);
       renderer.setSeriesPaint (0, Color.BLUE);
       
       BufferedImage img = chart.createBufferedImage (width, height);
	final ByteArrayOutputStream out = new ByteArrayOutputStream();
	try{
		ImageIO.write(img, "png", out);
	}catch(IOException e){
		log.warn("Error occurred while generating SiteStats chart image data", e);
	}
	return out.toByteArray();
}
 
Example 14
Source File: JPanelAnalysisTimeDist.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYAreaChart("",
			// x axis label
			bundle.getString("JPanelAnalysisTimeDist.labelX"), // "Distance"
			// y axis label
			bundle.getString("JPanelAnalysisTimeDist.labelY1"), // "Elevation"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	// -- Background color
	chart.setBackgroundPaint(Color.white);
	chart.setAntiAlias(true);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis(bundle.getString("JPanelAnalysisTimeDist.labelY2")); // "Time"
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);
	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 15
Source File: JPanelAnalysisTimeTemperature.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYLineChart("",
			// x axis label
			bundle.getString("JPanelAnalysisTimeDist.labelX"), // "Distance"
			// y axis label
			bundle.getString("JPanelAnalysisTimeDist.labelY1"), // "Elevation"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	// -- Background color
	chart.setBackgroundPaint(Color.white);
	chart.setAntiAlias(true);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis(bundle.getString("JPanelAnalysisTimeTemperature.labelY2")); // "Time"
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);
	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 16
Source File: SWTOtherEditor.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the chart.
 *
 * @param chart  the chart.
 */
public void updateChartProperties(JFreeChart chart) {
    chart.setAntiAlias(this.antialias.getSelection());
    chart.setBackgroundPaint(SWTUtils.toAwtColor(
            this.backgroundPaintCanvas.getColor()));
}
 
Example 17
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] generateLayeredBarChart (CategoryDataset dataset, int width, int height)
{
	JFreeChart chart = ChartFactory.createBarChart (null, // chart title
			null, // domain axis label
			null, // range axis label
			dataset, // data
			PlotOrientation.VERTICAL, // the plot orientation
			true, // legend
			true, // tooltips
			false // urls
			);

	// set background
	chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ()));

	// set chart border
	chart.setPadding (new RectangleInsets (10, 5, 5, 5));
	chart.setBorderVisible (true);
	chart.setBorderPaint (parseColor ("#cccccc"));

	// set anti alias
	chart.setAntiAlias (true);

	CategoryPlot plot = (CategoryPlot) chart.getPlot ();

	// disable bar outlines...
	LayeredBarRenderer renderer = new LayeredBarRenderer ();
	renderer.setDrawBarOutline (false);
	renderer.setSeriesBarWidth (0, .6);
	renderer.setSeriesBarWidth (1, .8);
	renderer.setSeriesBarWidth (2, 1.0);
	plot.setRenderer (renderer);

	// for this renderer, we need to draw the first series last...
	plot.setRowRenderingOrder (SortOrder.DESCENDING);

	// set up gradient paints for series...
	GradientPaint gp0 = new GradientPaint (0.0f, 0.0f, Color.blue, 0.0f,
			0.0f, new Color (0, 0, 64));
	GradientPaint gp1 = new GradientPaint (0.0f, 0.0f, Color.green, 0.0f,
			0.0f, new Color (0, 64, 0));
	GradientPaint gp2 = new GradientPaint (0.0f, 0.0f, Color.red, 0.0f,
			0.0f, new Color (64, 0, 0));
	renderer.setSeriesPaint (0, gp0);
	renderer.setSeriesPaint (1, gp1);
	renderer.setSeriesPaint (2, gp2);

	CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis ();
	domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45);
	domainAxis.setLowerMargin (0.0);
	domainAxis.setUpperMargin (0.0);

	BufferedImage img = chart.createBufferedImage (width, height);
	final ByteArrayOutputStream out = new ByteArrayOutputStream();
	try{
		ImageIO.write(img, "png", out);
	}catch(IOException e){
		log.warn("Error occurred while generating SiteStats chart image data", e);
	}
	return out.toByteArray();
}
 
Example 18
Source File: ChartServiceImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] generatePieChart(
		String siteId, PieDataset dataset, int width, int height,
		boolean render3d, float transparency,
		boolean smallFontInDomainAxis) {
	JFreeChart chart = null;
	if(render3d)
		chart = ChartFactory.createPieChart3D(null, dataset, false, false, false);
	else
		chart = ChartFactory.createPieChart(null, dataset, false, false, false);
	PiePlot plot = (PiePlot) chart.getPlot();
	
	// set start angle (135 or 150 deg so minor data has more space on the left)
	plot.setStartAngle(150D);
	
	// set transparency
	plot.setForegroundAlpha(transparency);
	
	// set background
	chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));
	plot.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));
	
	// fix border offset		
	chart.setPadding(new RectangleInsets(5,5,5,5));
	plot.setInsets(new RectangleInsets(1,1,1,1));
	// set chart border
	plot.setOutlinePaint(null);
	chart.setBorderVisible(true);
	chart.setBorderPaint(parseColor("#cccccc"));
	
	// set antialias
	chart.setAntiAlias(true);
	
	BufferedImage img = chart.createBufferedImage(width, height);
	final ByteArrayOutputStream out = new ByteArrayOutputStream();
	try{
		ImageIO.write(img, "png", out);
	}catch(IOException e){
		log.warn("Error occurred while generating SiteStats chart image data", e);
	}
	return out.toByteArray();
}
 
Example 19
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] generateStackedAreaChart (CategoryDataset dataset, int width, int height)
{
	JFreeChart chart = ChartFactory.createStackedAreaChart (null, // chart title
			null, // domain axis label
			null, // range axis label
			dataset, // data
			PlotOrientation.VERTICAL, // the plot orientation
			true, // legend
			true, // tooltips
			false // urls
			);

	// set background
	chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ()));

	// set chart border
	chart.setPadding (new RectangleInsets (10, 5, 5, 5));
	chart.setBorderVisible (true);
	chart.setBorderPaint (parseColor ("#cccccc"));

	// set anti alias
	chart.setAntiAlias (true);

	CategoryPlot plot = (CategoryPlot) chart.getPlot ();

	// set transparency
	plot.setForegroundAlpha (0.7f);
	plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0));
	plot.setBackgroundPaint (Color.lightGray);
	plot.setDomainGridlinesVisible (true);
	plot.setDomainGridlinePaint (Color.white);
	plot.setRangeGridlinesVisible (true);
	plot.setRangeGridlinePaint (Color.white);

	// set colour of regular users using Karate belt colour: white, green, blue, brown, black/gold
	CategoryItemRenderer renderer = plot.getRenderer ();
	renderer.setSeriesPaint (0, new Color (205, 173, 0)); // gold users
	renderer.setSeriesPaint (1, new Color (139, 69, 19));
	renderer.setSeriesPaint (2, Color.BLUE);
	renderer.setSeriesPaint (3, Color.GREEN);
	renderer.setSeriesPaint (4, Color.WHITE);

	// set the range axis to display integers only...
	NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis ();
	rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());

	CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis ();
	domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45);
       domainAxis.setLowerMargin(0.0);
       domainAxis.setUpperMargin(0.0);

       BufferedImage img = chart.createBufferedImage (width, height);
	final ByteArrayOutputStream out = new ByteArrayOutputStream();
	try{
		ImageIO.write(img, "png", out);
	}catch(IOException e){
		log.warn("Error occurred while generating SiteStats chart image data", e);
	}
	return out.toByteArray();
}
 
Example 20
Source File: SWTOtherEditor.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the chart.
 *
 * @param chart  the chart.
 */
public void updateChartProperties(JFreeChart chart) {
    chart.setAntiAlias(this.antialias.getSelection());
    chart.setBackgroundPaint(SWTUtils.toAwtColor(
            this.backgroundPaintCanvas.getColor()));
}