Search in sources :

Example 16 with PieDataset

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

the class DiscPlot method setDataset.

/**
     * Sets the dataset and sends a {@link DatasetChangeEvent} to 'this'.
     *
     * @param dataset  the dataset (<code>null</code> permitted).
     * 
     * @see #getDataset()
     */
public void setDataset(PieDataset dataset) {
    // if there is an existing dataset, remove the plot from the list of
    // change listeners...
    PieDataset existing = this.dataset;
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    // set the new dataset, and register the chart as a change listener...
    this.dataset = dataset;
    if (dataset != null) {
        setDatasetGroup(dataset.getGroup());
        dataset.addChangeListener(this);
    }
    // tell the item distributor about the change
    if (discDistributor != null) {
        discDistributor.setDataset(dataset);
    }
    // send a dataset change event to self...
    DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
    datasetChanged(event);
}
Also used : PieDataset(org.jfree.data.general.PieDataset) DatasetChangeEvent(org.jfree.data.general.DatasetChangeEvent)

Example 17 with PieDataset

use of org.jfree.data.general.PieDataset in project EnrichmentMapApp by BaderLab.

the class RadialHeatMapLayer method createDataset.

// ==[ PRIVATE METHODS ]============================================================================================
@Override
protected PieDataset createDataset() {
    List<Double> values = data.isEmpty() ? null : data.values().iterator().next();
    // All the slices must have the same size
    Double[] equalValues = values.isEmpty() ? null : new Double[values.size()];
    if (equalValues != null)
        Arrays.fill(equalValues, new Double(1));
    final PieDataset dataset = createPieDataset(equalValues != null ? Arrays.asList(equalValues) : null);
    if (showItemLabels && itemLabels != null) {
        final List<?> keys = dataset.getKeys();
        for (int i = 0; i < keys.size(); i++) {
            String k = (String) keys.get(i);
            String label = itemLabels.size() > i ? itemLabels.get(i) : null;
            if (label == null && values.size() > i)
                label = "" + values.get(i);
            labels.put(k, label);
        }
    }
    return dataset;
}
Also used : PieDataset(org.jfree.data.general.PieDataset)

Example 18 with PieDataset

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

the class PayeePieChart method createPanel.

private JPanel createPanel() {
    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    JButton addFilterButton = new JButton(rb.getString("Button.AddFilter"));
    final JButton saveButton = new JButton(rb.getString("Button.SaveFilters"));
    JButton deleteFilterButton = new JButton(rb.getString("Button.DeleteFilter"));
    JButton clearPrefButton = new JButton(rb.getString("Button.MasterDelete"));
    filterCombo = new JComboBox<>();
    startField = new DatePanel();
    endField = new DatePanel();
    txtAddFilter = new TextField();
    filterList = new ArrayList<>();
    filtersChanged = false;
    useFilters = new JCheckBox(rb.getString("Label.UseFilters"));
    useFilters.setSelected(true);
    showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
    combo = AccountListComboBox.getFullInstance();
    final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now().minusYears(DEBIT));
    long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
    startField.setDate(DateUtils.asLocalDate(start));
    currentAccount = combo.getSelectedAccount();
    PieDataset[] data = createPieDataSet(currentAccount);
    JFreeChart chartCredit = createPieChart(currentAccount, data, CREDIT);
    chartPanelCredit = new ChartPanel(chartCredit, true, true, true, false, true);
    //                         (chart, properties, save, print, zoom, tooltips)
    JFreeChart chartDebit = createPieChart(currentAccount, data, DEBIT);
    chartPanelDebit = new ChartPanel(chartDebit, true, true, true, false, true);
    FormLayout layout = new FormLayout("p, $lcgap, 70dlu, 8dlu, p, $lcgap, 70dlu, $ugap, p, $lcgap:g, left:p", "d, $rgap, d, $ugap, f:p:g, $rgap, d");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    layout.setRowGroups(new int[][] { { DEBIT, 3 } });
    // row 1
    builder.append(combo, 9);
    builder.append(useFilters);
    builder.nextLine();
    builder.nextLine();
    // row 3
    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(refreshButton);
    builder.append(showPercentCheck);
    builder.nextLine();
    builder.nextLine();
    // row 5
    FormLayout subLayout = new FormLayout("180dlu:g, 1dlu, 180dlu:g", "f:180dlu:g");
    DefaultFormBuilder subBuilder = new DefaultFormBuilder(subLayout);
    subBuilder.append(chartPanelCredit);
    subBuilder.append(chartPanelDebit);
    builder.append(subBuilder.getPanel(), 11);
    builder.nextLine();
    builder.nextLine();
    // row 7
    builder.append(txtAddFilter, 3);
    builder.append(addFilterButton, 3);
    builder.append(saveButton);
    builder.nextLine();
    // row
    builder.append(filterCombo, 3);
    builder.append(deleteFilterButton, 3);
    builder.append(clearPrefButton);
    builder.nextLine();
    JPanel panel = builder.getPanel();
    combo.addActionListener(e -> {
        Account newAccount = combo.getSelectedAccount();
        if (filtersChanged) {
            int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.SaveFilters"), "Warning", JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION) {
                saveButton.doClick();
            }
        }
        filtersChanged = false;
        String[] list = POUND_DELIMITER_PATTERN.split(pref.get(FILTER_TAG + newAccount.hashCode(), ""));
        filterList.clear();
        for (String filter : list) {
            if (!filter.isEmpty()) {
                filterList.add(filter);
            }
        }
        refreshFilters();
        setCurrentAccount(newAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });
    refreshButton.addActionListener(e -> {
        setCurrentAccount(currentAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });
    clearPrefButton.addActionListener(e -> {
        int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.MasterDelete"), "Warning", JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            try {
                pref.clear();
            } catch (Exception ex) {
                System.out.println("Exception clearing preferences" + ex);
            }
        }
    });
    saveButton.addActionListener(e -> {
        final StringBuilder sb = new StringBuilder();
        for (String filter : filterList) {
            sb.append(filter);
            sb.append('#');
        }
        pref.put(FILTER_TAG + currentAccount.hashCode(), sb.toString());
        filtersChanged = false;
    });
    addFilterButton.addActionListener(e -> {
        String newFilter = txtAddFilter.getText();
        filterList.remove(newFilter);
        if (!newFilter.isEmpty()) {
            filterList.add(newFilter);
            filtersChanged = true;
            txtAddFilter.setText("");
        }
        refreshFilters();
    });
    deleteFilterButton.addActionListener(e -> {
        if (!filterList.isEmpty()) {
            String filter = (String) filterCombo.getSelectedItem();
            filterList.remove(filter);
            filtersChanged = true;
        }
        refreshFilters();
    });
    useFilters.addActionListener(e -> setCurrentAccount(currentAccount));
    showPercentCheck.addActionListener(e -> {
        ((PiePlot) chartPanelCredit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
        ((PiePlot) chartPanelDebit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
    });
    return panel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JPanel(javax.swing.JPanel) Account(jgnash.engine.Account) ChartPanel(org.jfree.chart.ChartPanel) JButton(javax.swing.JButton) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) JCheckBox(javax.swing.JCheckBox) PieDataset(org.jfree.data.general.PieDataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) DatePanel(jgnash.ui.components.DatePanel) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) TextField(java.awt.TextField) PiePlot(org.jfree.chart.plot.PiePlot)

