plot.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator( "{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(gen);
PiePlot plot = (PiePlot) chart.getPlot(); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {2}"));
PieSectionLabelGenerator labelGenerator = new StandardPieSectionLabelGenerator("{0} = {1}");
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}"));
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( "{0} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")) { @Override public String generateSectionLabel(PieDataset dataset, Comparable key) { if (key.equals("dormant")) { return null; } return super.generateSectionLabel(dataset, key); } };
PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} {2}"));
PiePlot plot = (PiePlot) chart.getPlot(); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0} = {1}"); plot.setLabelGenerator(gen);
PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} {2}"));
/** * {@inheritDoc} */ @Override public void customize(JFreeChart chart, ReportParameters reportParameters) { PiePlot plot = (PiePlot) chart.getPlot(); if (labelFormat == null) { plot.setLabelGenerator(null); } else { plot.setLabelGenerator(new StandardPieSectionLabelGenerator(labelFormat, new DecimalFormat(valuePattern), new DecimalFormat(percentValuePattern + "%"))); } } }
/** * Handle pie plot customization * - get customization parameters from parameter Map and modify plot accordingly * @param parameters macro parameters * @param plot chart plot */ void handlePiePlotCustomization(Map parameters, PiePlot plot) { // Pie section label customization String pieSectionLabel = getStringParameter(parameters, "piesectionlabel", "%0%") // default to just show key .replaceAll("%0%", "\\{0\\}") // convert to what jfreechart uses - unfortunately {and } cause problems in parameters .replaceAll("%1%", "\\{1\\}") .replaceAll("%2%", "\\{2\\}"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(pieSectionLabel)); // Pie section explode - just simple to start with, requires jfreechart 1.0.3 or above // - need a comma separated list of key=value pairs to support fully if (ChartUtil.isVersion103Capable()) { String pieSectionExplode = getStringParameter(parameters, "piesectionexplode", ""); // default to no key explode String explodeList[] = pieSectionExplode.split(","); for (String anExplodeList : explodeList) { if (StringUtils.isBlank(anExplodeList)) continue; /* Should skip if trimming string is blank */ try { plot.setExplodePercent(anExplodeList.trim(), DEFAULT_PIE_EXPLODE); } catch (Exception exception) { log.debug("Ignore errors"); } } } }
public class SO { public static void main(String[] args){ DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("JavaWorld", new Integer(75)); pieDataset.setValue("Other", new Integer(25)); JFreeChart chart = SO.createPieChart("Pie", pieDataset, new StandardPieSectionLabelGenerator()); JFrame frame = new JFrame("Pie"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new ChartPanel(chart)); frame.pack(); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); } public static JFreeChart createPieChart(final String title, final PieDataset dataset, PieSectionLabelGenerator labelGenerator) { final JFreeChart chart = ChartFactory.createPieChart(title, dataset, false, true, true); PiePlot plot = (PiePlot) chart.getPlot(); ChartUtil.formatPiePlot(plot); plot.setLabelGenerator(labelGenerator); PieRenderer renderer = new PieRenderer(); renderer.setColor((PiePlot) chart.getPlot(), dataset); return chart; } }
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 with default settings. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * * @param title the chart title ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param locale the locale ({@code null} not permitted). * * @return A pie chart. * * @since 1.0.7 */ public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a ring chart with default settings. * <P> * The chart object returned by this method uses a {@link RingPlot} * instance as the plot. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param locale the locale (<code>null</code> not permitted). * * @return A ring chart. * * @since 1.0.7 */ public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) { RingPlot plot = new RingPlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a ring chart with default settings. * <P> * The chart object returned by this method uses a {@link RingPlot} * instance as the plot. * * @param title the chart title ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param locale the locale ({@code null} not permitted). * * @return A ring chart. * * @since 1.0.7 */ public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) { RingPlot plot = new RingPlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a pie chart with default settings. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param locale the locale (<code>null</code> not permitted). * * @return A pie chart. * * @since 1.0.7 */ public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
public static ChartHelper generatePieChart(PieDataset dataset, String chartTitle, Color[][] colorScheme) { boolean legend = false; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createPieChart(chartTitle, dataset, legend, tooltips, urls); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(false); PiePlot plot = (PiePlot) chart.getPlot(); // Make section labels in the format "<Key>" plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); plot.setBackgroundPaint(Color.white); plot.setOutlinePaint(null); for(int i = 0; i < colorScheme.length; i++) { setSectionColor(dataset, plot, i, colorScheme[i][0], colorScheme[i][1]); } plot.setShadowXOffset(0); plot.setShadowYOffset(0); return new ChartHelper(chart); }
/** * Creates a ring chart with default settings. * <P> * The chart object returned by this method uses a {@link RingPlot} * instance as the plot. * * @param title the chart title ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A ring chart. */ public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls) { RingPlot plot = new RingPlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a pie chart with default settings. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * * @param title the chart title ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A pie chart. */ public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
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; }