List of usage examples for org.jfree.chart.plot PiePlot setLabelGenerator
public void setLabelGenerator(PieSectionLabelGenerator generator)
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;/*from w w w. ja v a 2 s .co 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:com.manydesigns.portofino.chart.Chart1DGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultPieDataset dataset = new DefaultPieDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);/* ww w . j a v a2 s.co m*/ Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper key = new ComparableWrapper((Comparable) current[0]); dataset.setValue(key, (Number) current[1]); if (current.length > 2) { key.setLabel(current[2].toString()); } } JFreeChart chart = createChart(chartDefinition, dataset); chart.setAntiAlias(isAntiAlias()); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno // eventualmente e' il css a fornirne uno chart.setBorderVisible(isBorderVisible()); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot PiePlot plot = (PiePlot) chart.getPlot(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression); plot.setURLGenerator(urlGenerator); } else { plot.setURLGenerator(null); } // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // hongliangpan add // :?{0} {1} {2} ? ,??? plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); // {0}={1}({2}) plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); // ?(0.0-1.0) // plot.setForegroundAlpha(1.0f); // imposta la distanza delle etichette dal plot plot.setLabelGap(0.03); // plot.setLabelGenerator(new MyPieSectionLabelGenerator()); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setCircular(true); plot.setBaseSectionOutlinePaint(Color.BLACK); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // ? plot.setForegroundAlpha(1.0f); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE); chart.setBackgroundPaint(chartBgPaint); 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 w w w .j a v a2 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 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); } 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). // w ww . j ava 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 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:KIDLYFactory.java
/** * Creates a pie chart with default settings. * <P>// w ww .jav a 2 s. c o m * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @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). * * @return A pie chart. * * @since 1.0.7 */ public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) { 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)); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:KIDLYFactory.java
/** * Creates a pie chart with default settings. * <P>//from w w w .j av a2s . c om * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @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? * * @return A pie chart. */ public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls) { 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()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:servlets.LeasingControllerServlet.java
public void doGetChart() { PieDataset pieDataset = createDataset(); JFreeChart chart = ChartFactory.createPieChart("Tenant Mix ", pieDataset, true, true, false); //chart.setBackgroundPaint(new Color(222, 222, 255)); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}")); plot.setCircular(true);//from w w w.j a va2s .com plot.setSectionPaint("F&B", new Color(15, 192, 252)); try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File( getServletContext().getRealPath("") + "/leasingSystem/leasingSystemAssets/chart/piechart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { System.out.println(e); } }
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 a v a 2s . 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 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: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 ww w . ja v 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.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.jav a2 s . 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); } }