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 + "%"))); } } }
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}"));
/** * 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; } }
/** * Returns JFree chart for dataset * * @param title * @param dataset * @return JFreeChart */ public static JFreeChart getPieChart(String title, DefaultPieDataset dataset) { JFreeChart pieChart = ChartFactory.createPieChart(title, dataset, true, // legend false, // tooltips false // URLs ); PiePlot plot = (PiePlot) pieChart.getPlot(); plot.setLabelGenerator(null); // green=passed, red=failed, grey=exception Color[] colors = { Color.GREEN, Color.RED, Color.GRAY }; PieChartColorRendererHelper renderer = new PieChartColorRendererHelper(colors); renderer.setColor(plot, dataset); return pieChart; }
private void initPlot(PiePlot plot, int chartType) { switch (chartType) { case TYPE_FISHEYE_PIE: //orient chart so labels will align nicely even if small slices of pie are present plot.setStartAngle(180); plot.setDirection(Rotation.ANTICLOCKWISE); break; case TYPE_CRUCIBLE_PIE: plot.setStartAngle(160); plot.setDirection(Rotation.CLOCKWISE); plot.setExplodePercent("Unreviewed", .25); plot.setLabelGenerator(null); break; default: } }
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; }
/** * @param showLabels <code>true</code> if labels are to be shown. */ public void setShowLabels(boolean showLabels) { this.showLabels = showLabels; Plot plot = chart.getPlot(); if(plot instanceof MultiplePiePlot) { PiePlot pieplot = (PiePlot)((MultiplePiePlot)plot).getPieChart().getPlot(); // ???? ChartLabelGenerator generator = new ChartLabelGenerator(ChartLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT); generator.setDefaultRenderer(Component.class, new AgentKeyRenderer()); pieplot.setLabelGenerator(showLabels ? generator : null); } if(plot instanceof CategoryPlot) { ((CategoryPlot)plot).getRenderer().setBaseItemLabelsVisible(showLabels); } }
@Override public JFreeChart createChart() { JFreeChart chart = null; PieDataset dataset = (PieDataset)dataset(); String name = stringValueForBinding("name", null); if("PieChart3D".equals(chartType())) { chart = ChartFactory.createPieChart3D(name,dataset,showLegends(),showToolTips(),showUrls()); } else if("RingChart".equals(chartType())) { chart = ChartFactory.createRingChart(name,dataset,showLegends(),showToolTips(),showUrls()); } else { chart = ChartFactory.createPieChart(name,dataset,showLegends(),showToolTips(),showUrls()); } if(!showLabels()) ((PiePlot) chart.getPlot()).setLabelGenerator(null); 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 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; }
/** * 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; }
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 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; }
plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) {
pieplot.setLabelGenerator(showLabels ? generator_advanced : null); pieplot.setToolTipGenerator(generator_advanced); pieplot.setIgnoreNullValues(true);
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; }