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

The following examples show how to use org.jfree.chart.plot.PiePlot#setCircular() . 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: SWTPieChartDemo1.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
    
}
 
Example 2
Source File: SWTPieChartDemo1.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
    
}
 
Example 3
Source File: PieChartDemo1.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
    
}
 
Example 4
Source File: SWTPieChartDemo1.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;        
}
 
Example 5
Source File: SWTPieChartDemo1.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}
 
Example 6
Source File: SWTPieChartDemo1.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
    
}
 
Example 7
Source File: CommonPieChartAction.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
private void fillChart(String title, List<String> names, 
		List<String> colors, List<Float> values) throws Exception {
	DefaultPieDataset data=new DefaultPieDataset();
	for (int ix=0; ix<names.size(); ix++) {
		data.setValue( names.get(ix), values.get(ix) );
	}
       this.chart=ChartFactory.createPieChart3D(
       		title, 
       		data, 
       		true,
       		true, 
       		false);
       LegendTitle legend=this.chart.getLegend();
       legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9) );
       PiePlot plot=(PiePlot)this.chart.getPlot();
       plot.setCircular(true);
       plot.setBackgroundAlpha(0.9f);       
       plot.setForegroundAlpha(0.5f);
       plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9) );
       this.setPlotColor( plot, names, colors );
       this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9) ) ); 		
}
 
Example 8
Source File: SWTPieChartDemo1.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
    
}
 
Example 9
Source File: SWTPieChartDemo1.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
    
}
 
Example 10
Source File: RingChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public JFreeChart createChart(PieDataset pieDataSet, boolean createLegend) {
	JFreeChart chart = ChartFactory.createRingChart(null, pieDataSet, createLegend, // legend
			true, false);

	PiePlot plot = (PiePlot) chart.getPlot();
	plot.setSectionOutlinesVisible(false);
	plot.setLabelFont(FontTools.getFont(Font.SANS_SERIF, Font.PLAIN, 11));
	plot.setNoDataMessage("No data available");
	plot.setCircular(true);
	plot.setLabelGap(0.02);

	return chart;
}
 
Example 11
Source File: AegeanChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createPieChart() throws JRException
{
	JFreeChart jfreeChart = super.createPieChart();

	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();

	if(isShowLabels && piePlot.getLabelGenerator() != null)
	{
		piePlot.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
		piePlot.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
		piePlot.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
	}
	piePlot.setShadowXOffset(0);
	piePlot.setShadowYOffset(0);
	PieDataset pieDataset = piePlot.getDataset();
	if(pieDataset != null)
	{
		for(int i = 0; i < pieDataset.getItemCount(); i++)
		{
			piePlot.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
			
			//makes pie colors darker
			//piePlot.setSectionPaint(pieDataset.getKey(i), GRADIENT_PAINTS[i]);
		}
	}
	piePlot.setCircular(true);
	return jfreeChart;
}
 
Example 12
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createPieChart() throws JRException
{
	JFreeChart jfreeChart = super.createPieChart();
	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();

	if (isShowLabels && piePlot.getLabelGenerator() != null)
	{
		piePlot.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
		piePlot.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
		piePlot.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
	}
	piePlot.setShadowXOffset(5);
	piePlot.setShadowYOffset(10);
	piePlot.setShadowPaint(new GradientPaint(0, getChart().getHeight() / 2, new Color(41, 120, 162), 0, getChart().getHeight(), Color.white));
	PieDataset pieDataset = piePlot.getDataset();
	if (pieDataset != null)
	{
		for (int i = 0; i < pieDataset.getItemCount(); i++)
		{
			piePlot.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
			//makes pie colors darker
			//piePlot.setSectionPaint(pieDataset.getKey(i), GRADIENT_PAINTS[i]);
		}
	}
	
	piePlot.setCircular(true);
	return jfreeChart;
}
 
Example 13
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 14
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 15
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPieChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart, getPlot());
	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular();
	piePlot.setCircular(isCircular);

	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPiePlot.getItemLabel();
		if (labelGenerator != null)
		{
			piePlot.setLabelGenerator(labelGenerator);
		}
		else if (jrPiePlot.getLabelFormat() != null)
		{
			piePlot.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot.setLabelGenerator(
//					new StandardPieSectionLabelGenerator(itemLabel.getMask())
//					);
//		}
		
		if (itemLabel != null && itemLabel.getFont() != null)
		{
			piePlot.setLabelFont(getFontUtil().getAwtFont(itemLabel.getFont(), getLocale()));
		}
		else
		{
			piePlot.setLabelFont(getFontUtil().getAwtFont(new JRBaseFont(getChart(), null), getLocale()));
		}

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot.setLabelGenerator(null);
	}
	
	if (jrPiePlot.getLegendLabelFormat() != null)
	{
		piePlot.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(((JRPiePlot)getPlot()).getLegendLabelFormat(), 
					NumberFormat.getNumberInstance(getLocale()),
	                NumberFormat.getPercentInstance(getLocale()))
			);
	}
	
	return jfreeChart;
}
 