Example 19 with PieDataset

use of org.jfree.data.general.PieDataset in project xwiki-platform by xwiki.

the class TablePieDatasetBuilderTest method testBuildPieDataset.

@Test
public void testBuildPieDataset() throws Exception {
    String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "pie", "range", "B2-D3"), null);
    ChartModel chartModel = getDataSource().getChartModel();
    Dataset dataset = chartModel.getDataset();
    Assert.assertTrue(dataset instanceof PieDataset);
    PieDataset pieDataset = (PieDataset) dataset;
    Assert.assertTrue(pieDataset.getKey(0).equals(" row 1 "));
    Assert.assertTrue(pieDataset.getKey(1).equals(" row 2 "));
    Assert.assertTrue(pieDataset.getValue(0).intValue() == 12);
    Assert.assertTrue(pieDataset.getValue(1).intValue() == 22);
}
Also used : PieDataset(org.jfree.data.general.PieDataset) Dataset(org.jfree.data.general.Dataset) PieDataset(org.jfree.data.general.PieDataset) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

Example 20 with PieDataset

use of org.jfree.data.general.PieDataset in project xwiki-platform by xwiki.

the class TablePieDatasetBuilderTest method testBuildPieDatasetRowsSeries.

@Test
public void testBuildPieDatasetRowsSeries() throws Exception {
    String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "pie", "range", "B2-D3", "series", "rows"), null);
    ChartModel chartModel = getDataSource().getChartModel();
    Dataset dataset = chartModel.getDataset();
    Assert.assertTrue(dataset instanceof PieDataset);
    PieDataset pieDataset = (PieDataset) dataset;
    Assert.assertTrue(pieDataset.getKey(0).equals(" column 2 "));
    Assert.assertTrue(pieDataset.getKey(1).equals(" column 3 "));
    Assert.assertTrue(pieDataset.getKey(2).equals(" column 4"));
    Assert.assertTrue(pieDataset.getValue(0).intValue() == 12);
    Assert.assertTrue(pieDataset.getValue(1).intValue() == 13);
    Assert.assertTrue(pieDataset.getValue(2).intValue() == 14);
}
Also used : PieDataset(org.jfree.data.general.PieDataset) Dataset(org.jfree.data.general.Dataset) PieDataset(org.jfree.data.general.PieDataset) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

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