public static void setPieRadius(JFreeChart chart, double radius) { if (chart != null) { Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot) plot; double ig = 1.0 - radius; if (ig > PiePlot.MAX_INTERIOR_GAP) { ig = PiePlot.MAX_INTERIOR_GAP; } piePlot.setInteriorGap(ig); } } }
pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); pieplot.setSimpleLabels(true); pieplot.setInteriorGap(0.0D);
public JFreeChart createPieChart(String title, PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setCircular(true); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage("No data to display"); StandardPieSectionLabelGenerator labelGenerator = new StandardPieSectionLabelGenerator("{0} {1} ({2})"); plot.setLabelGenerator(labelGenerator); plot.setInteriorGap(0.01); plot.setMaximumLabelWidth(0.32); Font font = new Font(chart.getLegend().getItemFont().getFamily(), Font.PLAIN, 12); plot.setLabelFont(font); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); font = new Font(chart.getLegend().getItemFont().getFamily(), Font.PLAIN, 12); chart.getLegend().setItemFont(font); return chart; }
/** * Creates a pie chart. * * @return A pie chart. */ private static JFreeChart createPieChart() { JFreeChart chart = ChartFactory.createPieChart(null, null, false, true, false); chart.setBackgroundPaint(Color.white); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setInteriorGap(0.06); plot.setStartAngle(0.0); plot.setLabelGenerator(null); plot.setBaseSectionOutlinePaint(Color.white); plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); plot.setOutlineVisible(false); plot.setLabelBackgroundPaint(null); plot.setLabelOutlinePaint(null); plot.setLabelShadowPaint(null); plot.setLabelPadding(RectangleInsets.ZERO_INSETS); plot.setLabelFont(new Font("Dialog", Font.PLAIN, 12)); plot.setLabelPaint(Color.gray); plot.setToolTipGenerator(new StandardPieToolTipGenerator("{2}")); return chart; }
PiePlot pie = (PiePlot) plot; PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition; pie.setInteriorGap( pieDefinition.getInteriorGap() ); pie.setStartAngle( pieDefinition.getStartAngle() ); pie.setLabelFont( pieDefinition.getLabelFont() );