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

The following examples show how to use org.jfree.chart.plot.PiePlot#setShadowPaint() . 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: JFreeChartTest.java    From testarea-itext5 with GNU Affero General Public License v3.0 6 votes vote down vote up
public static JFreeChart generatePieChart()
{
    DefaultPieDataset dataSet = new DefaultPieDataset();
    dataSet.setValue("China", 30);
    dataSet.setValue("India", 30);
    dataSet.setValue("United States", 40);

    JFreeChart chart = ChartFactory.createPieChart("", dataSet, false, true, false);
    PiePlot piePlot = (PiePlot) chart.getPlot();
    piePlot.setBackgroundPaint(Color.WHITE); // set background color white
    piePlot.setOutlineVisible(false); // remove background border
    piePlot.setLabelGenerator(null); // remove pie section labels
    piePlot.setSectionPaint("China", Color.GRAY);
    piePlot.setSectionPaint("India", Color.GREEN);
    piePlot.setSectionPaint("United States", Color.BLUE);
    piePlot.setShadowPaint(Color.WHITE);

    return chart;
}
 
Example 2
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 3
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 4
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 );
  }

}
 
Example 5
Source File: MultiPieChartExpression.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 MultiplePiePlot mpp = (MultiplePiePlot) plot;
  final JFreeChart pc = mpp.getPieChart();
  configureSubChart( pc );

  final PiePlot pp = (PiePlot) pc.getPlot();
  if ( StringUtils.isEmpty( getTooltipFormula() ) == false ) {
    pp.setToolTipGenerator( new FormulaPieTooltipGenerator( getRuntime(), getTooltipFormula() ) );
  }
  if ( StringUtils.isEmpty( getUrlFormula() ) == false ) {
    pp.setURLGenerator( new FormulaPieURLGenerator( getRuntime(), getUrlFormula() ) );
  }

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

  final CategoryDataset c = mpp.getDataset();
  if ( c != null ) {
    final String[] colors = getSeriesColor();
    final int keysSize = c.getColumnKeys().size();
    for ( int i = 0; i < colors.length; i++ ) {
      if ( keysSize > i ) {
        pp.setSectionPaint( c.getColumnKey( i ), parseColorFromString( colors[ i ] ) );
      }
    }
  }

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

  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 );
    final FastDecimalFormat fastInteger = new FastDecimalFormat( FastDecimalFormat.TYPE_INTEGER, locale );

    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( multipieLabelFormat, numFormat, percentFormat );
    pp.setLabelGenerator( labelGen );
  }
}