List of usage examples for org.jfree.chart.plot PiePlot setMaximumLabelWidth
public void setMaximumLabelWidth(double width)
From source file:org.jfree.chart.demo.XYDrawableAnnotationDemo1.java
private static JFreeChart createPieChart() { DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("Engineering", 43.200000000000003D); defaultpiedataset.setValue("Research", 13.199999999999999D); defaultpiedataset.setValue("Advertising", 20.899999999999999D); PiePlot pieplot = new PiePlot(defaultpiedataset); pieplot.setBackgroundPaint(null);//ww w . j a va 2s . c om pieplot.setOutlinePaint(null); pieplot.setBaseSectionOutlinePaint(Color.white); pieplot.setBaseSectionOutlineStroke(new BasicStroke(2.0F)); pieplot.setLabelFont(new Font("Dialog", 0, 18)); pieplot.setMaximumLabelWidth(0.25D); JFreeChart jfreechart = new JFreeChart(pieplot); jfreechart.setBackgroundPaint(null); jfreechart.removeLegend(); jfreechart.setPadding(RectangleInsets.ZERO_INSETS); return jfreechart; }
From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java
private static JFreeChart createPieChart() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Engineering", 43.2); dataset.setValue("Research", 13.2); dataset.setValue("Advertising", 20.9); PiePlot plot = new PiePlot(dataset); plot.setBackgroundPainter(null);/*w ww. ja v a 2 s .c o m*/ plot.setBorderPainter(null); plot.setBaseSectionOutlinePaint(Color.white); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); plot.setLabelFont(new Font("Dialog", Font.PLAIN, 18)); plot.setMaximumLabelWidth(0.25); JFreeChart chart = new JFreeChart(plot); chart.setBackgroundPainter(null); chart.removeLegend(); chart.setPadding(RectangleInsets.ZERO_INSETS); return chart; }
From source file:org.jfree.chart.demo.MultiplePieChartDemo3.java
/** * Creates a sample chart for the given dataset. * /* ww w .j ava 2 s .c om*/ * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 3", dataset, TableOrder.BY_COLUMN, true, true, false); chart.setBackgroundPaint(new Color(216, 255, 216)); final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot(); final PiePlot p = (PiePlot) plot.getPieChart().getPlot(); p.setMaximumLabelWidth(0.35); p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9)); p.setInteriorGap(0.30); return chart; }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreePieChartData.java
@Override public JFreeChart getJFreeChart() { DefaultPieDataset pieDataset = makeDataSet(); JFreeChart chart = ChartFactory.createPieChart(title, // Title pieDataset, // Dataset true // Show legend , false, false);// w ww.j a v a 2 s . c o m PiePlot plot = (PiePlot) chart.getPlot(); StandardPieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0} ({2})"); plot.setLabelGenerator(gen); plot.setMaximumLabelWidth(0.07); plot.setLabelFont(plot.getLabelFont().deriveFont(9.0F)); LegendTitle leg = chart.getLegend(); leg.setPosition(RectangleEdge.RIGHT); if (!colours.isEmpty()) { String legends[] = ds.getLegends(); for (int i = 0; i < ds.getNumSets(); i++) { if (legends != null && legends.length > i && colours.size() > i) { Color c = colours.get(i); plot.setSectionPaint(legends[i], c); } } } return chart; }
From source file:org.jfree.chart.demo.MultiplePieChartDemo2.java
/** * Creates a sample chart with the given dataset. * /*from www .j a v a 2s. c o m*/ * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createMultiplePieChart("Multiple Pie Chart", // chart title dataset, // dataset TableOrder.BY_COLUMN, true, // include legend true, false); final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setOutlineStroke(new BasicStroke(1.0f)); final JFreeChart subchart = plot.getPieChart(); final PiePlot p = (PiePlot) subchart.getPlot(); p.setBackgroundPaint(null); p.setOutlineStroke(null); p.setLabelGenerator(new StandardPieItemLabelGenerator("{0} ({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); p.setMaximumLabelWidth(0.35); p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9)); p.setInteriorGap(0.30); return chart; }
From source file:jmemorize.gui.swing.panels.CardCounterPanel.java
private void setupPiePlot(PiePlot plot) { plot.setMaximumLabelWidth(0.0); plot.setLabelGap(0.0);/*from w ww. ja v a2 s. c o m*/ plot.setInteriorGap(0.0); //piePlot.setLabelLinkMargin(0.0); plot.setCircular(true); plot.setLabelGenerator(new PieSectionLabelGenerator() { public String generateSectionLabel(PieDataset arg0, Comparable arg1) { return null; } public AttributedString generateAttributedSectionLabel(PieDataset arg0, Comparable arg1) { return null; } }); //piePlot.setForegroundAlpha(0.5f); plot.setSectionPaint(Localization.get(LC.STATUS_LEARNED), ColorConstants.LEARNED_CARDS); plot.setSectionPaint(Localization.get(LC.STATUS_PARTIAL), ColorConstants.PARTIAL_LEARNED_CARDS); plot.setSectionPaint(Localization.get(LC.STATUS_UNLEARNED), ColorConstants.UNLEARNED_CARDS); }
From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java
/** * Creer camember3 d.//from w w w.j a v a 2 s. c o m * * @param title * the title * @param dataset * the dataset * @param legend * the legend * @param tooltips * the tooltips * @param urls * the urls * @return the j free chart * @throws FontFormatException * the font format exception * @throws IOException * Signals that an I/O exception has occurred. */ public static JFreeChart creerCamember3D(final String title, final DefaultPieDataset dataset, final boolean legend, final boolean tooltips, final boolean urls) throws FontFormatException, IOException { dataset.sortByValues(SortOrder.DESCENDING); final JFreeChart jfreeChart = ChartFactory.createPieChart3D(title, dataset, legend, tooltips, urls); jfreeChart.setBackgroundPaint(Color.white); jfreeChart.setBorderVisible(true); jfreeChart.getLegend().setPosition(RectangleEdge.LEFT); final GraphicsEnvironment graph = GraphicsEnvironment.getLocalGraphicsEnvironment(); final InputStream inputStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("hornet/framework/font/LiberationSans-Bold.ttf"); final Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream); graph.registerFont(font); jfreeChart.getLegend().setItemFont(new Font("Liberation Sans", Font.BOLD, 11)); jfreeChart.getLegend().setHeight(400); jfreeChart.getLegend().setBorder(0, 0, 0, 0); jfreeChart.setTitle(new TextTitle(title, new Font("Liberation Sans", Font.BOLD, 16))); final PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); final int nbData = dataset.getItemCount(); int cptColor = 0; for (int x = 0; x < nbData; x++) { if (cptColor >= listColor.size()) { cptColor = 0; } piePlot.setSectionPaint(dataset.getKey(x), listColor.get(cptColor)); cptColor++; } piePlot.setForegroundAlpha(0.5f); piePlot.setLabelFont(new Font("Liberation Sans", Font.BOLD, 12)); piePlot.setLabelOutlineStroke(null); piePlot.setLabelLinkStroke(new BasicStroke(0.4f)); piePlot.setLabelBackgroundPaint(Color.WHITE); piePlot.setLabelLinkStyle(PieLabelLinkStyle.STANDARD); piePlot.setBackgroundAlpha(0); piePlot.setOutlineVisible(false); piePlot.setForegroundAlpha(1); // transparence piePlot.setInteriorGap(0); // le camembert occupe plus de place piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}")); piePlot.setStartAngle(70); piePlot.setCircular(true); // force pour avoir un cercle et pas un oval piePlot.setMaximumLabelWidth(0.20); piePlot.setBaseSectionOutlinePaint(Color.BLACK); // bordure du camembert return jfreeChart; }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * /* w ww .ja v a2 s.co m*/ * DOC qiongli Comment method "decoratePiePlot". * * @param chart */ private static void decoratePiePlot(JFreeChart chart) { Font font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$ TextTitle textTitle = chart.getTitle(); // MOD msjian TDQ-5213 2012-5-7: fixed NPE if (textTitle != null) { textTitle.setFont(font); } setLegendFont(chart); // TDQ-5213~ PiePlot plot = (PiePlot) chart.getPlot(); font = new Font("Monospaced", Font.PLAIN, 10);//$NON-NLS-1$ plot.setLabelFont(font); plot.setNoDataMessage("No data available"); //$NON-NLS-1$ StandardPieSectionLabelGenerator standardPieSectionLabelGenerator = new StandardPieSectionLabelGenerator( ("{0}:{2}"), //$NON-NLS-1$ NumberFormat.getNumberInstance(), new DecimalFormat(PERCENT_FORMAT)); plot.setLabelGenerator(standardPieSectionLabelGenerator); plot.setLabelLinkPaint(Color.GRAY); plot.setLabelOutlinePaint(Color.WHITE); plot.setLabelGap(0.02D); plot.setOutlineVisible(false); plot.setMaximumLabelWidth(0.2D); plot.setCircular(false); // remove the shadow of the pie chart plot.setShadowXOffset(0); plot.setShadowYOffset(0); }
From source file:edu.gmu.cs.sim.util.media.chart.PieChartGenerator.java
protected void buildChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); chart = ChartFactory.createMultiplePieChart("Untitled Chart", dataset, org.jfree.util.TableOrder.BY_COLUMN, false, true, false);/*from w ww. j a v a 2s . co m*/ chart.setAntiAlias(true); //chartPanel = new ScrollableChartPanel(chart, true); chartPanel = buildChartPanel(chart); //chartHolder.getViewport().setView(chartPanel); setChartPanel(chartPanel); JFreeChart baseChart = (JFreeChart) ((MultiplePiePlot) (chart.getPlot())).getPieChart(); PiePlot base = (PiePlot) (baseChart.getPlot()); base.setIgnoreZeroValues(true); base.setLabelOutlinePaint(java.awt.Color.WHITE); base.setLabelShadowPaint(java.awt.Color.WHITE); base.setMaximumLabelWidth(0.25); // allow bigger labels by a bit (this will make the chart smaller) base.setInteriorGap(0.000); // allow stretch to compensate for the bigger label width base.setLabelBackgroundPaint(java.awt.Color.WHITE); base.setOutlinePaint(null); base.setBackgroundPaint(null); base.setShadowPaint(null); base.setSimpleLabels(false); // I think they're false anyway // change the look of the series title to be smaller StandardChartTheme theme = new StandardChartTheme("Hi"); TextTitle title = new TextTitle("Whatever", theme.getLargeFont()); title.setPaint(theme.getAxisLabelPaint()); title.setPosition(RectangleEdge.BOTTOM); baseChart.setTitle(title); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartPieGraphSource.java
@SuppressWarnings("unchecked") @Override/*from w ww. j ava2s . c o m*/ public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP); boolean graphDisplayLabel = getParam(GraphSource.GRAPH_DISPLAY_LABEL, Boolean.class, false); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); String noDataMessage = getParam(GraphSource.GRAPH_NO_DATA_MESSAGE, String.class, DEFAULT_GRAPH_NO_DATA_MESSAGE); PieGraphData pieGraphData = makeDataSet(); Map<Comparable, Paint> colors = pieGraphData.colors; this.chart = ChartFactory.createPieChart(title, pieGraphData.data, false, graphToolTip, false); Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Paint labelColor = getParam(JFreeChartTimeSeriesGraphSource.GRAPH_LABEL_BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); this.chart.setBackgroundPaint(backgroundColor); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(plotColor); plot.setNoDataMessage(noDataMessage); if (!graphDisplayLabel) { plot.setLabelGenerator(null); } else { plot.setInteriorGap(0.001); plot.setMaximumLabelWidth(.3); // plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setShadowPaint(null); // plot.setOutlineVisible(false); //TODO use title font? Font font = plot.getLabelFont(); plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE); plot.setLabelFont(font.deriveFont(font.getSize2D() * .75f)); plot.setLabelBackgroundPaint(labelColor); plot.setLabelShadowPaint(null); plot.setLabelOutlinePaint(null); plot.setLabelGap(0.001); plot.setLabelLinkMargin(0.0); plot.setLabelLinksVisible(true); // plot.setSimpleLabels(true); // plot.setCircular(true); } if (!graphBorder) { plot.setOutlineVisible(false); } if (title != null && !"".equals(title)) { TextTitle title1 = new TextTitle(); title1.setText(title); title1.setFont(titleFont); title1.setPadding(3, 2, 5, 2); chart.setTitle(title1); } else { chart.setTitle((TextTitle) null); } plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1)); //Makes a wrapper for the legend to remove the border around it if (legend) { LegendTitle legend1 = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legend1.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend1.setWrapper(wrapper); legend1.setPosition(RectangleEdge.BOTTOM); legend1.setHorizontalAlignment(HorizontalAlignment.CENTER); if (params.get(GraphSource.LEGEND_FONT) instanceof Font) { legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT))); } chart.addSubtitle(legend1); plot.setLegendLabelGenerator(new PieGraphLabelGenerator()); } for (Comparable category : colors.keySet()) { plot.setSectionPaint(category, colors.get(category)); } plot.setToolTipGenerator(new PieGraphToolTipGenerator(pieGraphData)); plot.setURLGenerator(new PieGraphURLGenerator(pieGraphData)); initialized = true; }