Search in sources :

Example 1 with PieDataset

use of org.jfree.data.general.PieDataset in project jgnash by ccavanaugh.

the class IncomeExpensePieChart method createPieChart.

private JFreeChart createPieChart(final Account a) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Objects.requireNonNull(a);
    PieDataset data = createPieDataSet(a);
    PiePlot plot = new PiePlot(data);
    // rebuilt each time because they're based on the account's commodity
    CurrencyNode defaultCurrency = engine.getDefaultCurrency();
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);
    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
    plot.setLabelGap(.02);
    plot.setInteriorGap(.1);
    // own transactions, not just child accounts), separate it from children.
    if (data.getIndex(a) != -1) {
        plot.setExplodePercent(a, .10);
    }
    String title;
    // pick an appropriate title
    if (a.getAccountType() == AccountType.EXPENSE) {
        title = rb.getString("Title.PercentExpense");
    } else if (a.getAccountType() == AccountType.INCOME) {
        title = rb.getString("Title.PercentIncome");
    } else {
        title = rb.getString("Title.PercentDist");
    }
    title = title + " - " + a.getPathName();
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    BigDecimal total = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();
    String subtitle = valueFormat.format(total);
    if (!defaultCurrency.equals(a.getCurrencyNode())) {
        BigDecimal totalDefaultCurrency = total.multiply(a.getCurrencyNode().getExchangeRate(defaultCurrency));
        NumberFormat defaultValueFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
        subtitle += "  -  " + defaultValueFormat.format(totalDefaultCurrency);
    }
    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);
    return chart;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) TextTitle(org.jfree.chart.title.TextTitle) PieDataset(org.jfree.data.general.PieDataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) Engine(jgnash.engine.Engine) JFreeChart(org.jfree.chart.JFreeChart) BigDecimal(java.math.BigDecimal) NumberFormat(java.text.NumberFormat)

Example 2 with PieDataset

use of org.jfree.data.general.PieDataset in project processdash by dtuma.

the class DiscChart method createDiscChart.

public static JFreeChart createDiscChart(ResultSet data, Map parameters) {
    // data.sortBy(1, true);
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getColumnCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
    DiscPlot plot = new DiscPlot(pieData);
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    plot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    if (parameters.get("skipItemLabels") != null || parameters.get("skipDiscLabels") != null)
        plot.setLabelGenerator(null);
    else if (parameters.get("discLabelFontSize") != null)
        try {
            float fontSize = Float.parseFloat((String) parameters.get("discLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {
        }
    if (parameters.get("ellipse") != null)
        ((StandardDiscItemDistributor) plot.getDiscDistributor()).setCircular(false);
    String interiorGap = (String) parameters.get("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = (String) parameters.get("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }
    return chart;
}
Also used : DiscPlot(net.sourceforge.processdash.ui.lib.chart.DiscPlot) PieDataset(org.jfree.data.general.PieDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart)

Example 3 with PieDataset

use of org.jfree.data.general.PieDataset in project processdash by dtuma.

the class PieChart method createChart.

/** Create a  line chart. */
@Override
public JFreeChart createChart() {
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getColumnCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
    JFreeChart chart = null;
    if (get3DSetting()) {
        chart = ChartFactory.createPieChart3D(null, pieData, true, true, false);
        chart.getPlot().setForegroundAlpha(ALPHA);
    } else {
        chart = ChartFactory.createPieChart(null, pieData, true, true, false);
    }
    PiePlot plot = (PiePlot) chart.getPlot();
    if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null)
        plot.setLabelGenerator(null);
    else if (parameters.get("wedgeLabelFontSize") != null)
        try {
            float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {
        }
    if (parameters.get("ellipse") != null)
        plot.setCircular(true);
    else
        plot.setCircular(false);
    Object colorScheme = parameters.get("colorScheme");
    if ("byPhase".equals(colorScheme))
        maybeConfigurePhaseColors(plot, pieData);
    else if ("consistent".equals(colorScheme))
        // since 2.0.9
        configureConsistentColors(plot, pieData);
    else if (parameters.containsKey("c1"))
        configureIndividualColors(plot, pieData);
    String interiorGap = (String) parameters.get("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = (String) parameters.get("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }
    if (!parameters.containsKey("showZeroValues")) {
        plot.setIgnoreZeroValues(true);
        plot.setIgnoreNullValues(true);
    }
    return chart;
}
Also used : PieDataset(org.jfree.data.general.PieDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with PieDataset

use of org.jfree.data.general.PieDataset 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 5 with PieDataset

use of org.jfree.data.general.PieDataset in project cytoscape-impl by cytoscape.

the class RingLayer method createDataset.

// ==[ PRIVATE METHODS ]============================================================================================
@Override
protected PieDataset createDataset() {
    datasetList = new ArrayList<PieDataset>();
    for (final String category : data.keySet()) {
        final List<Double> values = data.get(category);
        final PieDataset ds = createPieDataset(values);
        if (ds != null)
            datasetList.add(ds);
    }
    if (showItemLabels && itemLabels != null && datasetList.size() == 1) {
        final List<?> keys = datasetList.get(0).getKeys();
        for (int i = 0; i < keys.size(); i++) {
            final String k = (String) keys.get(i);
            final String label = itemLabels.size() > i ? itemLabels.get(i) : null;
            labels.put(k, label);
        }
    }
    return datasetList.isEmpty() ? null : datasetList.get(0);
}
Also used : PieDataset(org.jfree.data.general.PieDataset)

Aggregations

PieDataset (org.jfree.data.general.PieDataset)26 JFreeChart (org.jfree.chart.JFreeChart)9 PiePlot (org.jfree.chart.plot.PiePlot)7 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)6 Paint (java.awt.Paint)5 CategoryDataset (org.jfree.data.category.CategoryDataset)4 RectangleInsets (org.jfree.ui.RectangleInsets)4 Rectangle (java.awt.Rectangle)3 Font (java.awt.Font)2 Shape (java.awt.Shape)2 Stroke (java.awt.Stroke)2 Arc2D (java.awt.geom.Arc2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 BigDecimal (java.math.BigDecimal)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)2 CategoryPlot (org.jfree.chart.plot.CategoryPlot)2 Plot (org.jfree.chart.plot.Plot)2 XYPlot (org.jfree.chart.plot.XYPlot)2