List of usage examples for org.jfree.chart.plot PiePlot setSectionPaint
public void setSectionPaint(int section, Paint paint)
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void chartMouseClicked(ChartMouseEvent chartMouseEvent) { ChartEntity entity = chartMouseEvent.getEntity(); MouseEvent mouseEvent = chartMouseEvent.getTrigger(); if (SwingUtilities.isLeftMouseButton(mouseEvent) && entity != null && entity instanceof PieSectionEntity) { java.util.List<String> names = dataset.getTransactionTypeNames(); PieSectionEntity pieSectionEntity = (PieSectionEntity) entity; int idx = pieSectionEntity.getSectionIndex(); String name = (String) JOptionPane.showInputDialog(null, "Enter the name for this transaction type", "Transaction Type", JOptionPane.PLAIN_MESSAGE, null, null, ""); if (name != null) { if (names.contains(name) && !names.get(idx).equals(name) && !name.isEmpty()) { JOptionPane.showMessageDialog(null, "Please enter a different name for the transaction type.\nEach name has to be unique.", "Warning", JOptionPane.WARNING_MESSAGE); } else { PieDataset oldDataset = pieSectionEntity.getDataset(); DefaultPieDataset newDataset = new DefaultPieDataset(); PiePlot plot = (PiePlot) chart.getPlot(); String oldName = (String) oldDataset.getKey(idx); names.set(idx, name);/*from w w w. ja v a 2s. c o m*/ dataset.setTransactionTypeName(idx, name); for (int i = 0; i < oldDataset.getItemCount(); ++i) { String key = (String) oldDataset.getKey(i); Number number = oldDataset.getValue(i); if (key.equals(oldName)) { if (name.isEmpty()) newDataset.setValue("Transaction Type " + (i + 1), number); else newDataset.setValue(name, number); } else { newDataset.setValue(key, number); } } Paint[] tempPaint = new Paint[oldDataset.getItemCount()]; for (int i = 0; i < oldDataset.getItemCount(); ++i) { String key = (String) oldDataset.getKey(i); tempPaint[i] = plot.getSectionPaint(key); } ((DefaultPieDataset) oldDataset).clear(); plot.setDataset(newDataset); for (int i = 0; i < newDataset.getItemCount(); ++i) { String key = (String) newDataset.getKey(i); plot.setSectionPaint(key, tempPaint[i]); } } } } }
From source file:KIDLYFactory.java
/** * Creates a pie chart with default settings that compares 2 datasets. * The colour of each section will be determined by the move from the value * for the same key in <code>previousDataset</code>. ie if value1 > value2 * then the section will be in green (unless <code>greenForIncrease</code> * is <code>false</code>, in which case it would be <code>red</code>). * Each section can have a shade of red or green as the difference can be * tailored between 0% (black) and percentDiffForMaxScale% (bright * red/green).//w w w . j av a 2 s .c om * <p> * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a * difference of 5% will have a half shade of red/green, a difference of * 10% or more will have a maximum shade/brightness of red/green. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * <p> * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit * Xhenseval</a>. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param previousDataset the dataset for the last run, this will be used * to compare each key in the dataset * @param percentDiffForMaxScale scale goes from bright red/green to black, * percentDiffForMaxScale indicate the change * required to reach top scale. * @param greenForIncrease an increase since previousDataset will be * displayed in green (decrease red) if true. * @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). * @param subTitle displays a subtitle with colour scheme if true * @param showDifference create a new dataset that will show the % * difference between the two datasets. * * @return A pie chart. * * @since 1.0.7 */ public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, 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)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); } List keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (Iterator it = keys.iterator(); it.hasNext();) { Comparable key = (Comparable) it.next(); Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.green); } else { plot.setSectionPaint(key, Color.red); } if (showDifference) { series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } currentTheme.apply(chart); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a pie chart with default settings that compares 2 datasets. * The colour of each section will be determined by the move from the value * for the same key in <code>previousDataset</code>. ie if value1 > value2 * then the section will be in green (unless <code>greenForIncrease</code> * is <code>false</code>, in which case it would be <code>red</code>). * Each section can have a shade of red or green as the difference can be * tailored between 0% (black) and percentDiffForMaxScale% (bright * red/green). //from ww w .ja v a2s . c o m * <p> * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a * difference of 5% will have a half shade of red/green, a difference of * 10% or more will have a maximum shade/brightness of red/green. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * <p> * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit * Xhenseval</a>. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param previousDataset the dataset for the last run, this will be used * to compare each key in the dataset * @param percentDiffForMaxScale scale goes from bright red/green to black, * percentDiffForMaxScale indicate the change * required to reach top scale. * @param greenForIncrease an increase since previousDataset will be * displayed in green (decrease red) if true. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * @param subTitle displays a subtitle with colour scheme if true * @param showDifference create a new dataset that will show the % * difference between the two datasets. * * @return A pie chart. */ public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, boolean urls, boolean subTitle, boolean showDifference) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } List keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (Iterator it = keys.iterator(); it.hasNext();) { Comparable key = (Comparable) it.next(); Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.green); } else { plot.setSectionPaint(key, Color.red); } if (showDifference) { series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } return chart; }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
private void createSlices(final IScope scope) throws GamaRuntimeException { int i = 0;/*from w w w . ja va2 s .com*/ dataset = new DefaultPieDataset(); final PiePlot plot = (PiePlot) chart.getPlot(); for (final ChartData e : datas) { final String legend = e.getName(); ((DefaultPieDataset) dataset).insertValue(i++, legend, null); history.append(legend); history.append(','); } if (history.length() > 0) { history.deleteCharAt(history.length() - 1); } history.append(Strings.LN); plot.setDataset((DefaultPieDataset) dataset); i = 0; for (final ChartData e : datas) { plot.setSectionPaint(i++, e.getColor()); } plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})")); if (exploded) { for (final Object c : ((DefaultPieDataset) dataset).getKeys()) { plot.setExplodePercent((Comparable) c, 0.20); } } plot.setSectionOutlinesVisible(false); plot.setLabelFont(getLabelFont()); plot.setNoDataMessage("No data available yet"); plot.setCircular(true); plot.setLabelGap(0.02); plot.setInteriorGap(0); }
From source file:KIDLYFactory.java
/** * Creates a pie chart with default settings that compares 2 datasets. * The colour of each section will be determined by the move from the value * for the same key in <code>previousDataset</code>. ie if value1 > value2 * then the section will be in green (unless <code>greenForIncrease</code> * is <code>false</code>, in which case it would be <code>red</code>). * Each section can have a shade of red or green as the difference can be * tailored between 0% (black) and percentDiffForMaxScale% (bright * red/green).//from w w w . j av a 2 s .c o m * <p> * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a * difference of 5% will have a half shade of red/green, a difference of * 10% or more will have a maximum shade/brightness of red/green. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * <p> * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit * Xhenseval</a>. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param previousDataset the dataset for the last run, this will be used * to compare each key in the dataset * @param percentDiffForMaxScale scale goes from bright red/green to black, * percentDiffForMaxScale indicate the change * required to reach top scale. * @param greenForIncrease an increase since previousDataset will be * displayed in green (decrease red) if true. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * @param subTitle displays a subtitle with colour scheme if true * @param showDifference create a new dataset that will show the % * difference between the two datasets. * * @return A pie chart. */ public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, boolean urls, boolean subTitle, boolean showDifference) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } List keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (Iterator it = keys.iterator(); it.hasNext();) { Comparable key = (Comparable) it.next(); Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.green); } else { plot.setSectionPaint(key, Color.red); } if (showDifference) { series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } currentTheme.apply(chart); return chart; }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
public JFreeChart makePieChart(ChartModel chartModel, NamedValuesDataModel dataModel, final IChartLinkGenerator linkGenerator) { final DefaultPieDataset dataset = new DefaultPieDataset(); for (NamedValue namedValue : dataModel) { if (namedValue.getName() != null) { dataset.setValue(namedValue.getName(), scaleNumber(namedValue.getValue(), dataModel.getScalingFactor())); }/*from w ww .ja v a 2 s . co m*/ } boolean showLegend = (chartModel.getLegend() != null) && (chartModel.getLegend().getVisible()); String title = ""; if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null) && (chartModel.getTitle().getText().trim().length() > 0)) { title = chartModel.getTitle().getText(); } final JFreeChart chart = ChartFactory.createPieChart(title, dataset, showLegend, true, false); initChart(chart, chartModel); final PiePlot jFreePiePlot = (PiePlot) chart.getPlot(); if (linkGenerator != null) { jFreePiePlot.setURLGenerator(new PieURLGenerator() { public String generateURL(PieDataset arg0, Comparable arg1, int arg2) { return linkGenerator.generateLink(arg1.toString(), arg1.toString(), arg0.getValue(arg1)); } }); } jFreePiePlot.setNoDataMessage("No data available"); //$NON-NLS-1$ jFreePiePlot.setCircular(true); jFreePiePlot.setLabelGap(0.02); org.pentaho.chart.model.PiePlot chartBeansPiePlot = (org.pentaho.chart.model.PiePlot) chartModel.getPlot(); List<Integer> colors = getPlotColors(chartBeansPiePlot); int index = 0; for (NamedValue namedValue : dataModel) { if (namedValue.getName() != null) { jFreePiePlot.setSectionPaint(namedValue.getName(), new Color(0x00FFFFFF & colors.get(index % colors.size()))); } index++; } if (chartBeansPiePlot.getLabels().getVisible()) { jFreePiePlot.setLabelGenerator(new StandardPieSectionLabelGenerator()); Font font = ChartUtils.getFont(chartBeansPiePlot.getLabels().getFontFamily(), chartBeansPiePlot.getLabels().getFontStyle(), chartBeansPiePlot.getLabels().getFontWeight(), chartBeansPiePlot.getLabels().getFontSize()); if (font != null) { jFreePiePlot.setLabelFont(font); if (chartBeansPiePlot.getLabels().getColor() != null) { jFreePiePlot.setLabelPaint(new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getColor())); } if (chartBeansPiePlot.getLabels().getBackgroundColor() != null) { jFreePiePlot.setLabelBackgroundPaint( new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getBackgroundColor())); } } } else { jFreePiePlot.setLabelGenerator(null); } jFreePiePlot.setStartAngle(-chartBeansPiePlot.getStartAngle()); return chart; }
From source file:org.openfaces.component.chart.impl.plots.PiePlotAdapter.java
private void sectorProcessing(PiePlot plot, PieChartView chartView, PieDataset dataset, CategoryDataset categoryDataset) { List<PieSectorProperties> sectors = chartView.getSectors(); if (sectors == null || sectors.size() == 0) return;//from w ww . j a v a 2s.c o m for (PieSectorProperties sector : sectors) { DynamicPieGenerator generator = new DynamicPieGenerator(chartView, null); int index = -1; Float sectorPulled = sector.getPulled(); if (dataset instanceof CategoryToPieDataset) { CategoryToPieDataset cds = (CategoryToPieDataset) dataset; int count = getIterationCount(cds); for (int q = 0; q < count; q++) { CategoryToPieDataset currPieDataset = new CategoryToPieDataset(categoryDataset, order, q); List keys = currPieDataset.getKeys(); index = -1; for (int j = 0; j < keys.size(); j++) { index++; boolean conditionValue = generator.getConditionValue(sector, q, currPieDataset, currPieDataset.getKey(j)); if (!conditionValue) continue; if (sectorPulled != null && sectorPulled > 0) { plot.setExplodePercent(index, (double) sectorPulled); } StyleObjectModel cssSectorModel = sector.getStyleObjectModel(); if (cssSectorModel != null && cssSectorModel.getBorder() != null) { StyleBorderModel border = cssSectorModel.getBorder(); Color borderColor = border.getColor(); if (borderColor != null) { plot.setSectionOutlinePaint(index, borderColor); plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border)); } Color sectorModelColor = cssSectorModel.getColor(); if (sectorModelColor != null) { plot.setSectionPaint(index, sectorModelColor); } } } } } else { if (dataset == null || dataset.getKeys() == null) continue; for (int j = 0; j < dataset.getKeys().size(); j++) { index++; boolean conditionValue = generator.getConditionValue(sector, 0, dataset, dataset.getKey(j)); if (!conditionValue) continue; if (sectorPulled != null && sectorPulled > 0) { plot.setExplodePercent(index, (double) sectorPulled); } StyleObjectModel cssSectorModel = sector.getStyleObjectModel(); if (cssSectorModel != null && cssSectorModel.getBorder() != null) { StyleBorderModel border = cssSectorModel.getBorder(); if (border.getColor() != null) { plot.setSectionOutlinePaint(index, border.getColor()); plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border)); } } if (cssSectorModel != null && cssSectorModel.getColor() != null) { plot.setSectionPaint(index, cssSectorModel.getColor()); } } } } }
From source file:org.openfaces.component.chart.impl.plots.PiePlot3DAdapter.java
private void sectorProcessing(PiePlot plot, PieChartView chartView, PieDataset dataset, CategoryDataset categoryDataset) { java.util.List<PieSectorProperties> sectors = chartView.getSectors(); if (sectors == null || sectors.size() == 0) return;/*from w w w. jav a2 s .c om*/ for (PieSectorProperties sector : sectors) { DynamicPieGenerator generator = new DynamicPieGenerator(chartView, null); int index = -1; Float sectorPulled = sector.getPulled(); if (dataset instanceof CategoryToPieDataset) { CategoryToPieDataset cds = (CategoryToPieDataset) dataset; int count = getIterationCount(cds); for (int q = 0; q < count; q++) { CategoryToPieDataset currPieDataset = new CategoryToPieDataset(categoryDataset, order, q); java.util.List keys = currPieDataset.getKeys(); index = -1; for (int j = 0; j < keys.size(); j++) { index++; boolean conditionValue = generator.getConditionValue(sector, q, currPieDataset, currPieDataset.getKey(j)); if (!conditionValue) continue; if (sectorPulled != null && sectorPulled > 0) { plot.setExplodePercent(index, (double) sectorPulled); } StyleObjectModel cssSectorModel = sector.getStyleObjectModel(); if (cssSectorModel != null && cssSectorModel.getBorder() != null) { StyleBorderModel border = cssSectorModel.getBorder(); Color borderColor = border.getColor(); if (borderColor != null) { plot.setSectionOutlinePaint(index, borderColor); plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border)); } Color sectorModelColor = cssSectorModel.getColor(); if (sectorModelColor != null) { plot.setSectionPaint(index, sectorModelColor); } } } } } else { if (dataset == null || dataset.getKeys() == null) continue; for (int j = 0; j < dataset.getKeys().size(); j++) { index++; boolean conditionValue = generator.getConditionValue(sector, 0, dataset, dataset.getKey(j)); if (!conditionValue) continue; if (sectorPulled != null && sectorPulled > 0) { plot.setExplodePercent(index, (double) sectorPulled); } StyleObjectModel cssSectorModel = sector.getStyleObjectModel(); if (cssSectorModel != null && cssSectorModel.getBorder() != null) { StyleBorderModel border = cssSectorModel.getBorder(); if (border.getColor() != null) { plot.setSectionOutlinePaint(index, border.getColor()); plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border)); } } if (cssSectorModel != null && cssSectorModel.getColor() != null) { plot.setSectionPaint(index, cssSectorModel.getColor()); } } } } }
From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java
/** * Creates the chart./*from www . j a v a 2 s.c om*/ * * @param dataset * the dataset. * @param loader * the pie chart loader * @param dataRequested * flag indicating if the data have been requested for the current loader and the * current interval * @return the pie chart */ private JFreeChart createChart(PieDataset dataset, String title, IPieChartLoader loader, boolean dataRequested) { JFreeChart chart = ChartFactory.createPieChart(title, dataset, HAS_LEGEND, HAS_TOOLTIPS, HAS_URLS); // legend if (HAS_LEGEND) { LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.LEFT); } // plot PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage( "No data available " + (dataRequested ? "in this time interval" : "yet. Press the Load button.")); plot.setCircular(true); plot.setLabelGenerator(null); // hide labels plot.setBackgroundPaint(Color.WHITE); plot.setOutlineVisible(false); plot.setShadowPaint(Color.WHITE); plot.setBaseSectionPaint(Color.WHITE); StandardPieToolTipGenerator g = (StandardPieToolTipGenerator) plot.getToolTipGenerator(); NumberFormat format = ValueLabelProvider.getActualFormat(loader.getFormat(), getTimeUnit()); StandardPieToolTipGenerator sg = new StandardPieToolTipGenerator(g.getLabelFormat(), format, g.getPercentFormat()); plot.setToolTipGenerator(sg); for (Object o : dataset.getKeys()) { String key = (String) o; plot.setSectionPaint(key, loader.getColor(key).getAwtColor()); } return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.PieChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final Plot plot = chart.getPlot(); final PiePlot pp = (PiePlot) plot; final PieDataset pieDS = pp.getDataset(); pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE); if ((explodeSegment != null) && (explodePct != null)) { configureExplode(pp);//from w w w . j a v a 2s.co m } if (StringUtils.isEmpty(getTooltipFormula()) == false) { pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula())); } if (StringUtils.isEmpty(getUrlFormula()) == false) { pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula())); } pp.setIgnoreNullValues(ignoreNulls); pp.setIgnoreZeroValues(ignoreZeros); if (Boolean.FALSE.equals(getItemsLabelVisible())) { pp.setLabelGenerator(null); } else { final ExpressionRuntime runtime = getRuntime(); final Locale locale = runtime.getResourceBundleFactory().getLocale(); final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale); final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale); final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(), new DecimalFormatSymbols(locale)); numFormat.setRoundingMode(RoundingMode.HALF_UP); final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(), new DecimalFormatSymbols(locale)); percentFormat.setRoundingMode(RoundingMode.HALF_UP); final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(pieLabelFormat, numFormat, percentFormat); pp.setLabelGenerator(labelGen); final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator( pieLegendLabelFormat, numFormat, percentFormat); pp.setLegendLabelGenerator(legendGen); } if (StringUtils.isEmpty(getLabelFont()) == false) { pp.setLabelFont(Font.decode(getLabelFont())); } if (pieDS != null) { final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { if (i < pieDS.getItemCount()) { pp.setSectionPaint(pieDS.getKey(i), parseColorFromString(colors[i])); } else { break; } } } if (shadowPaint != null) { pp.setShadowPaint(shadowPaint); } if (shadowXOffset != null) { pp.setShadowXOffset(shadowXOffset.doubleValue()); } if (shadowYOffset != null) { pp.setShadowYOffset(shadowYOffset.doubleValue()); } pp.setCircular(circular); if (isShowBorder() == false || isChartSectionOutline() == false) { chart.setBorderVisible(false); chart.getPlot().setOutlineVisible(false); } }