Example 16
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPieChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart, getPlot());
	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular();
	piePlot.setCircular(isCircular);

	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPiePlot.getItemLabel();

		if (labelGenerator != null)
		{
			piePlot.setLabelGenerator(labelGenerator);
		}
		else if (jrPiePlot.getLabelFormat() != null)
		{
			piePlot.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot.setLabelGenerator(
//					new StandardPieSectionLabelGenerator(itemLabel.getMask())
//					);
//
//		}

		Integer baseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
		JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null;
		
		piePlot.setLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize));

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot.setLabelGenerator(null);
	}
	
	
	if (jrPiePlot.getLegendLabelFormat() != null)
	{
		piePlot.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(jrPiePlot.getLegendLabelFormat(), 
					NumberFormat.getNumberInstance(getLocale()),
	                NumberFormat.getPercentInstance(getLocale()))
			);
	}
	
	return jfreeChart;
}
 
Example 17
Source File: DefaultChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPieChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart);
	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular();
	piePlot.setCircular(isCircular);

	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPiePlot.getItemLabel();
		if (labelGenerator != null)
		{
			piePlot.setLabelGenerator(labelGenerator);
		}
		else if (jrPiePlot.getLabelFormat() != null)
		{
			piePlot.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}// the default section label is just the key, so there's no need to set localized number formats
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot.setLabelGenerator(
//					new StandardPieSectionLabelGenerator(itemLabel.getMask())
//					);
//		}

		piePlot.setLabelFont(
			fontUtil.getAwtFont(
				getFont(itemLabel == null ? null : itemLabel.getFont()), 
				getLocale()
				)
			);

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot.setLabelGenerator(null);
	}
	
	if (jrPiePlot.getLegendLabelFormat() != null)
	{
		piePlot.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(jrPiePlot.getLegendLabelFormat(),
					NumberFormat.getNumberInstance(getLocale()),
					NumberFormat.getPercentInstance(getLocale()))
			);
	}// the default legend label is just the key, so there's no need to set localized number formats
	
	return jfreeChart;
}
 
Example 18
Source File: PieChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  super.configureChart( chart );

  final Plot plot = chart.getPlot();
  final PiePlot pp = (PiePlot) plot;
  final PieDataset pieDS = pp.getDataset();
  pp.setDirection( rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE );
  if ( ( explodeSegment != null ) && ( explodePct != null ) ) {
    configureExplode( pp );
  }
  if ( StringUtils.isEmpty( getTooltipFormula() ) == false ) {
    pp.setToolTipGenerator( new FormulaPieTooltipGenerator( getRuntime(), getTooltipFormula() ) );
  }
  if ( StringUtils.isEmpty( getUrlFormula() ) == false ) {
    pp.setURLGenerator( new FormulaPieURLGenerator( getRuntime(), getUrlFormula() ) );
  }

  pp.setIgnoreNullValues( ignoreNulls );
  pp.setIgnoreZeroValues( ignoreZeros );
  if ( Boolean.FALSE.equals( getItemsLabelVisible() ) ) {
    pp.setLabelGenerator( null );
  } else {
    final ExpressionRuntime runtime = getRuntime();
    final Locale locale = runtime.getResourceBundleFactory().getLocale();

    final FastDecimalFormat fastPercent = new FastDecimalFormat( FastDecimalFormat.TYPE_PERCENT, locale, true );
    final FastDecimalFormat fastInteger = new FastDecimalFormat( FastDecimalFormat.TYPE_INTEGER, locale, true );

    final DecimalFormat numFormat = new DecimalFormat( fastInteger.getPattern(), new DecimalFormatSymbols( locale ) );
    numFormat.setRoundingMode( RoundingMode.HALF_UP );

    final DecimalFormat percentFormat =
      new DecimalFormat( fastPercent.getPattern(), new DecimalFormatSymbols( locale ) );
    percentFormat.setRoundingMode( RoundingMode.HALF_UP );

    final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( pieLabelFormat,
      numFormat, percentFormat );
    pp.setLabelGenerator( labelGen );

    final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator( pieLegendLabelFormat,
      numFormat, percentFormat );
    pp.setLegendLabelGenerator( legendGen );
  }

  if ( StringUtils.isEmpty( getLabelFont() ) == false ) {
    pp.setLabelFont( Font.decode( getLabelFont() ) );
  }

  if ( pieDS != null ) {
    final String[] colors = getSeriesColor();
    for ( int i = 0; i < colors.length; i++ ) {
      if ( i < pieDS.getItemCount() ) {
        pp.setSectionPaint( pieDS.getKey( i ), parseColorFromString( colors[ i ] ) );
      } else {
        break;
      }
    }
  }

  if ( shadowPaint != null ) {
    pp.setShadowPaint( shadowPaint );
  }
  if ( shadowXOffset != null ) {
    pp.setShadowXOffset( shadowXOffset.doubleValue() );
  }
  if ( shadowYOffset != null ) {
    pp.setShadowYOffset( shadowYOffset.doubleValue() );
  }
  pp.setCircular( circular );

  if ( isShowBorder() == false || isChartSectionOutline() == false ) {
    chart.setBorderVisible( false );
    chart.getPlot().setOutlineVisible( false );
  }

}