Java Code Examples for org.jfree.chart.ChartFactory#createPieChart3D()

The following examples show how to use org.jfree.chart.ChartFactory#createPieChart3D() . 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: PiePlot3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
public void testDrawWithNullDataset() {
    JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true);
    boolean success = false; 
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example 2
Source File: OrdersChartPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JFreeChart initChart() {
	
	JFreeChart chart=null ;
	try {
		if(PropertyUtils.getProperty(new OrderEntry(), p) instanceof Date)
		{
			chart = ChartFactory.createTimeSeriesChart("Orders", "Date", "Value", getTimeDataSet(), true, true,false);

		}
		else
		{
			chart = ChartFactory.createPieChart3D("Orders", getPieDataSet(), false, true, true);
			PiePlot plot = (PiePlot) chart.getPlot();
			PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"),new DecimalFormat("0.00%"));
			plot.setLabelGenerator(generator);
				
		}
	} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		logger.error(e);
	}
	return chart;
}
 
Example 3
Source File: MultiAPIChartDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
   * Creates a sample chart.
   *
   * @return A chart.
   */
  private JFreeChart createChart(final int year)
  {

    final JFreeChart chart = ChartFactory.createPieChart3D(
        "Programming Language of the Year " + year, // chart title
        createSampleDataset(), // data
        true, // include legend
        true,
        false
    );

    // set the background color for the chart...
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
//    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");

    return chart;

  }
 
Example 4
Source File: PiePlot3DTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
@Test
public void testDrawWithNullDataset() {
    JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true,
            false, false);
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example 5
Source File: PiePlot3DTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
@Test
public void testDrawWithNullDataset() {
    JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true,
            false, false);
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example 6
Source File: PiePlot3DTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
@Test
public void testDrawWithNullDataset() {
    JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true,
            false, false);
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
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: PiePlot3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
public void testDrawWithNullDataset() {
    JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true, 
            false, false);
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100, 
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example 9
Source File: MultiExtXmlChartDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
   * Creates a sample chart.
   *
   * @return A chart.
   */
  private JFreeChart createChart(final int year)
  {

    final JFreeChart chart = ChartFactory.createPieChart3D(
        "Programming Language of the Year " + year, // chart title
        createSampleDataset(), // data
        true, // include legend
        true,
        false
    );

    // set the background color for the chart...
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
//    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");

    return chart;

  }
 
Example 10
Source File: BasicSimpleXmlChartDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return A chart.
   */
  private JFreeChart createChart(final PieDataset dataset)
  {

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

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.yellow);
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
//    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");

    return chart;

  }
 
Example 11
Source File: PieChart3DPlotter.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.createPieChart3D(null, pieDataSet, createLegend, // legend
			true, false);

	PiePlot3D plot = (PiePlot3D) chart.getPlot();
	plot.setForegroundAlpha(0.5f);

	return chart;
}
 
Example 12
Source File: ChartJFreeChartOutputPie.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void createChart(final IScope scope) {
	super.createChart(scope);
	if (style.equals(IKeyword.THREE_D)) {
		chart = ChartFactory.createPieChart3D(getName(), null, false, true, false);
	} else if (style.equals(IKeyword.RING)) {
		chart = ChartFactory.createRingChart(getName(), null, false, true, false);
	} else {
		chart = ChartFactory.createPieChart(getName(), null, false, true, false);
	}
}
 
Example 13
Source File: TransitionsPieChart.java    From osmo with GNU Lesser General Public License v2.1 5 votes vote down vote up
private JFreeChart createChart(String title) {
  JFreeChart chart = ChartFactory.createPieChart3D(title, data, true, true, false);
  PiePlot3D plot = (PiePlot3D) chart.getPlot();
  plot.setStartAngle(290);
  plot.setDirection(Rotation.CLOCKWISE);
  plot.setForegroundAlpha(0.5f);
  return chart;
}
 
Example 14
Source File: PieChart3DTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a pie chart.
 *
 * @param dataset  the dataset.
 * 
 * @return The pie chart.
 */
private static JFreeChart createPieChart3D(PieDataset dataset) {

    return ChartFactory.createPieChart3D(
        "Pie Chart",  // chart title
        dataset,      // data
        true,         // include legend
        true,
        false
    );
}
 
