Search in sources :

Example 6 with PiePlot

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;
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PieURLGenerator(org.jfree.chart.urls.PieURLGenerator) StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PiePlot3D(org.jfree.chart.plot.PiePlot3D) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 7 with PiePlot

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());
    }
}
Also used : Plot(org.jfree.chart.plot.Plot) PiePlot(org.jfree.chart.plot.PiePlot) Zoomable(org.jfree.chart.plot.Zoomable) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 8 with PiePlot

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;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) Constructor(java.lang.reflect.Constructor) PiePlot(org.jfree.chart.plot.PiePlot) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException)

Example 9 with PiePlot

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;
}
Also used : PieDataset(org.jfree.data.general.PieDataset) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PlotGeneratorException(org.xwiki.chart.PlotGeneratorException)

Example 10 with 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;
}
Also used : BasicStroke(java.awt.BasicStroke) CustomPieSectionLabelGenerator(org.cytoscape.ding.internal.charts.CustomPieSectionLabelGenerator) Color(java.awt.Color) RectangleInsets(org.jfree.ui.RectangleInsets) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

PiePlot (org.jfree.chart.plot.PiePlot)40 JFreeChart (org.jfree.chart.JFreeChart)22 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)16 Font (java.awt.Font)14 TextTitle (org.jfree.chart.title.TextTitle)11 MultiplePiePlot (org.jfree.chart.plot.MultiplePiePlot)10 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)9 RectangleInsets (org.jfree.ui.RectangleInsets)9 Color (java.awt.Color)8 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)8 DecimalFormat (java.text.DecimalFormat)6 PieDataset (org.jfree.data.general.PieDataset)6 BasicStroke (java.awt.BasicStroke)5 Plot (org.jfree.chart.plot.Plot)5 StandardPieURLGenerator (org.jfree.chart.urls.StandardPieURLGenerator)5 ChartPanel (org.jfree.chart.ChartPanel)4 Test (org.junit.Test)4 GradientPaint (java.awt.GradientPaint)3 Paint (java.awt.Paint)3 Iterator (java.util.Iterator)3