use of org.jfree.chart.plot.MultiplePiePlot in project pentaho-platform by pentaho.
the class JFreeChartEngine method updatePlot.
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);
}
// TODO define outline stroke
plot.setOutlineStroke(null);
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()) {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}");
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()) {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})");
pie.setLabelGenerator(labelGen);
} else {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})");
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());
}
}
}
}
}
use of org.jfree.chart.plot.MultiplePiePlot in project pentaho-platform by pentaho.
the class JFreeChartEngine method createMultiplePieChart.
private static JFreeChart createMultiplePieChart(final CategoryDatasetChartDefinition chartDefinition) {
// TODO Make the following accessible from the chartDefinition
TableOrder order = TableOrder.BY_ROW;
// boolean tooltips = true;
// boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
if (order == null) {
throw new IllegalArgumentException(Messages.getInstance().getString(// $NON-NLS-1$
"JFreeChartEngine.ERROR_0001_NULL_ORDER_ARGUMENT"));
}
MultiplePiePlot plot = new MultiplePiePlot(chartDefinition);
JFreeChartEngine.updatePlot(plot, chartDefinition);
plot.setDataExtractOrder(order);
JFreeChart pieCharts = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
JFreeChart pieChart = plot.getPieChart();
// $NON-NLS-1$ //$NON-NLS-2$
TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
seriesTitle.setPosition(RectangleEdge.BOTTOM);
pieChart.setTitle(seriesTitle);
pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
plot.setPieChart(pieChart);
return pieCharts;
}
use of org.jfree.chart.plot.MultiplePiePlot in project pdfbox-graphics2d by rototor.
the class MultiPageTest method createChartCategory.
/**
* Creates a sample chart for the given dataset.
*
* @param dataset
* the dataset.
*
* @return A sample chart.
*/
private JFreeChart createChartCategory(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 4", dataset, TableOrder.BY_COLUMN, false, true, false);
chart.setBackgroundPaint(new Color(216, 255, 216));
final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
final JFreeChart subchart = plot.getPieChart();
// final StandardLegend legend = new StandardLegend();
// legend.setItemFont(new Font("SansSerif", Font.PLAIN, 8));
// legend.setAnchor(Legend.SOUTH);
// subchart.setLegend(legend);
plot.setLimit(0.10);
final PiePlot p = (PiePlot) subchart.getPlot();
// p.setLabelGenerator(new StandardPieItemLabelGenerator("{0}"));
p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
p.setInteriorGap(0.30);
return chart;
}
use of org.jfree.chart.plot.MultiplePiePlot in project dhis2-core by dhis2.
the class DefaultChartService method getMultiplePieChart.
private JFreeChart getMultiplePieChart(PlotData plotData, CategoryDataset[] dataSets) {
JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart(plotData.getName(), dataSets[0], TableOrder.BY_ROW, !plotData.isHideLegend(), false, false);
setBasicConfig(multiplePieChart, plotData);
if (multiplePieChart.getLegend() != null) {
multiplePieChart.getLegend().setItemFont(SUB_TITLE_FONT);
}
MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
JFreeChart pieChart = multiplePiePlot.getPieChart();
pieChart.setBackgroundPaint(DEFAULT_BACKGROUND_COLOR);
pieChart.getTitle().setFont(SUB_TITLE_FONT);
PiePlot piePlot = (PiePlot) pieChart.getPlot();
piePlot.setBackgroundPaint(DEFAULT_BACKGROUND_COLOR);
piePlot.setOutlinePaint(DEFAULT_BACKGROUND_COLOR);
piePlot.setLabelFont(LABEL_FONT);
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}"));
piePlot.setSimpleLabels(true);
piePlot.setIgnoreZeroValues(true);
piePlot.setIgnoreNullValues(true);
piePlot.setShadowXOffset(0d);
piePlot.setShadowYOffset(0d);
for (int i = 0; i < dataSets[0].getColumnCount(); i++) {
piePlot.setSectionPaint(dataSets[0].getColumnKey(i), COLORS[(i % COLORS.length)]);
}
return multiplePieChart;
}
use of org.jfree.chart.plot.MultiplePiePlot in project SIMVA-SoS by SESoS.
the class ChartFactory method createMultiplePieChart3D.
/**
* Creates a chart that displays multiple pie plots. The chart object
* returned by this method uses a {@link MultiplePiePlot} instance as the
* plot.
*
* @param title the chart title (<code>null</code> permitted).
* @param dataset the dataset (<code>null</code> permitted).
* @param order the order that the data is extracted (by row or by column)
* (<code>null</code> not permitted).
* @param legend include a legend?
* @param tooltips generate tooltips?
* @param urls generate URLs?
*
* @return A chart.
*/
public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls) {
ParamChecks.nullNotPermitted(order, "order");
MultiplePiePlot plot = new MultiplePiePlot(dataset);
plot.setDataExtractOrder(order);
plot.setBackgroundPaint(null);
plot.setOutlineStroke(null);
JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
seriesTitle.setPosition(RectangleEdge.BOTTOM);
pieChart.setTitle(seriesTitle);
pieChart.removeLegend();
pieChart.setBackgroundPaint(null);
plot.setPieChart(pieChart);
if (tooltips) {
PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
pp.setToolTipGenerator(tooltipGenerator);
}
if (urls) {
PieURLGenerator urlGenerator = new StandardPieURLGenerator();
PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
pp.setURLGenerator(urlGenerator);
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
currentTheme.apply(chart);
return chart;
}
Aggregations