List of usage examples for org.jfree.chart.plot PiePlot setExplodePercent
public void setExplodePercent(int section, double percent)
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample pie chart. * * @return a sample pie chart./*www.j a v a2s . c om*/ */ public JFreeChart createPieChartOne() { // create a default chart based on some sample data... final String title = this.resources.getString("pie.pie1.title"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final PieDataset extracted = DatasetUtilities.createPieDatasetForRow(data, 0); final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.orange)); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setCircular(false); // make section 1 explode by 100%... plot.setExplodePercent(1, 1.00); 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;/* w w w . j a va2 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); 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 ww w . ja v a 2 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:org.orbeon.oxf.processor.serializer.legacy.JFreeChartSerializer.java
protected JFreeChart drawChart(ChartConfig chartConfig, final Dataset ds) { JFreeChart chart = null;/* w w w. j a v a 2 s .c o m*/ Axis categoryAxis = null; if (ds instanceof XYSeriesCollection) { categoryAxis = new RestrictedNumberAxis(chartConfig.getCategoryTitle()); } else if (ds instanceof TimeSeriesCollection) { categoryAxis = new DateAxis(chartConfig.getCategoryTitle()); ((DateAxis) categoryAxis).setDateFormatOverride(new SimpleDateFormat(chartConfig.getDateFormat())); if (chartConfig.getCategoryLabelAngle() == 90) { ((DateAxis) categoryAxis).setVerticalTickLabels(true); } else { if (chartConfig.getCategoryLabelAngle() != 0) throw new OXFException( "The only supported values of category-label-angle for time-series charts are 0 or 90"); } } else { categoryAxis = new CategoryAxis(chartConfig.getCategoryTitle()); ((CategoryAxis) categoryAxis).setCategoryLabelPositions(chartConfig.getCategoryLabelPosition()); } NumberAxis valueAxis = new RestrictedNumberAxis(chartConfig.getSerieTitle()); valueAxis.setAutoRangeIncludesZero(chartConfig.getSerieAutoRangeIncludeZero()); AbstractRenderer renderer = null; Plot plot = null; switch (chartConfig.getType()) { case ChartConfig.VERTICAL_BAR_TYPE: case ChartConfig.HORIZONTAL_BAR_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new BarRenderer() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new BarRenderer(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.VERTICAL_BAR_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.STACKED_VERTICAL_BAR_TYPE: case ChartConfig.STACKED_HORIZONTAL_BAR_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new StackedBarRenderer() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new StackedBarRenderer(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.STACKED_VERTICAL_BAR_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.LINE_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new LineAndShapeRenderer(true, false) { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : (new LineAndShapeRenderer(true, false)); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); break; case ChartConfig.AREA_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new AreaRenderer() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new AreaRenderer(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); break; case ChartConfig.VERTICAL_BAR3D_TYPE: case ChartConfig.HORIZONTAL_BAR3D_TYPE: categoryAxis = new CategoryAxis3D(chartConfig.getCategoryTitle()); valueAxis = new NumberAxis3D(chartConfig.getSerieTitle()); renderer = (ds instanceof ItemPaintCategoryDataset) ? new BarRenderer3D() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new BarRenderer3D(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.VERTICAL_BAR3D_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.STACKED_VERTICAL_BAR3D_TYPE: case ChartConfig.STACKED_HORIZONTAL_BAR3D_TYPE: categoryAxis = new CategoryAxis3D(chartConfig.getCategoryTitle()); valueAxis = new NumberAxis3D(chartConfig.getSerieTitle()); renderer = (ds instanceof ItemPaintCategoryDataset) ? new StackedBarRenderer3D() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new StackedBarRenderer3D(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.STACKED_VERTICAL_BAR3D_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.PIE_TYPE: case ChartConfig.PIE3D_TYPE: categoryAxis = null; valueAxis = null; renderer = null; ExtendedPieDataset pds = (ExtendedPieDataset) ds; plot = chartConfig.getType() == ChartConfig.PIE_TYPE ? new PiePlot(pds) : new PiePlot3D(pds); PiePlot pp = (PiePlot) plot; pp.setLabelGenerator(new StandardPieSectionLabelGenerator()); for (int i = 0; i < pds.getItemCount(); i++) { Paint p = pds.getPaint(i); if (p != null) pp.setSectionPaint(i, p); pp.setExplodePercent(i, pds.getExplodePercent(i)); Paint paint = pds.getPaint(i); if (paint != null) pp.setSectionPaint(i, paint); } break; case ChartConfig.XY_LINE_TYPE: renderer = new XYLineAndShapeRenderer(true, false); plot = new XYPlot((XYDataset) ds, (ValueAxis) categoryAxis, (ValueAxis) valueAxis, (XYLineAndShapeRenderer) renderer); break; case ChartConfig.TIME_SERIES_TYPE: renderer = new XYLineAndShapeRenderer(true, false); plot = new XYPlot((XYDataset) ds, (DateAxis) categoryAxis, (ValueAxis) valueAxis, (XYLineAndShapeRenderer) renderer); break; default: throw new OXFException("Chart Type not supported"); } if (categoryAxis != null) { categoryAxis.setLabelPaint(chartConfig.getTitleColor()); categoryAxis.setTickLabelPaint(chartConfig.getTitleColor()); categoryAxis.setTickMarkPaint(chartConfig.getTitleColor()); if (categoryAxis instanceof RestrictedNumberAxis) { ((RestrictedNumberAxis) categoryAxis).setMaxTicks(chartConfig.getMaxNumOfLabels()); } if (categoryAxis instanceof CategoryAxis && chartConfig.getCategoryMargin() != 0) ((CategoryAxis) categoryAxis).setCategoryMargin(chartConfig.getCategoryMargin()); } if (valueAxis != null) { valueAxis.setLabelPaint(chartConfig.getTitleColor()); valueAxis.setTickLabelPaint(chartConfig.getTitleColor()); valueAxis.setTickMarkPaint(chartConfig.getTitleColor()); ((RestrictedNumberAxis) valueAxis).setMaxTicks(chartConfig.getMaxNumOfLabels()); } if (renderer != null) { if (renderer instanceof XYLineAndShapeRenderer) { ((XYLineAndShapeRenderer) renderer).setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); } else { ((CategoryItemRenderer) renderer) .setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } if (renderer instanceof BarRenderer) ((BarRenderer) renderer).setItemMargin(chartConfig.getBarMargin()); int j = 0; for (Iterator i = chartConfig.getValueIterator(); i.hasNext();) { Value v = (Value) i.next(); renderer.setSeriesPaint(j, v.getColor()); j++; } } plot.setOutlinePaint(chartConfig.getTitleColor()); CustomLegend legend = chartConfig.getLegendConfig(); chart = new JFreeChart(chartConfig.getTitle(), TextTitle.DEFAULT_FONT, plot, false); if (legend.isVisible()) { legend.setSources(new LegendItemSource[] { plot }); chart.addLegend(legend); } chart.setBackgroundPaint(chartConfig.getBackgroundColor()); TextTitle textTitle = new TextTitle(chartConfig.getTitle(), TextTitle.DEFAULT_FONT, chartConfig.getTitleColor(), TextTitle.DEFAULT_POSITION, TextTitle.DEFAULT_HORIZONTAL_ALIGNMENT, TextTitle.DEFAULT_VERTICAL_ALIGNMENT, TextTitle.DEFAULT_PADDING); chart.setTitle(textTitle); return chart; }
From source file:cnu.eslab.fileTest.NewJFrame.java
public void PieGraphGenerate(String[] arGrop, double[] arValue, String arTitle, String arSubTitle) { // ?? ?.//from w ww. j ava 2 s .co m DefaultPieDataset data = new DefaultPieDataset(); data.setValue(arGrop[0], arValue[0]); //CPU data.setValue(arGrop[1], arValue[1]); //WIFI data.setValue(arGrop[5], arValue[5]); //3G data.setValue(arGrop[2], arValue[2]); //LED data.setValue(arGrop[3], arValue[3]); //GPS data.setValue(arGrop[4], arValue[4]); //AUDIO //offset data . RectangleInsets pieOffset = new RectangleInsets(50.0, 50.0, 50.0, 50.0); // ? ?. JFreeChart chart = ChartFactory.createPieChart(arTitle, data, true, true, false); TextTitle subTitle = new TextTitle(arSubTitle); chart.setBackgroundPaint(Color.WHITE); chart.addSubtitle(subTitle); PiePlot pieplot = (PiePlot) chart.getPlot(); pieplot.setNoDataMessage("No data available"); pieplot.setExplodePercent("LED", 0.20000000000000001D); pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} mW) ({2} percent)")); pieplot.setLabelBackgroundPaint(new Color(220, 220, 220)); pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); //? /*pieplot.setSectionPaint(arGrop[0], new Color(0,0,0)); pieplot.setSectionPaint(arGrop[1], new Color(60,60,60)); pieplot.setSectionPaint(arGrop[2], new Color(120,120,120)); pieplot.setSectionPaint(arGrop[4], new Color(180,180,180));*/ //pieplot.setSimpleLabels(true); //pieplot.setSimpleLabelOffset(pieOffset); //?? offset? . pieplot.setInteriorGap(0.0D); // ?? ?. ChartPanel chartPanel = new ChartPanel(chart); JFrame f = new JFrame(""); f.setSize(600, 600); f.getContentPane().add(chartPanel); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
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 ww . j av a 2 s .co 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:msi.gama.outputs.layers.ChartLayerStatement.java
private void createSlices(final IScope scope) throws GamaRuntimeException { int i = 0;/* w w w.ja va2 s .c om*/ 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:lucee.runtime.tag.Chart.java
private void chartPie() throws PageException, IOException { // do dataset DefaultPieDataset dataset = new DefaultPieDataset(); ChartSeriesBean csb = _series.get(0); ChartDataBean cdb;//from w w w. j ava 2s . c om List datas = csb.getDatas(); if (sortxaxis) Collections.sort(datas); Iterator itt = datas.iterator(); while (itt.hasNext()) { cdb = (ChartDataBean) itt.next(); dataset.setValue(cdb.getItemAsString(), cdb.getValue()); } JFreeChart chart = show3d ? ChartFactory.createPieChart3D(title, dataset, false, true, true) : ChartFactory.createPieChart(title, dataset, false, true, true); Plot p = chart.getPlot(); PiePlot pp = (PiePlot) p; Font _font = getFont(); pp.setLegendLabelGenerator(new PieSectionLegendLabelGeneratorImpl(_font, chartwidth)); pp.setBaseSectionOutlinePaint(Color.GRAY); // border pp.setLegendItemShape(new Rectangle(7, 7)); pp.setLabelFont(new Font(font, 0, 11)); pp.setLabelLinkPaint(COLOR_333333); pp.setLabelLinkMargin(-0.05); pp.setInteriorGap(0.123); pp.setLabelGenerator(new PieSectionLabelGeneratorImpl(labelFormat)); databackgroundcolor = backgroundcolor; setBackground(chart, p); setBorder(chart, p); setLegend(chart, p, _font); set3d(p); setFont(chart, _font); setTooltip(chart); setScale(chart); // Slice Type and colors boolean doSclice = pieslicestyle == PIE_SLICE_STYLE_SLICED; Color[] colors = csb.getColorlist(); Iterator it = csb.getDatas().iterator(); int count = 0; while (it.hasNext()) { cdb = (ChartDataBean) it.next(); if (doSclice) pp.setExplodePercent(cdb.getItemAsString(), 0.13); if (count < colors.length) { pp.setSectionPaint(cdb.getItemAsString(), colors[count]); } count++; } writeOut(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 . j av a 2 s. c o m 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 PiePlot getPiePlot(List<cfCHARTSERIESData> series, String pieSliceStyle, boolean bShow3D) throws cfmBadFileException { org.jfree.data.general.DefaultPieDataset dataset = new org.jfree.data.general.DefaultPieDataset(); cfCHARTSERIESData seriesData = series.get(0); int num = seriesData.getNumItems(); for (int j = 0; j < num; j++) { dataset.setValue(seriesData.getItemName(j), seriesData.getItemValue(j)); }/*from w w w . ja v a 2 s . c om*/ // Create a pie plot PiePlot plot; if (bShow3D) { plot = new PiePlot3D(dataset); ((PiePlot3D) plot).setDepthFactor(0.1); } else { if (seriesData.getType().equals("pie")) { // It's a 2D pie chart plot = new PiePlot(dataset); } else { // It's a 2D ring chart plot = new org.jfree.chart.plot.RingPlot(dataset); ((org.jfree.chart.plot.RingPlot) plot).setSeparatorsVisible(false); } } // If a colorList attribute was specified on the cfchartseries tag // then set the section paint for each slice of the pie. List<String> colorList = seriesData.getColorList(); if (colorList != null) { for (int i = 0; i < colorList.size(); i++) { plot.setSectionPaint(i, convertStringToColor(colorList.get(i))); } } // Don't display a shadow plot.setShadowPaint(null); // Only display the name in the Legend plot.setLegendLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); // Don't draw an outline around the chart plot.setOutlinePaint(null); if (pieSliceStyle.equals("sliced")) { for (int j = 0; j < num; j++) plot.setExplodePercent(j, .1); } return plot; }