Refine search
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; }
PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(Color.WHITE); plot.setCircular(true); plot.setDirection(Rotation.CLOCKWISE); plot.setIgnoreNullValues(true); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1}")); plot.setLabelGap(0.04); plot.setLabelBackgroundPaint(Color.WHITE); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} - {2})")); plot.setLegendItemShape(new Rectangle(0, 0, 10, 10));
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; }
Locale locale, boolean subTitle, boolean showDifference) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle);
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); }
JFreeChart chart = ChartFactory.createPieChart(null, dataset, false, false, false); chart.setBackgroundPaint(Color.white); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setDrawingSupplier(ds); plot.setLabelGenerator(new StandardPieSectionLabelGenerator( "{0} = {1} ({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance() ));
/** * 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; }
PiePlot plot = (PiePlot) someChart.getPlot(); plot.setSectionPaint(KEY1, Color.green); plot.setSectionPaint(KEY2, Color.red); plot.setExplodePercent(KEY1, 0.10); plot.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator( "{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(gen);
PiePlot pieplot = (PiePlot)chart.getPlot(); pieplot.setSectionPaint(api, palette.get(i%palette.size())); i++; pieplot.setNoDataMessage("No data available"); pieplot.setExplodePercent(topApi, 0.20000000000000001D); pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); pieplot.setLabelBackgroundPaint(new Color(220, 220, 220)); pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); pieplot.setSimpleLabels(true); pieplot.setInteriorGap(0.0D);
PiePlot piePlot = (PiePlot)jfreeChart.getPlot(); piePlot.setCircular(isCircular); if (labelGenerator != null) piePlot.setLabelGenerator(labelGenerator); piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator(jrPlot.getLabelFormat()) ); piePlot.setLegendLabelGenerator( new StandardPieSectionLabelGenerator(jrPlot.getLegendLabelFormat()) );
); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieSectionLabelGenerator( "{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance() ));
dataset.setValue("Low", new Integer(5)); JFreeChart chart = ChartFactory.createRingChart("", dataset, false, true, false); RingPlot pie = (RingPlot) chart.getPlot(); pie.setBackgroundPaint(Color.WHITE); pie.setOutlineVisible(false); pie.setShadowPaint(null); pie.setSimpleLabels(true); pie.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}")); pie.setSimpleLabelOffset(new RectangleInsets( UnitType.RELATIVE, 0.09, 0.09, 0.09, 0.09));
/** * 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; }
final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}"));
final PieSectionLabelGenerator labelGenerator = new StandardPieSectionLabelGenerator("{0} = {1}"); final PiePlot plot1 = (PiePlot) chart1.getPlot(); plot1.setLabelGenerator(labelGenerator); final PiePlot plot2 = (PiePlot) chart2.getPlot(); plot2.setExplodePercent("3", 0.25); plot2.setLabelGenerator(labelGenerator); final PiePlot3D plot3 = (PiePlot3D) chart3.getPlot(); plot3.setLabelGenerator(labelGenerator);
/** * {@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 pieplot = (PiePlot) plot; if (label != null) { pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator(label)); pieplot.setBaseSectionOutlinePaint(findColor(baseSectionOutlinePaint)); pieplot.setBaseSectionOutlineStroke(findStroke(baseSectionOutlineStroke));
PiePlot pie = (PiePlot) plot; PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition; pie.setInteriorGap( pieDefinition.getInteriorGap() ); pie.setStartAngle( pieDefinition.getStartAngle() ); pie.setLabelFont( pieDefinition.getLabelFont() ); if ( pieDefinition.getLabelPaint() != null ) { pie.setLabelPaint( pieDefinition.getLabelPaint() ); pie.setLabelBackgroundPaint( pieDefinition.getLabelBackgroundPaint() ); if ( pieDefinition.isLegendIncluded() ) { StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( "{0}" ); //$NON-NLS-1$ pie.setLegendLabelGenerator( labelGen ); } else { if ( pieDefinition.isLegendIncluded() ) { StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( "{1} ({2})" ); //$NON-NLS-1$ pie.setLabelGenerator( labelGen ); } else { StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( "{0} = {1} ({2})" ); //$NON-NLS-1$ pie.setLabelGenerator( labelGen );
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"); } } } }