List of usage examples for org.jfree.chart.plot PiePlot setInteriorGap
public void setInteriorGap(double percent)
From source file:org.jfree.expdemo.SelectionDemo6Pie.java
private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", // chart title dataset, // dataset true, // include legend true, false);//from ww w . ja v a2s.c o m final PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("One", new Color(160, 160, 255)); plot.setSectionPaint("Two", new Color(128, 128, 255 - 32)); plot.setSectionPaint("Three", new Color(96, 96, 255 - 64)); plot.setSectionPaint("Four", new Color(64, 64, 255 - 96)); plot.setSectionPaint("Five", new Color(32, 32, 255 - 128)); plot.setSectionPaint("Six", new Color(0, 0, 255 - 144)); plot.setNoDataMessage("No data available"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); plot.setSimpleLabels(true); plot.setInteriorGap(0.1); //pie plots done use abstract renderers need to react to selection on our own final PieCursor cursor = new PieCursor(); ext.addSelectionChangeListener(new SelectionChangeListener() { public void selectionChanged(SelectionChangeEvent event) { for (int i = 0; i < dataset.getItemCount(); i++) { cursor.setPosition(dataset.getKey(i)); if (event.getSelectionExtension().isSelected(cursor)) { plot.setExplodePercent(cursor.key, 0.15); } else { plot.setExplodePercent(cursor.key, 0.0); } } } }); return chart; }
From source file:org.jfree.chart.demo.selection.SelectionDemo6Pie.java
private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension<PieCursor<String>> ext) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("One", new Color(160, 160, 255)); plot.setSectionPaint("Two", new Color(128, 128, 255 - 32)); plot.setSectionPaint("Three", new Color(96, 96, 255 - 64)); plot.setSectionPaint("Four", new Color(64, 64, 255 - 96)); plot.setSectionPaint("Five", new Color(32, 32, 255 - 128)); plot.setSectionPaint("Six", new Color(0, 0, 255 - 144)); plot.setNoDataMessage("No data available"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); plot.setSimpleLabels(true);/*from w ww . ja v a 2 s. c o m*/ plot.setInteriorGap(0.1); //pie plots done use abstract renderers need to react to selection on our own final PieCursor<String> cursor = new PieCursor<String>(); ext.addChangeListener(new SelectionChangeListener<PieCursor<String>>() { public void selectionChanged(SelectionChangeEvent<PieCursor<String>> event) { for (int i = 0; i < dataset.getItemCount(); i++) { cursor.setPosition((String) dataset.getKey(i)); if (event.getSelectionExtension().isSelected(cursor)) { plot.setExplodePercent(cursor.key, 0.15); } else { plot.setExplodePercent(cursor.key, 0.0); } } } }); return chart; }
From source file:net.footballpredictions.footballstats.swing.ResultsPieChart.java
/** * Updates the relative sizes of the pie chart segments. *///from ww w . ja v a2 s.c o m public void updateGraph(int won, int drawn, int lost) { DefaultKeyedValues values = new DefaultKeyedValues(); values.addValue(messageResources.getString("headToHead.won"), won); values.addValue(messageResources.getString("headToHead.drawn"), drawn); values.addValue(messageResources.getString("headToHead.lost"), lost); PieDataset dataSet = new DefaultPieDataset(values); JFreeChart chart = ChartFactory.createPieChart(title, dataSet, false, // Legend. true, // Tooltips. false); // URLs. PiePlot plot = (PiePlot) chart.getPlot(); plot.setInteriorGap(0); plot.setSectionPaint(0, Colours.WIN); plot.setSectionPaint(1, Colours.DRAW); plot.setSectionPaint(2, Colours.DEFEAT); plot.setBackgroundPaint(null); plot.setOutlinePaint(null); plot.setLabelGenerator(null); plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} {1} ({2})")); setChart(chart); }
From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java
/** * Creer camember3 d./* ww w . j av a2 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.jfree.chart.demo.PieChartDemo5.java
/** * Creates a chart./*w w w. ja va 2 s. co m*/ * * @param dataset the dataset. * * @return a chart. */ private JFreeChart createChart(final PieDataset dataset) { final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 5", // chart title dataset, // data false, // include legend true, false); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setInteriorGap(0.0); plot.setLabelGenerator(null); return chart; }
From source file:org.openmrs.module.usagestatistics.web.view.chart.FoundByChartView.java
@Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { UsageStatisticsService svc = Context.getService(UsageStatisticsService.class); int[] stats = svc.getFoundByStats(getFromDate(), getUntilInclusiveDate(), getLocation(), getUsageFilter()); String labelLink = ContextProvider.getMessage("usagestatistics.foundBy.directLink"); String labelId = ContextProvider.getMessage("usagestatistics.foundBy.idSearch"); String labelName = ContextProvider.getMessage("usagestatistics.foundBy.nameSearch"); double total = stats[0]; DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue(labelLink, 100.0 * stats[1] / total); dataset.setValue(labelId, 100.0 * stats[2] / total); dataset.setValue(labelName, 100.0 * stats[3] / total); JFreeChart chart = ChartFactory.createPieChart(null, dataset, false, false, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setInteriorGap(0.0); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); plot.setLabelFont(getFont());// ww w . j av a 2 s .c o m return chart; }
From source file:com.leonarduk.finance.chart.PieChartFactory.java
public JFreeChart buildChart() { final JFreeChart chart = ChartFactory.createPieChart(this.title, this.dataset); final PiePlot p = (PiePlot) chart.getPlot(); p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); p.setInteriorGap(0.01); return chart; }
From source file:org.pathvisio.cytoscape.superpathways.PieGenerator.java
public void generatePie(int number) { // Defining the dataset DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < number; i++) { String temp = String.valueOf(i); dataset.setValue(temp, 10);/*from w w w .j a v a 2s . c o m*/ } // Defining the chart JFreeChart chart = ChartFactory.createPieChart("", dataset, false, false, false); // Defining the chartPanel //final ChartPanel chartPanel = new ChartPanel(chart); //chartPanel.setPreferredSize(new java.awt.Dimension(350, 350)); //setContentPane(chartPanel); // Defining the plot PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(null); plot.setInteriorGap(0.0); //add the following two lines to make the background transparent chart.setBackgroundPaint(new Color(255, 255, 255, 0)); plot.setBackgroundPaint(new Color(255, 255, 255, 0)); //plot.setBackgroundAlpha(0.0f); // Specify the colors here PieRenderer renderer = new PieRenderer(colors); renderer.setColor(plot, dataset); try { // This will create a PNG image ChartUtilities.saveChartAsPNG(new File(imageLocation + "chart.png"), chart, 280, 280, null, true, // encodeAlpha 0); } catch (Exception e) { System.out.println("Exception while creating the chart"); } }
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart.//ww w .j av a2s . c o m * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // no legend true, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); // use gradients and white borders for the section colours int itemIndex = 0; for (Object col : pieDataset.getKeys()) { plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]); if (itemIndex == pieDataset.getItemCount() - 1) { itemIndex = 0; } itemIndex++; } plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:org.jfree.chart.demo.MultiplePieChartDemo3.java
/** * Creates a sample chart for the given dataset. * /*w ww . j a v a 2s .com*/ * @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; }