List of usage examples for org.jfree.chart.plot PiePlot setLabelFont
public void setLabelFont(Font font)
From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java
/** Create a line chart. */ @Override/*from ww w.jav a 2 s. c o m*/ public JFreeChart createChart() { CategoryDataset catData = data.catDataSource(); PieDataset pieData = null; if (catData.getColumnCount() == 1) pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0); else pieData = DatasetUtilities.createPieDatasetForRow(catData, 0); JFreeChart chart = null; if (get3DSetting()) { chart = ChartFactory.createPieChart3D(null, pieData, true, true, false); chart.getPlot().setForegroundAlpha(ALPHA); } else { chart = ChartFactory.createPieChart(null, pieData, true, true, false); } PiePlot plot = (PiePlot) chart.getPlot(); if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null) plot.setLabelGenerator(null); else if (parameters.get("wedgeLabelFontSize") != null) try { float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize")); plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize)); } catch (Exception lfe) { } if (parameters.get("ellipse") != null) plot.setCircular(true); else plot.setCircular(false); Object colorScheme = parameters.get("colorScheme"); if ("byPhase".equals(colorScheme)) maybeConfigurePhaseColors(plot, pieData); else if ("consistent".equals(colorScheme)) // since 2.0.9 configureConsistentColors(plot, pieData); else if (parameters.containsKey("c1")) configureIndividualColors(plot, pieData); String interiorGap = (String) parameters.get("interiorGap"); if (interiorGap != null) try { plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0); } catch (NumberFormatException e) { } String interiorSpacing = (String) parameters.get("interiorSpacing"); if (interiorSpacing != null) try { plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0); } catch (NumberFormatException e) { } if (!parameters.containsKey("showZeroValues")) { plot.setIgnoreZeroValues(true); plot.setIgnoreNullValues(true); } return chart; }
From source file:org.pentaho.chart.plugin.jfreechart.chart.pie.JFreePieChartGenerator.java
/** * Set the font for the labels on the chart. * </p>/*from w w w .j a v a 2 s . com*/ * @param piePlot - PiePlot for the current Pie Chart. * @param seriesElements - Array of all the series elements defined in the chart definition document. */ private void setLabelFont(final PiePlot piePlot, final ChartElement[] seriesElements) { final int length = seriesElements.length; for (int i = 0; i < length; i++) { final ChartElement seriesElement = seriesElements[i]; final Font font = JFreeChartUtils.getFont(seriesElement); if (font != null) { piePlot.setLabelFont(font); break; } } }
From source file:org.jajuk.ui.views.StatView.java
/** * Device size pie./*from www .ja va2 s . com*/ * * @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./*w w w .j a va 2s . c o m*/ * * @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:msi.gama.outputs.layers.charts.ChartJFreeChartOutputPie.java
@Override public void initChart(final IScope scope, final String chartname) { super.initChart(scope, chartname); final PiePlot pp = (PiePlot) chart.getPlot(); pp.setShadowXOffset(0);//from w w w . j a v a 2s . co m pp.setShadowYOffset(0); if (!this.series_label_position.equals("none")) { pp.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})")); if (axesColor != null) { pp.setLabelLinkPaint(axesColor); } pp.setLabelFont(getTickFont()); } if (this.series_label_position.equals("none")) { pp.setLabelLinksVisible(false); pp.setLabelGenerator(null); } if (textColor != null) { // pp.setLabelPaint(textColor); // not for Pie since the label background is always yellow for // now... } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.piecharts.LinkablePie.java
public JFreeChart createChart(DatasetMap datasets) { Dataset dataset = (Dataset) datasets.getDatasets().get("1"); boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true;// w w w . j a v a2s .c o m JFreeChart chart = null; if (!threeD) { chart = ChartFactory.createPieChart(name, (PieDataset) dataset, // data legend, // include legend true, false); chart.setBackgroundPaint(color); TextTitle title = chart.getTitle(); title.setToolTipText("A title tooltip!"); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize())); plot.setCircular(false); plot.setLabelGap(0.02); plot.setNoDataMessage("No data available"); if (percentage == false) { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})")); } else { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); } MyPieUrlGenerator pieUrl = new MyPieUrlGenerator(rootUrl); pieUrl.setDocument_composition(document_composition); pieUrl.setCategoryUrlLabel(categoryUrlName); pieUrl.setDrillDocTitle(drillDocTitle); pieUrl.setTarget(target); plot.setURLGenerator(pieUrl); } else { chart = ChartFactory.createPieChart3D(name, (PieDataset) dataset, // data true, // include legend true, false); chart.setBackgroundPaint(color); TextTitle title = chart.getTitle(); title.setToolTipText("A title tooltip!"); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setDarkerSides(true); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(1.0f); plot.setDepthFactor(0.2); plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize())); plot.setCircular(false); plot.setLabelGap(0.02); plot.setNoDataMessage("No data available"); //org.jfree.chart.renderer.category.BarRenderer renderer = new org.jfree.chart.renderer.category.AreaRenderer); MyPieUrlGenerator pieUrl = new MyPieUrlGenerator(rootUrl); pieUrl.setDocument_composition(document_composition); pieUrl.setCategoryUrlLabel(categoryUrlName); pieUrl.setDrillDocTitle(drillDocTitle); pieUrl.setTarget(target); plot.setURLGenerator(pieUrl); if (percentage == false) { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})")); } else { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); } } TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } return chart; }
From source file:edu.ucla.stat.SOCR.applications.demo.BinomialTradingApplication.java
protected JFreeChart createEmptyChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("SOCR Chart", // chart title null, // data true, // include legend true, false);/* w w w . j a va2 s . co m*/ PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); return chart; }
From source file:hr.restart.util.chart.ChartXY.java
/** * Creates a PIE CHART//from www. ja v a 2 s . c o m * @param dataset The org.jfree.data.PieDataset * @param title The title * @return org.jfree.chart.JFreeChart */ private JFreeChart createPieChart(final PieDataset dataset, String title) { final JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, false); chart.setBackgroundPaint(Color.white); Plot plot = chart.getPlot(); // the subtitle from the combobox if (jcb != null) chart.addSubtitle(new TextTitle(jcb.getSelectedItem().toString())); //subtitles setted by the user. if (getSubtitles() != null) for (int i = 0; i < getSubtitles().size(); i++) { chart.addSubtitle(new TextTitle(getSubtitles().get(i).toString())); } final PiePlot piePlot = (PiePlot) plot; piePlot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); piePlot.setNoDataMessage("NO DATA!"); piePlot.setCircular(false); piePlot.setLabelLinkPaint(Color.red); piePlot.setLabelGap(0.02); return chart; }
From source file:org.openfaces.component.chart.impl.plots.PiePlot3DAdapter.java
private void setupPieLabelGenerator(PiePlot plot, PieChartView chartView) { if (chartView.isLabelsVisible()) { ChartLabels labels = chartView.getLabels(); if (labels != null && labels.getDynamicText() != null) plot.setLabelGenerator(new DynamicPieGenerator(chartView, labels.getDynamicText())); else/*from w w w.ja va 2 s . c om*/ plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); //TODO: move to style helper if (labels != null) { StyleObjectModel cssLabelsModel = labels.getStyleObjectModel(); plot.setLabelFont(CSSUtil.getFont(cssLabelsModel)); plot.setLabelPaint(cssLabelsModel.getColor()); plot.setLabelBackgroundPaint(cssLabelsModel.getBackground()); } } else { plot.setLabelGenerator(null); } }
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart.//from w w w . j a va 2s . 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; }