List of usage examples for org.jfree.chart.plot PiePlot setStartAngle
public void setStartAngle(double angle)
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) { plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint()); plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage()); plot.setNoDataMessage(chartDefinition.getNoDataMessage()); // create a custom palette if it was defined if (chartDefinition.getPaintSequence() != null) { DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); plot.setDrawingSupplier(drawingSupplier); }/* w w w . j a v a 2 s. c o m*/ plot.setOutlineStroke(null); // TODO define outline stroke if (plot instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) plot; CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition; categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation()); CategoryAxis domainAxis = categoryPlot.getDomainAxis(); if (domainAxis != null) { domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle()); domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont()); if (categoryDatasetChartDefintion.getDomainTickFont() != null) { domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont()); } domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions()); } NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis(); if (numberAxis != null) { numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle()); numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont()); if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum()); } if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum()); } if (categoryDatasetChartDefintion.getRangeTickFormat() != null) { numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat()); } if (categoryDatasetChartDefintion.getRangeTickFont() != null) { numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont()); } if (categoryDatasetChartDefintion.getRangeTickUnits() != null) { numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits())); } } } if (plot instanceof PiePlot) { PiePlot pie = (PiePlot) plot; PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition; pie.setInteriorGap(pieDefinition.getInteriorGap()); pie.setStartAngle(pieDefinition.getStartAngle()); pie.setLabelFont(pieDefinition.getLabelFont()); if (pieDefinition.getLabelPaint() != null) { pie.setLabelPaint(pieDefinition.getLabelPaint()); } pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint()); if (pieDefinition.isLegendIncluded()) { StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$ pie.setLegendLabelGenerator(labelGen); } if (pieDefinition.getExplodedSlices() != null) { for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext();) { pie.setExplodePercent((Comparable) iter.next(), .30); } } pie.setLabelGap(pieDefinition.getLabelGap()); if (!pieDefinition.isDisplayLabels()) { pie.setLabelGenerator(null); } else { if (pieDefinition.isLegendIncluded()) { StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$ pie.setLabelGenerator(labelGen); } else { StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( "{0} = {1} ({2})"); //$NON-NLS-1$ pie.setLabelGenerator(labelGen); } } } if (plot instanceof MultiplePiePlot) { MultiplePiePlot pies = (MultiplePiePlot) plot; CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition; pies.setDataset(categoryDatasetChartDefintion); } if (plot instanceof MeterPlot) { MeterPlot meter = (MeterPlot) plot; DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition; List intervals = widget.getIntervals(); Iterator intervalIterator = intervals.iterator(); while (intervalIterator.hasNext()) { MeterInterval interval = (MeterInterval) intervalIterator.next(); meter.addInterval(interval); } meter.setNeedlePaint(widget.getNeedlePaint()); meter.setDialShape(widget.getDialShape()); meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint()); meter.setRange(new Range(widget.getMinimum(), widget.getMaximum())); } if (plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; if (chartDefinition instanceof XYSeriesCollectionChartDefinition) { XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition; xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation()); ValueAxis domainAxis = xyPlot.getDomainAxis(); if (domainAxis != null) { domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle()); domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont()); domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels()); if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) { ((NumberAxis) domainAxis) .setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat()); } if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) { domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont()); } if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum()); } if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum()); } } ValueAxis rangeAxis = xyPlot.getRangeAxis(); if (rangeAxis != null) { rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle()); rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont()); if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum()); } if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum()); } if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum()); } if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum()); } if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) { ((NumberAxis) rangeAxis) .setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat()); } if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) { rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont()); } } } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) { TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition; xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation()); ValueAxis domainAxis = xyPlot.getDomainAxis(); if (domainAxis != null) { domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle()); domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont()); domainAxis .setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels()); if (domainAxis instanceof DateAxis) { DateAxis da = (DateAxis) domainAxis; if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) { da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum()); } if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) { da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum()); } } } ValueAxis rangeAxis = xyPlot.getRangeAxis(); if (rangeAxis != null) { rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle()); rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont()); if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum()); } if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum()); } } } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) { XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition; xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation()); ValueAxis domainAxis = xyPlot.getDomainAxis(); if (domainAxis != null) { domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle()); domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont()); domainAxis .setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels()); if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum()); } if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum()); } if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) { ((NumberAxis) domainAxis) .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat()); } if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) { domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont()); } } ValueAxis rangeAxis = xyPlot.getRangeAxis(); if (rangeAxis != null) { rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle()); rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont()); rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum()); if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum()); } if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum()); } if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) { ((NumberAxis) rangeAxis) .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat()); } if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) { rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont()); } } } } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.piecharts.SimplePie.java
public JFreeChart createChart(DatasetMap datasets) { Dataset dataset = (Dataset) datasets.getDatasets().get("1"); JFreeChart chart = null;// ww w . j a va2s .c o m 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})")); } } 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.setNoDataMessages("No data available"); 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})")); } } 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:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Creates a Pie Chart based on map.//from w w w. j av a 2 s . c o m * * @return the Pie Chart generated. */ public JFreeChart getPieChart(Map<String, Double> pieValues) { DefaultPieDataset dataset = new DefaultPieDataset(); for (String key : pieValues.keySet()) { dataset.setValue(key, pieValues.get(key)); } JFreeChart chart = ChartFactory.createPieChart3D(null, // chart title dataset, // data true, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(false); chart.setBorderPaint(null); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(true); plot.setLabelGap(0.02); plot.setOutlinePaint(null); plot.setLabelLinksVisible(false); plot.setLabelGenerator(null); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); plot.setStartAngle(270); plot.setDirection(Rotation.ANTICLOCKWISE); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.33); return chart; }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createPieChart() throws QueryException { pieDataset = new DefaultPieDataset(); String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); JFreeChart jfreechart = ChartFactory.createPieChart(chartTitle, pieDataset, true, true, false); // hide border jfreechart.setBorderVisible(false);/* w ww. j av a 2 s. c o m*/ // title setTitle(jfreechart); PiePlot plot = (PiePlot) jfreechart.getPlot(); plot.setForegroundAlpha(transparency); // a start angle used to create similarities between flash chart and this jfreechart plot.setStartAngle(330); // legend label will contain the text and the value plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1}")); // no shadow plot.setShadowXOffset(0); plot.setShadowYOffset(0); DecimalFormat decimalformat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalformat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalformat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalformat; } boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); if (showValues) { // label will contain also the percentage formatted with two decimals plot.setLabelGenerator( new StandardPieSectionLabelGenerator("{0} ({2})", decimalformat, percentageFormat)); } // chart background plot.setBackgroundPaint(chart.getBackground()); createChart(null, new Object[1]); // after chart creation we can set slices colors List<Comparable> keys = pieDataset.getKeys(); List<Color> colors = chart.getForegrounds(); for (int i = 0, size = colors.size(); i < keys.size(); i++) { plot.setSectionPaint(keys.get(i), colors.get(i % size)); plot.setLabelFont(chart.getFont()); } return jfreechart; }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private byte[] generatePieChart(String siteId, PieDataset dataset, int width, int height, boolean render3d, float transparency, boolean smallFontInDomainAxis) { JFreeChart chart = null;/*from ww w . ja v a 2 s.c o m*/ if (render3d) chart = ChartFactory.createPieChart3D(null, dataset, false, false, false); else chart = ChartFactory.createPieChart(null, dataset, false, false, false); PiePlot plot = (PiePlot) chart.getPlot(); // set start angle (135 or 150 deg so minor data has more space on the left) plot.setStartAngle(150D); // set transparency plot.setForegroundAlpha(transparency); // set background chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); plot.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); // fix border offset chart.setPadding(new RectangleInsets(5, 5, 5, 5)); plot.setInsets(new RectangleInsets(1, 1, 1, 1)); // set chart border plot.setOutlinePaint(null); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set antialias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { LOG.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.operamasks.faces.render.graph.PieChartRenderer.java
protected JFreeChart createChart(UIChart comp) { Dataset dataset = createDataset(comp); JFreeChart chart = null;/*from ww w . j a v a 2 s .c om*/ PiePlot pieplot = null; boolean ring = Coercion.coerceToBoolean(comp.getAttributes().get("ring")); if (dataset instanceof CategoryDataset) { CategoryDataset catset = (CategoryDataset) dataset; if (catset.getRowCount() == 1) { PieDataset pieset = new CategoryToPieDataset(catset, TableOrder.BY_ROW, 0); if (ring) { chart = ChartFactory.createRingChart(null, pieset, false, false, false); } else if (comp.isEffect3D()) { chart = ChartFactory.createPieChart3D(null, pieset, false, false, false); } else { chart = ChartFactory.createPieChart(null, pieset, false, false, false); } pieplot = (PiePlot) chart.getPlot(); } else { if (comp.isEffect3D()) { chart = ChartFactory.createMultiplePieChart3D(null, catset, TableOrder.BY_ROW, false, false, false); } else { chart = ChartFactory.createMultiplePieChart(null, catset, TableOrder.BY_ROW, false, false, false); } pieplot = (PiePlot) ((MultiplePiePlot) chart.getPlot()).getPieChart().getPlot(); } } if (pieplot != null) { if (!comp.isDrawItemLabel()) { pieplot.setLabelGenerator(null); } if (comp.isShowItemTips()) { pieplot.setToolTipGenerator(new StandardPieToolTipGenerator()); } Object startAngle = comp.getAttributes().get("startAngle"); if (startAngle != null) { pieplot.setStartAngle(Coercion.coerceToDouble(startAngle)); } } return chart; }
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 ww . j av a 2 s . 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: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 v a 2s . c om*/ } 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; }