List of usage examples for org.jfree.chart.plot PiePlot setLabelBackgroundPaint
public void setLabelBackgroundPaint(Paint paint)
From source file:semaforo.Semaforo.java
public static void editGrafico() { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);//from www . j av a 2 s .c o m double cfd = 0.0; double bull = 0.0; double bear = 0.0; if (countCfd != 0) cfd = (countCfd * 100) / (countBear + countBull + countCfd); if (countBull != 0) bull = ((countBull * 100) / (countBear + countBull + countCfd)); if (countBear != 0) bear = ((countBear * 100) / (countBear + countBull + countCfd)); Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)"); Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)"); Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)"); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd)); pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull)); pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear)); JFreeChart chart = null; chart = ChartFactory.createPieChart("", // chart title pieDataset, // data false, // no legend false, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK)); // 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, 0)); PiePlot plot = null; plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.00); plot.setOutlineVisible(true); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.BLACK); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 0)); plot.setLabelLinkPaint(Color.BLACK); plot.setLabelLinkStroke(new BasicStroke(0.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(null); plot.setLabelBackgroundPaint(Color.BLACK); plot.setLabelShadowPaint(Color.BLACK); // add a subtitle giving the data source // Mostramos la grafica dentro del jPanel1 Semaforo.panel.setChart(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 w w.j a va 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:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java
private void customizePiePlot(ChartDefinition cd, PiePlot plot, PieCollection pie) { PlotInformation pi = cd.getPlotInformation(); plot.setBackgroundPaint(null);/* w w w. ja va 2 s . c om*/ plot.setOutlineVisible(false); customizeBasicPlot(plot, pi); List<RenderableDataItem> rows = cd.getSeries(); int len = (rows == null) ? 0 : rows.size(); ChartDataItem di; iComponentPainter bp; Paint p = null; if (len > 0) { rows = rows.get(0).getItems(); len = rows.size(); } for (int i = 0; i < len; i++) { di = (ChartDataItem) rows.get(i); bp = di.getComponentPainter(); iPlatformPaint pp; if (bp == null) { p = di.getBackground(); } else if (bp.getBackgroundPainter() != null) { pp = bp.getBackgroundPainter().getPaint(100, 100); p = (pp == null) ? null : pp.getPaint(); } if (p == null) { p = getDefaultColor(i); } plot.setSectionPaint(di.getDomainValue().toString(), p); } if (pie.getExplodedPiece() != null) { plot.setExplodePercent(pie.getExplodedPiece(), 0.50); } plot.setLabelBackgroundPaint(null); plot.setLabelOutlinePaint(null); plot.setLabelShadowPaint(null); UIColor fg = cd.getTextColor(plotLabelColor); UIFont font = cd.getTextFont(plotLabelFont); plot.setLabelFont(font); plot.setLabelPaint(fg); if (cd.isShowPlotLabels()) { String format = (pi == null) ? null : pi.getLabelsFormat(); plot.setLabelGenerator(new PieLabelGenerator(cd, format)); } if (cd.isShowToolTips()) { plot.setToolTipGenerator(new PieToolTipLabelGenerator(cd, false)); } }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private JFreeChart renderPieChart(cfSession _Session, cfCHARTInternalData chartData, List<cfCHARTSERIESData> series, String tipStyle, String drillDownUrl) throws cfmRunTimeException { // Retrieve the attributes of the chart String backgroundColorStr = getDynamic(_Session, "BACKGROUNDCOLOR").toString(); Color backgroundColor = convertStringToColor(backgroundColorStr); String foregroundColorStr = getDynamic(_Session, "FOREGROUNDCOLOR").toString(); Color foregroundColor = convertStringToColor(foregroundColorStr); String labelFormat = getDynamic(_Session, "LABELFORMAT").toString().toLowerCase(); if (!labelFormat.equals("number") && !labelFormat.equals("currency") && !labelFormat.equals("percent")) throw newRunTimeException( "The labelFormat value '" + labelFormat + "' is not supported with pie charts"); String pieSliceStyle = getDynamic(_Session, "PIESLICESTYLE").toString().toLowerCase(); String title = null;/* w ww .j a v a 2 s . co m*/ if (containsAttribute("TITLE")) title = getDynamic(_Session, "TITLE").toString(); Font font = getFont(_Session); cfCHARTSERIESData seriesData = series.get(0); boolean bShow3D = getDynamic(_Session, "SHOW3D").getBoolean(); if (bShow3D && !seriesData.getType().equals("pie")) throw newRunTimeException("Only bar, line, horizontal bar and pie charts can be displayed in 3D"); boolean bShowBorder = getDynamic(_Session, "SHOWBORDER").getBoolean(); boolean bShowLegend = true; // default to true for pie charts if (containsAttribute("SHOWLEGEND")) bShowLegend = getDynamic(_Session, "SHOWLEGEND").getBoolean(); // Get the plot for the chart and configure it PiePlot plot = getPiePlot(series, pieSliceStyle, bShow3D); setBackgroundImage(_Session, plot, chartData.getImageData()); plot.setBackgroundPaint(backgroundColor); plot.setLabelBackgroundPaint(backgroundColor); plot.setLabelShadowPaint(backgroundColor); // Set the labels color plot.setLabelPaint(convertStringToColor(seriesData.getDataLabelColor())); // Set the labels font plot.setLabelFont(getFont(seriesData.getDataLabelFont(), seriesData.getDataLabelFontBold(), seriesData.getDataLabelFontItalic(), seriesData.getDataLabelFontSize())); String dataLabelStyle = seriesData.getDataLabelStyle(); NumberFormat percentInstance = NumberFormat.getPercentInstance(); percentInstance.setMaximumFractionDigits(3); NumberFormat numberFormat = null; if (labelFormat.equals("number")) { // Only display the value in the Label as a number numberFormat = NumberFormat.getInstance(); if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}")); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0} {1} ({2} of {3})")); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern)); } } else if (labelFormat.equals("currency")) { // Only display the value in the Label as a currency numberFormat = NumberFormat.getCurrencyInstance(); if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}", NumberFormat.getCurrencyInstance(), percentInstance)); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator( "{0} {1} ({2} of {3})", NumberFormat.getCurrencyInstance(), percentInstance)); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern, NumberFormat.getCurrencyInstance(), percentInstance)); } } else if (labelFormat.equals("percent")) { // Only display the value in the Label as a percent numberFormat = percentInstance; if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}", percentInstance, percentInstance)); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator( "{0} {1} ({2} of {3})", percentInstance, percentInstance)); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern, percentInstance, percentInstance)); } } if (!tipStyle.equals("none")) { plot.setToolTipGenerator(new StandardPieToolTipGenerator( StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT, numberFormat, numberFormat)); } if (drillDownUrl != null) { plot.setURLGenerator(new com.newatlanta.bluedragon.PieURLGenerator(drillDownUrl, numberFormat)); } // Get the chart and configure it JFreeChart chart = new JFreeChart(null, null, plot, false); chart.setBorderVisible(bShowBorder); chart.setBackgroundPaint(backgroundColor); setTitle(chart, title, font, foregroundColor, chartData.getTitles()); setLegend(chart, bShowLegend, font, foregroundColor, backgroundColor, chartData.getLegendData()); return chart; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *///from ww w . j a v a 2 s .co m protected JFreeChart createPieChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart(evaluateTextExpression(getChart().getTitleExpression()), (PieDataset) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart); PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPiePlot jrPiePlot = (JRPiePlot) getPlot(); boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular(); piePlot.setCircular(isCircular); boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels(); if (isShowLabels) { PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator) getLabelGenerator(); JRItemLabel itemLabel = jrPiePlot.getItemLabel(); if (labelGenerator != null) { piePlot.setLabelGenerator(labelGenerator); } else if (jrPiePlot.getLabelFormat() != null) { piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } // the default section label is just the key, so there's no need to set localized number formats // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // } piePlot.setLabelFont( fontUtil.getAwtFont(getFont(itemLabel == null ? null : itemLabel.getFont()), getLocale())); if (itemLabel != null && itemLabel.getColor() != null) { piePlot.setLabelPaint(itemLabel.getColor()); } else { piePlot.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot.setLabelBackgroundPaint(getChart().getBackcolor()); } } else { piePlot.setLabelGenerator(null); } if (jrPiePlot.getLegendLabelFormat() != null) { piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(jrPiePlot.getLegendLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } // the default legend label is just the key, so there's no need to set localized number formats return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * *//*from w w w. java2s .c om*/ protected JFreeChart createPieChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart( (String) evaluateExpression(getChart().getTitleExpression()), (PieDataset) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPiePlot jrPlot = (JRPiePlot) getPlot(); boolean isCircular = jrPlot.getCircular() == null ? true : jrPlot.getCircular().booleanValue(); piePlot.setCircular(isCircular); PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator) getLabelGenerator(); JRItemLabel itemLabel = jrPlot.getItemLabel(); if (labelGenerator != null) { piePlot.setLabelGenerator(labelGenerator); } else if (jrPlot.getLabelFormat() != null) { piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(jrPlot.getLabelFormat())); } // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // // } if (jrPlot.getLegendLabelFormat() != null) { piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(jrPlot.getLegendLabelFormat())); } Integer baseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null; piePlot.setLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize)); if (itemLabel != null && itemLabel.getColor() != null) { piePlot.setLabelPaint(itemLabel.getColor()); } else { piePlot.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot.setLabelBackgroundPaint(getChart().getBackcolor()); } return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * *///from ww w . j a va 2 s.c om protected JFreeChart createPieChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart( (String) evaluateExpression(getChart().getTitleExpression()), (PieDataset) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPiePlot jrPlot = (JRPiePlot) getPlot(); boolean isCircular = jrPlot.getCircular() == null ? true : jrPlot.getCircular().booleanValue(); piePlot.setCircular(isCircular); PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator) getLabelGenerator(); JRItemLabel itemLabel = jrPlot.getItemLabel(); if (labelGenerator != null) { piePlot.setLabelGenerator(labelGenerator); } else if (jrPlot.getLabelFormat() != null) { piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(jrPlot.getLabelFormat())); } // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // } if (jrPlot.getLegendLabelFormat() != null) { piePlot.setLegendLabelGenerator( new StandardPieSectionLabelGenerator(((JRPie3DPlot) getPlot()).getLegendLabelFormat())); } if (itemLabel != null && itemLabel.getFont() != null) { piePlot.setLabelFont(JRFontUtil.getAwtFont(itemLabel.getFont(), getLocale())); } else { piePlot.setLabelFont(JRFontUtil.getAwtFont(new JRBaseFont(getChart(), null), getLocale())); } if (itemLabel != null && itemLabel.getColor() != null) { piePlot.setLabelPaint(itemLabel.getColor()); } else { piePlot.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot.setLabelBackgroundPaint(getChart().getBackcolor()); } return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
/** * *///from w w w .j ava 2 s. c o m protected JFreeChart createPieChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart(evaluateTextExpression(getChart().getTitleExpression()), (PieDataset) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPiePlot jrPiePlot = (JRPiePlot) getPlot(); boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular(); piePlot.setCircular(isCircular); boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels(); if (isShowLabels) { PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator) getLabelGenerator(); JRItemLabel itemLabel = jrPiePlot.getItemLabel(); if (labelGenerator != null) { piePlot.setLabelGenerator(labelGenerator); } else if (jrPiePlot.getLabelFormat() != null) { piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // } if (itemLabel != null && itemLabel.getFont() != null) { piePlot.setLabelFont(getFontUtil().getAwtFont(itemLabel.getFont(), getLocale())); } else { piePlot.setLabelFont(getFontUtil().getAwtFont(new JRBaseFont(getChart(), null), getLocale())); } if (itemLabel != null && itemLabel.getColor() != null) { piePlot.setLabelPaint(itemLabel.getColor()); } else { piePlot.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot.setLabelBackgroundPaint(getChart().getBackcolor()); } } else { piePlot.setLabelGenerator(null); } if (jrPiePlot.getLegendLabelFormat() != null) { piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator( ((JRPiePlot) getPlot()).getLegendLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
/** * *//*from w ww . j a v a 2 s . c om*/ protected JFreeChart createPieChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart(evaluateTextExpression(getChart().getTitleExpression()), (PieDataset) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPiePlot jrPiePlot = (JRPiePlot) getPlot(); boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular(); piePlot.setCircular(isCircular); boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels(); if (isShowLabels) { PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator) getLabelGenerator(); JRItemLabel itemLabel = jrPiePlot.getItemLabel(); if (labelGenerator != null) { piePlot.setLabelGenerator(labelGenerator); } else if (jrPiePlot.getLabelFormat() != null) { piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // // } Integer baseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null; piePlot.setLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize)); if (itemLabel != null && itemLabel.getColor() != null) { piePlot.setLabelPaint(itemLabel.getColor()); } else { piePlot.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot.setLabelBackgroundPaint(getChart().getBackcolor()); } } else { piePlot.setLabelGenerator(null); } if (jrPiePlot.getLegendLabelFormat() != null) { piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(jrPiePlot.getLegendLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale()))); } return jfreeChart; }