List of usage examples for org.jfree.chart.plot PiePlot setBackgroundAlpha
public void setBackgroundAlpha(float alpha)
From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java
/** * Creer camember3 d.//from ww w . j a va 2 s. com * * @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:nl.wur.plantbreeding.logic.jfreechart.PieChart.java
/** * Create the Pie Chart using the given dataset. * It assigns to the chart the given title, prints the legend if asked, * adds a tooltips of the given url.// ww w. j av a2 s . c om * @param dataset a PieDataset * @param title the title of the graph * @param boollegend wether to add the legend or not * @param tooltips wether to add the tooltips or not * @param urls wether to link the different part of the plot or not * @return a JFreeChart object of the pie chart */ public final JFreeChart createChart(final PieDataset dataset, final String title, final boolean boollegend, final boolean tooltips, final boolean urls) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data boollegend, // include legend tooltips, // include tooltips urls // include urls ); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundAlpha(new Float(0.0)); plot.setSectionOutlinesVisible(false); plot.setNoDataMessage("No data available"); plot.setOutlineVisible(false); // remove borders around the plot return chart; }
From source file:com.netsteadfast.greenstep.action.CommonPieChartAction.java
private void fillChart(String title, List<String> names, List<String> colors, List<Float> values) throws Exception { DefaultPieDataset data = new DefaultPieDataset(); for (int ix = 0; ix < names.size(); ix++) { data.setValue(names.get(ix), values.get(ix)); }// w w w .ja va 2s.co m this.chart = ChartFactory.createPieChart3D(title, data, true, true, false); LegendTitle legend = this.chart.getLegend(); legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9)); PiePlot plot = (PiePlot) this.chart.getPlot(); plot.setCircular(true); plot.setBackgroundAlpha(0.9f); plot.setForegroundAlpha(0.5f); plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9)); this.setPlotColor(plot, names, colors); this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9))); }
From source file:org.sonar.server.charts.deprecated.PieChart.java
private void configurePlot() { PiePlot plot = (PiePlot) jfreechart.getPlot(); plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setDataset(dataset);/*from ww w. j a va2 s .co m*/ plot.setBackgroundAlpha(0.0f); plot.setCircular(true); plot.setLabelGenerator(null); plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setShadowPaint(null); plot.setLabelLinkMargin(0.0); plot.setInteriorGap(0.02); plot.setMaximumLabelWidth(0.10); }
From source file:org.gephi.desktop.partition.PartitionPie.java
public void setup(Partition partition) { data = new DefaultPieDataset(); for (Part p : partition.getParts()) { data.setValue(p.getDisplayName(), p.getPercentage()); }//from ww w . j a v a 2 s . c o m final JFreeChart chart = ChartFactory.createPieChart("test", data, false, false, false); chart.setTitle(new TextTitle()); chart.setBackgroundPaint(null); PiePlot plot = (PiePlot) chart.getPlot(); plot.setShadowPaint(null); //plot.setSimpleLabels(true); plot.setLabelBackgroundPaint(Color.WHITE); plot.setLabelOutlineStroke(null); plot.setLabelShadowPaint(null); plot.setOutlineVisible(false); plot.setLabelFont(new java.awt.Font("Tahoma", 0, 10)); plot.setLabelPaint(Color.BLACK); //plot.setLabelGap(0.05); plot.setCircular(true); plot.setBackgroundPaint(null); plot.setBackgroundAlpha(1f); for (Part p : partition.getParts()) { plot.setSectionPaint(p.getDisplayName(), p.getColor()); } chartPanel = new ChartPanel(chart, true); chartPanel.setOpaque(false); chartPanel.setPopupMenu(null); add(chartPanel, BorderLayout.CENTER); }
From source file:org.gephi.desktop.context.ContextPieChart.java
public ContextPieChart() { data = new DefaultPieDataset(); final JFreeChart chart = ChartFactory.createPieChart("Employee Survey", data, false, false, false); chart.setTitle(new TextTitle()); chart.setBackgroundPaint(null);//from w ww .j a va2s . c o m chart.setPadding(new RectangleInsets(0, 0, 0, 0)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setShadowPaint(null); plot.setSimpleLabels(true); plot.setLabelBackgroundPaint(null); plot.setLabelOutlineStroke(null); plot.setLabelShadowPaint(null); plot.setOutlineVisible(false); plot.setLabelFont(new java.awt.Font("Tahoma", 0, 10)); plot.setLabelPaint(Color.WHITE); plot.setLabelGap(0.5); plot.setCircular(true); plot.setInteriorGap(0); plot.setBackgroundPaint(null); plot.setBackgroundAlpha(1f); plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.visible"), new Color(0x222222)); plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.notVisible"), new Color(0xDDDDDD)); chartPanel = new ChartPanel(chart, 100, 100, 10, 10, 300, 300, true, false, false, false, false, false); ((FlowLayout) chartPanel.getLayout()).setHgap(0); ((FlowLayout) chartPanel.getLayout()).setVgap(0); chartPanel.setOpaque(false); chartPanel.setPopupMenu(null); }
From source file:org.jajuk.ui.views.StatView.java
/** * Device size pie.//from w w w. ja v a 2 s .c o m * * @return the chart */ private ChartPanel createDeviceRepartition() { try { DefaultPieDataset pdata = null; JFreeChart jfchart = null; // data pdata = new DefaultPieDataset(); // prepare devices long lTotalSize = 0; double dOthers = 0; List<Device> devices = DeviceManager.getInstance().getDevices(); long[] lSizes = new long[DeviceManager.getInstance().getElementCount()]; ReadOnlyIterator<File> it = FileManager.getInstance().getFilesIterator(); while (it.hasNext()) { File file = it.next(); lTotalSize += file.getSize(); lSizes[devices.indexOf(file.getDirectory().getDevice())] += file.getSize(); } for (Device device : devices) { long lSize = lSizes[devices.indexOf(device)]; if (lTotalSize > 0 && (double) lSize / lTotalSize < 0.05) { // less than 5% -> go to others dOthers += lSize; } else { double dValue = Math.round((double) lSize / 1073741824); pdata.setValue(device.getName(), dValue); } } if (dOthers > 0) { double dValue = Math.round((dOthers / 1073741824)); pdata.setValue(Messages.getString("StatView.3"), dValue); } // chart jfchart = ChartFactory.createPieChart3D(Messages.getString("StatView.4"), pdata, true, true, true); // set the background color for the chart... PiePlot plot = (PiePlot) jfchart.getPlot(); plot.setLabelFont(PiePlot.DEFAULT_LABEL_FONT); plot.setNoDataMessage(Messages.getString("StatView.5")); plot.setForegroundAlpha(0.5f); plot.setBackgroundAlpha(0.5f); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} GB ({2})")); plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} GB ({2})")); return new ChartPanel(jfchart); } catch (RuntimeException e) { Log.error(e); return null; } }
From source file:org.jajuk.ui.views.StatView.java
/** * Genre repartition pie.//from w ww . j a va 2s . c om * * @return the chart */ private ChartPanel createGenreRepartition() { try { DefaultPieDataset pdata = null; JFreeChart jfchart = null; // data pdata = new DefaultPieDataset(); int iTotal = TrackManager.getInstance().getElementCount(); double dOthers = 0; // Prepare a map genre -> nb tracks Map<Genre, Integer> genreNbTracks = new HashMap<Genre, Integer>( GenreManager.getInstance().getElementCount()); ReadOnlyIterator<Track> it = TrackManager.getInstance().getTracksIterator(); while (it.hasNext()) { Track track = it.next(); Genre genre = track.getGenre(); Integer nbTracks = genreNbTracks.get(genre); if (nbTracks == null) { genreNbTracks.put(genre, 1); } else { genreNbTracks.put(genre, nbTracks + 1); } } // Cleanup genre with weight < 5 % for (Map.Entry<Genre, Integer> entry : genreNbTracks.entrySet()) { double d = entry.getValue(); if (iTotal > 0 && d / iTotal < Conf.getFloat(CONF_STATS_MIN_VALUE_GENRE_DISPLAY) / 100) { // less than 5% -> go to others dOthers += d; } else { double dValue = Math.round(100 * (d / iTotal)); pdata.setValue(entry.getKey().getName2(), dValue); } } if (iTotal > 0 && dOthers > 0) { double dValue = Math.round(100 * (dOthers / iTotal)); pdata.setValue(Messages.getString("StatView.0"), dValue); } // chart jfchart = ChartFactory.createPieChart3D(Messages.getString("StatView.1"), pdata, true, true, true); // set the background color for the chart... PiePlot plot = (PiePlot) jfchart.getPlot(); plot.setLabelFont(PiePlot.DEFAULT_LABEL_FONT); plot.setNoDataMessage(Messages.getString("StatView.2")); plot.setForegroundAlpha(0.5f); plot.setBackgroundAlpha(0.5f); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}")); plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {2}")); return new ChartPanel(jfchart); } catch (RuntimeException e) { Log.error(e); return null; } }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample pie chart. * * @return a sample pie chart./*from ww w.java 2s. com*/ */ public JFreeChart createPieChartTwo() { // create a default chart based on some sample data... final String title = this.resources.getString("pie.pie2.title"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final Comparable category = (Comparable) data.getColumnKeys().get(1); final PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category); final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false); // then customise it a little... chart.setBackgroundPaint(Color.lightGray); final PiePlot pie = (PiePlot) chart.getPlot(); pie.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); pie.setBackgroundImage(JFreeChart.INFO.getLogo()); pie.setBackgroundPaint(Color.white); pie.setBackgroundAlpha(0.6f); pie.setForegroundAlpha(0.75f); return chart; }