Java Code Examples for org.jfree.chart.plot.PiePlot#setOutlinePaint()

The following examples show how to use org.jfree.chart.plot.PiePlot#setOutlinePaint() . 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: GraphStatsView.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Crée le graphe JFreeChart.
 *
 * @param piedataset
 *          : la source de données à afficher
 * @return le diagramme
 */
private JFreeChart createChart(GraphPieDataset piedataset) {
  JFreeChart jfreechart = ChartFactory.createPieChart3D(null, piedataset, false, true, false);
  jfreechart.setAntiAlias(true);
  jfreechart.setTextAntiAlias(true);

  PiePlot pieplot3d = (PiePlot) jfreechart.getPlot();
  pieplot3d.setInsets(new RectangleInsets(0, 0, 0, 0));
  final double angle = 290D;
  pieplot3d.setStartAngle(angle);
  pieplot3d.setDirection(Rotation.CLOCKWISE);
  final float foreground = 0.5F;
  pieplot3d.setForegroundAlpha(foreground);
  pieplot3d.setNoDataMessage(Messages.GraphStatsView_noDataToDisplay);
  pieplot3d.setCircular(true);

  pieplot3d.setOutlinePaint(null);
  pieplot3d.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
  pieplot3d.setLabelGap(0.02);
  pieplot3d.setLabelOutlinePaint(null);
  pieplot3d.setLabelShadowPaint(null);
  pieplot3d.setLabelBackgroundPaint(Color.WHITE);
  pieplot3d.setBackgroundPaint(Color.WHITE);
  // avoid showing the percentage as an absolute number in the tooltip
  pieplot3d.setToolTipGenerator(new StandardPieToolTipGenerator("{0}: {2}"));
  pieplot3d.setInteriorGap(0.02);
  pieplot3d.setMaximumLabelWidth(0.20);

  return jfreechart;
}
 
Example 2
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private JFreeChart getMultiplePieChart( BaseChart chart, CategoryDataset[] dataSets )
{
    JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( chart.getName(), dataSets[0], TableOrder.BY_ROW,
        !chart.isHideLegend(), false, false );

    setBasicConfig( multiplePieChart, chart );

    if ( multiplePieChart.getLegend() != null )
    {
        multiplePieChart.getLegend().setItemFont( SUB_TITLE_FONT );
    }

    MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
    JFreeChart pieChart = multiplePiePlot.getPieChart();
    pieChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    pieChart.getTitle().setFont( SUB_TITLE_FONT );

    PiePlot piePlot = (PiePlot) pieChart.getPlot();
    piePlot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    piePlot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR );
    piePlot.setLabelFont( LABEL_FONT );
    piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) );
    piePlot.setSimpleLabels( true );
    piePlot.setIgnoreZeroValues( true );
    piePlot.setIgnoreNullValues( true );
    piePlot.setShadowXOffset( 0d );
    piePlot.setShadowYOffset( 0d );

    for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
    {
        piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), COLORS[(i % COLORS.length)] );
    }

    return multiplePieChart;
}
 
Example 3
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private JFreeChart getMultiplePieChart( final Visualization visualization, CategoryDataset[] dataSets )
{
    JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( visualization.getName(), dataSets[0], TableOrder.BY_ROW,
        !visualization.isHideLegend(), false, false );

    setBasicConfig( multiplePieChart, visualization );

    if ( multiplePieChart.getLegend() != null )
    {
        multiplePieChart.getLegend().setItemFont( SUB_TITLE_FONT );
    }

    MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
    JFreeChart pieChart = multiplePiePlot.getPieChart();
    pieChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    pieChart.getTitle().setFont( SUB_TITLE_FONT );

    PiePlot piePlot = (PiePlot) pieChart.getPlot();
    piePlot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR );
    piePlot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR );
    piePlot.setLabelFont( LABEL_FONT );
    piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) );
    piePlot.setSimpleLabels( true );
    piePlot.setIgnoreZeroValues( true );
    piePlot.setIgnoreNullValues( true );
    piePlot.setShadowXOffset( 0d );
    piePlot.setShadowYOffset( 0d );

    for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
    {
        piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), COLORS[(i % COLORS.length)] );
    }

    return multiplePieChart;
}
 
Example 4
Source File: AbstractPieChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public void updatePlotter() {
	int categoryCount = prepareData();
	String maxClassesProperty = ParameterService
			.getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_LEGEND_CLASSLIMIT);
	int maxClasses = 20;
	try {
		if (maxClassesProperty != null) {
			maxClasses = Integer.parseInt(maxClassesProperty);
		}
	} catch (NumberFormatException e) {
		// LogService.getGlobal().log("Pie Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
		// LogService.WARNING);
		LogService.getRoot().log(Level.WARNING,
				"com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.pie_chart_plotter_parsing_error");
	}
	boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

	if (categoryCount <= MAX_CATEGORIES) {
		JFreeChart chart = createChart(pieDataSet, createLegend);

		// set the background color for the chart...
		chart.setBackgroundPaint(Color.white);

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

		plot.setBackgroundPaint(Color.WHITE);
		plot.setSectionOutlinesVisible(true);
		plot.setShadowPaint(new Color(104, 104, 104, 100));

		int size = pieDataSet.getKeys().size();
		for (int i = 0; i < size; i++) {
			Comparable<?> key = pieDataSet.getKey(i);
			plot.setSectionPaint(key, getColorProvider(true).getPointColor(i / (double) (size - 1)));

			boolean explode = false;
			for (String explosionGroup : explodingGroups) {
				if (key.toString().startsWith(explosionGroup) || explosionGroup.startsWith(key.toString())) {
					explode = true;
					break;
				}
			}

			if (explode) {
				plot.setExplodePercent(key, this.explodingAmount);
			}
		}

		plot.setLabelFont(LABEL_FONT);
		plot.setNoDataMessage("No data available");
		plot.setCircular(true);
		plot.setLabelGap(0.02);
		plot.setOutlinePaint(Color.WHITE);

		// legend settings
		LegendTitle legend = chart.getLegend();
		if (legend != null) {
			legend.setPosition(RectangleEdge.TOP);
			legend.setFrame(BlockBorder.NONE);
			legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
			legend.setItemFont(LABEL_FONT);
		}

		if (panel instanceof AbstractChartPanel) {
			panel.setChart(chart);
		} else {
			panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
			final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
			panel.addMouseListener(controller);
			panel.addMouseMotionListener(controller);
		}

		// ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
		panel.getChartRenderingInfo().setEntityCollection(null);
	} else {
		// LogService.getGlobal().logNote("Too many columns (" + categoryCount +
		// "), this chart is only able to plot up to " + MAX_CATEGORIES +
		// " different categories.");
		LogService.getRoot().log(Level.INFO,
				"com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.too_many_columns",
				new Object[] { categoryCount, MAX_CATEGORIES });
	}
}
 
Example 5
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 6
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();
}