use of org.jfree.chart.plot.PiePlot in project pentaho-platform by pentaho.
the class JFreeChartEngine method createPieDatasetChart.
private static JFreeChart createPieDatasetChart(final PieDatasetChartDefinition chartDefinition) {
// TODO Make the following accessible from the chartDefinition
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
PiePlot plot = null;
plot = chartDefinition.isThreeD() ? new PiePlot3D(chartDefinition) : new PiePlot(chartDefinition);
JFreeChartEngine.updatePlot(plot, chartDefinition);
JFreeChart pieChart = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
// $NON-NLS-1$ //$NON-NLS-2$
TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
seriesTitle.setPosition(RectangleEdge.BOTTOM);
pieChart.setTitle(title);
pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
if (tooltips) {
PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
plot.setToolTipGenerator(tooltipGenerator);
}
if (urls) {
PieURLGenerator urlGenerator = new StandardPieURLGenerator();
plot.setURLGenerator(urlGenerator);
}
return pieChart;
}
use of org.jfree.chart.plot.PiePlot in project jfreechart-fx by jfree.
the class ScrollHandlerFX method handleScroll.
@Override
public void handleScroll(ChartCanvas canvas, ScrollEvent e) {
JFreeChart chart = canvas.getChart();
Plot plot = chart.getPlot();
if (plot instanceof Zoomable) {
Zoomable zoomable = (Zoomable) plot;
handleZoomable(canvas, zoomable, e);
} else if (plot instanceof PiePlot) {
PiePlot pp = (PiePlot) plot;
pp.handleMouseWheelRotation((int) e.getDeltaY());
}
}
use of org.jfree.chart.plot.PiePlot in project xwiki-platform by xwiki.
the class PiePlotFactory method create.
@Override
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
DefaultPieDataset dataset = new DefaultPieDataset();
String dataSeries = params.getString(ChartParams.SERIES);
if (dataSeries.equals("columns")) {
for (int row = 0; row < dataSource.getRowCount(); row++) {
if (dataSource.hasHeaderColumn()) {
String category = dataSource.getHeaderColumnValue(row);
dataset.setValue(category, dataSource.getCell(row, 0));
} else {
dataset.setValue("Category " + (row + 1), dataSource.getCell(row, 0));
}
}
} else if (dataSeries.equals("rows")) {
for (int column = 0; column < dataSource.getColumnCount(); column++) {
if (dataSource.hasHeaderRow()) {
String category = dataSource.getHeaderRowValue(column);
dataset.setValue(category, dataSource.getCell(0, column));
} else {
dataset.setValue("Category " + (column + 1), dataSource.getCell(0, column));
}
}
} else {
throw new GenerateException("Invalid series parameter:" + dataSeries);
}
Class plotClass = params.getClass(ChartParams.RENDERER);
PiePlot plot;
if (plotClass != null) {
try {
Constructor ctor = plotClass.getConstructor(new Class[] { PieDataset.class });
plot = (PiePlot) ctor.newInstance(new Object[] { dataset });
} catch (Throwable e) {
throw new GenerateException(e);
}
} else {
plot = new PiePlot(dataset);
}
ChartCustomizer.customizePiePlot(plot, params);
return plot;
}
use of org.jfree.chart.plot.PiePlot in project xwiki-platform by xwiki.
the class PiePlotGenerator method generate.
@Override
public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException {
PieDataset dataset;
try {
dataset = (PieDataset) model.getDataset();
} catch (ClassCastException e) {
throw new PlotGeneratorException("Incompatible dataset for the pie plot.");
}
PiePlot piePlot = new PiePlot(dataset);
// Allow customizing the label to use
String pieLabelFormat = parameters.get(PIE_LABEL_FORMAT_KEY);
if (pieLabelFormat != null) {
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(pieLabelFormat, NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));
}
return piePlot;
}
use of org.jfree.chart.plot.PiePlot in project cytoscape-impl by cytoscape.
the class PieLayer method createChart.
@Override
protected JFreeChart createChart(final PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart(// chart title
null, // data
dataset, // include legend
false, // tooltips
false, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final PiePlot plot = (PiePlot) chart.getPlot();
plot.setCircular(true);
plot.setStartAngle(startAngle);
plot.setDirection(rotation == Rotation.ANTICLOCKWISE ? org.jfree.util.Rotation.ANTICLOCKWISE : org.jfree.util.Rotation.CLOCKWISE);
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setInteriorGap(INTERIOR_GAP);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setShadowPaint(TRANSPARENT_COLOR);
plot.setShadowXOffset(0.0);
plot.setShadowYOffset(0.0);
plot.setLabelGenerator(showItemLabels ? new CustomPieSectionLabelGenerator(labels) : null);
plot.setSimpleLabels(true);
plot.setLabelFont(plot.getLabelFont().deriveFont(itemFontSize));
plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
plot.setLabelShadowPaint(TRANSPARENT_COLOR);
plot.setLabelPaint(labelColor);
final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final List<?> keys = dataset.getKeys();
for (int i = 0; i < keys.size(); i++) {
final String k = (String) keys.get(i);
final Color c = colors.size() > i ? colors.get(i) : DEFAULT_ITEM_BG_COLOR;
plot.setSectionPaint(k, c);
plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
plot.setSectionOutlineStroke(k, stroke);
}
return chart;
}
Aggregations