Search in sources :

Example 16 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project seng438-a3-R41Ryan by seng438-winter-2022.

the class ChartFactory method createRingChart.

/**
 * Creates a ring chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link RingPlot}
 * instance as the plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param locale  the locale (<code>null</code> not permitted).
 *
 * @return A ring chart.
 *
 * @since 1.0.7
 */
public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) {
    RingPlot plot = new RingPlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : RingPlot(org.jfree.chart.plot.RingPlot) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) RectangleInsets(org.jfree.ui.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator)

Example 17 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project seng438-a3-R41Ryan by seng438-winter-2022.

the class ChartFactory method createPieChart.

/**
 * Creates a pie chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link PiePlot} instance
 * as the plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A pie chart.
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls) {
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) RectangleInsets(org.jfree.ui.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator)

Example 18 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project jgnash by ccavanaugh.

the class PayeePieChart method createPieChart.

private JFreeChart createPieChart(Account a, PieDataset[] data, int index) {
    PiePlot plot = new PiePlot(data[index]);
    // rebuilt each time because they're based on the account's commodity
    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);
    BigDecimal thisTotal = BigDecimal.ZERO;
    for (int i = 0; i < data[index].getItemCount(); i++) {
        thisTotal = thisTotal.add((BigDecimal) (data[index].getValue(i)));
    }
    BigDecimal acTotal = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();
    String title = "";
    String subtitle = "";
    // pick an appropriate title(s)
    if (index == CREDIT) {
        title = a.getPathName();
        subtitle = rb.getString("Column.Credit") + " : " + valueFormat.format(thisTotal);
    } else if (index == DEBIT) {
        title = rb.getString("Column.Balance") + " : " + valueFormat.format(acTotal);
        subtitle = rb.getString("Column.Debit") + " : " + valueFormat.format(thisTotal);
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);
    return chart;
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) BigDecimal(java.math.BigDecimal) JFreeChart(org.jfree.chart.JFreeChart) NumberFormat(java.text.NumberFormat)

Example 19 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator 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 20 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project dhis2-core by dhis2.

the class DefaultChartService method getMultiplePieChart.

private JFreeChart getMultiplePieChart(BaseChart chart, CategoryDataset[] dataSets) {
    JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart(chart.getName(), dataSets[0], TableOrder.BY_ROW, !chart.isHideLegend(), false, false);
    setBasicConfig(multiplePieChart, chart);
    if (multiplePieChart.getLegend() != null) {
        multiplePieChart.getLegend().setItemFont(SUB_TITLE_FONT);
    }
    MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
    JFreeChart pieChart = multiplePiePlot.getPieChart();
    pieChart.setBackgroundPaint(COLOR_TRANSPARENT);
    pieChart.getTitle().setFont(SUB_TITLE_FONT);
    PiePlot piePlot = (PiePlot) pieChart.getPlot();
    piePlot.setBackgroundPaint(COLOR_TRANSPARENT);
    piePlot.setOutlinePaint(COLOR_TRANSPARENT);
    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;
}
Also used : StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)72 PiePlot (org.jfree.chart.plot.PiePlot)47 JFreeChart (org.jfree.chart.JFreeChart)31 DecimalFormat (java.text.DecimalFormat)30 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)30 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)26 PieSectionLabelGenerator (org.jfree.chart.labels.PieSectionLabelGenerator)24 MultiplePiePlot (org.jfree.chart.plot.MultiplePiePlot)21 File (java.io.File)17 IOException (java.io.IOException)17 Connection (java.sql.Connection)16 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 Statement (java.sql.Statement)16 DateFormat (java.text.DateFormat)16 SimpleDateFormat (java.text.SimpleDateFormat)16 ImageIcon (javax.swing.ImageIcon)16 BlueSeerUtils.currformatDouble (com.blueseer.utl.BlueSeerUtils.currformatDouble)13 RectangleInsets (org.jfree.ui.RectangleInsets)13 Font (java.awt.Font)12