Example 15
Source File: JFreeChartScriptlet.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void afterReportInit() throws JRScriptletException
{
	DefaultPieDataset dataset = new DefaultPieDataset();
	dataset.setValue("Java", 43.2d);
	dataset.setValue("Visual Basic", 10.0d);
	dataset.setValue("C/C++", 17.5d);
	dataset.setValue("PHP", 32.5d);
	dataset.setValue("Perl", 1.0d);

	JFreeChart chart = 
		ChartFactory.createPieChart3D(
			"Pie Chart 3D Demo 1",
			dataset,
			true,
			true,
			false
			);

	PiePlot3D plot = (PiePlot3D) chart.getPlot();
	plot.setStartAngle(290);
	plot.setDirection(Rotation.CLOCKWISE);
	plot.setForegroundAlpha(0.5f);
	plot.setNoDataMessage("No data to display");

	/*   */
	this.setVariableValue("Chart", new JCommonDrawableRendererImpl(chart));
}
 
Example 16
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 17
Source File: PieChartTab.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
   * Create a PieChart view that displays the data in a particular column.
   *
   * @param model Data source.
   * @param column Index of the column to collate.
   */
  public PieChartTab(MonitorModel model, int column) {
      super(model, false, ImageLoader.getNewIcon(MonitorWindow.PIE_ICON));

      String title = model.getName() + " - " + model.getColumnName(column);
      setName(title);

      pieModel = new TablePieDataset(model, column);

      chart = ChartFactory.createPieChart3D(null, pieModel, true, true, false);
      chart.setBackgroundPaint(getBackground());

      pieModel.calculate();

      // 2015-10-18 Changed to 3D pie
      final PiePlot3D plot = (PiePlot3D)chart.getPlot();

      //plot.setCircular(false);
      //plot.setRadius(0.60);
      //plot.setSectionLabelType(PiePlot.PERCENT_LABELS);

      plot.setStartAngle(270);
      plot.setDirection(Rotation.ANTICLOCKWISE);
      plot.setForegroundAlpha(0.6f);
      //plot.setInteriorGap(0.33);

      pieModel.addChangeListener(plot);

      chartpanel = new ChartPanel(chart, true);

      // 2015-10-18 Added setting below to keep the aspect ratio of 8:5
      // see http://www.jfree.org/forum/viewtopic.php?f=3&t=115763
      // Chart will always be drawn to an off-screen buffer that is the same size as the ChartPanel, so no scaling will happen when the offscreen image is copied to the panel.
      chartpanel.setPreferredSize(new Dimension (800, 300));
      chartpanel.setMinimumDrawWidth(0);
      chartpanel.setMaximumDrawWidth(Integer.MAX_VALUE);
      chartpanel.setMinimumDrawHeight(0);
      chartpanel.setMaximumDrawHeight(Integer.MAX_VALUE);

JPanel fixedSizePane = new JPanel(new FlowLayout());
fixedSizePane.add(chartpanel);
fixedSizePane.addComponentListener(new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent e) {
          	int w = fixedSizePane.getWidth();
              int h = fixedSizePane.getHeight();
              int size =  Math.min(w, h);
              int newWidth = (int) (size *8D/3D);
              chartpanel.setPreferredSize(new Dimension(newWidth, size));
              fixedSizePane.revalidate();
          }
      });

      add(fixedSizePane, BorderLayout.CENTER);

      // 2015-10-18 Added rotator code
      final Rotator rotator = new Rotator(plot);
      rotator.start();
//System.out.println("PieChartTab : just done calling constructor");
  }
 
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: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPie3DChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart3D(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart, getPlot());

	PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPie3DPlot jrPie3DPlot = (JRPie3DPlot)getPlot();
	double depthFactor = jrPie3DPlot.getDepthFactorDouble() == null ? JRPie3DPlot.DEPTH_FACTOR_DEFAULT : jrPie3DPlot.getDepthFactorDouble();
	boolean isCircular =  jrPie3DPlot.getCircular() == null ? false : jrPie3DPlot.getCircular();
	piePlot3D.setDepthFactor(depthFactor);
	piePlot3D.setCircular(isCircular);

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

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

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot3D.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot3D.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot3D.setLabelGenerator(null);
	}

	if (jrPie3DPlot.getLegendLabelFormat() != null)
	{
		piePlot3D.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(jrPie3DPlot.getLegendLabelFormat(), 
					NumberFormat.getNumberInstance(getLocale()),
	                NumberFormat.getPercentInstance(getLocale()))
			);
	}
	
	return jfreeChart;
}
 
Example 20
Source File: PieChart3DTests.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a pie chart.
 *
 * @param dataset  the dataset.
 *
 * @return The pie chart.
 */
private static JFreeChart createPieChart3D(PieDataset dataset) {
    return ChartFactory.createPieChart3D("Pie Chart", dataset, true);
}