Example usage for org.jfree.data.general DefaultPieDataset setValue

List of usage examples for org.jfree.data.general DefaultPieDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.general DefaultPieDataset setValue.

Prototype

public void setValue(Comparable key, double value) 

Source Link

Document

Sets the data value for a key and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:edu.uara.wrappers.customcharts.CustomPieChart.java

@Override
public void updateChart(CustomDatasetTable dsTable, ITableObject source) {
    if (ds != null)//update multipiedataset
    {/*from   w  ww .j  av a2 s. co m*/
        DefaultCategoryDataset dataset = (DefaultCategoryDataset) ds;
        String[] rowLabels = dsTable.getRowLabels();
        String[] columnLabels = dsTable.getColumnLabels(source);
        double[][] values = dsTable.getTableContentAsValue(source);
        for (int r = 0; r < rowLabels.length; r++) {
            for (int c = 0; c < columnLabels.length; c++) {
                dataset.setValue(values[r][c], rowLabels[r], columnLabels[c]);

            }
        }

    } else if (pieDs != null)//single pie dataset
    {
        DefaultPieDataset pieDataset = (DefaultPieDataset) pieDs;
        String[] rowLabels = dsTable.getRowLabels();
        String[] columnLabels = dsTable.getColumnLabels(source);
        double[][] values = dsTable.getTableContentAsValue(source);
        if (tableOrder == TableOrder.BY_ROW) {
            int r;//index of the series in the main dataset
            for (r = 0; r < rowLabels.length; r++) {
                if (rowLabels[r].equals(this.singlePieDatasetSeries))
                    ;
                break;
            }
            for (int c = 0; c < columnLabels.length; c++) {
                pieDataset.setValue(columnLabels[c], values[r][c]);
            }
        } else if (tableOrder == TableOrder.BY_COLUMN) {
            int c;//index of the series in the main dataset
            for (c = 0; c < columnLabels.length; c++) {
                if (columnLabels[c].equals(this.singlePieDatasetSeries))
                    ;
                break;
            }
            for (int r = 0; r < rowLabels.length; r++) {
                pieDataset.setValue(rowLabels[r], values[r][c]);
            }

        }

    }

}

From source file:UserInterface.CentreForDiseaseControl.DataAnalysis.java

private void salesDetailJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salesDetailJButtonActionPerformed
    // TODO add your handling code here:
    int totalVaccinesSold = 0;
    int totalQuantity = 0;
    VaccineManufacturerEnterprise popularManufacturer = null;
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    for (VaccineManufacturerEnterprise manufactureres : enterprise.getVaccineManufacturerList()) {
        for (Order order : enterprise.getMasterOrderCatalog().getOrderList()) {
            for (OrderItem orderItem : order.getOrderItemList()) {
                if (orderItem.getVaccine().getVaccineManufacturer() == manufactureres) {
                    totalQuantity = totalQuantity + orderItem.getTotalQuantity();
                    if (totalQuantity > totalVaccinesSold) {
                        totalVaccinesSold = totalQuantity;
                        popularManufacturer = manufactureres;
                    }/*from w  w w . j av  a  2  s  . co  m*/
                }
            }
        }
        pieDataset.setValue(manufactureres.getName(), totalQuantity);
        totalQuantity = 0;
    }

    JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
    PiePlot p = (PiePlot) chart.getPlot();
    ChartFrame frame = new ChartFrame("Sale details of Manufacturers", chart);
    frame.setVisible(true);
    frame.setSize(450, 500);

}

From source file:servlets.LeasingControllerServlet.java

private PieDataset createDataset() {
    DefaultPieDataset result = new DefaultPieDataset();
    result.setValue("F&B", 25);
    result.setValue("Retail", 0);
    result.setValue("Entertainment", 25);
    result.setValue("Event", 25);
    return result;
}

From source file:statisticslabro.StatisticsLabr.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    List<String> Temp = new ArrayList<String>();
    List<String> check = new ArrayList<String>();
    List<Double> fnl = new ArrayList<>();
    List<String> frame = new ArrayList<String>();
    List<String> name = new ArrayList<String>();
    List<String> name2 = new ArrayList<String>();
    List<Double> frame2 = new ArrayList<Double>();
    List<Double> limitLeft = new ArrayList<>();
    List<Double> limitRight = new ArrayList<>();
    List<Double> trueLimitLeft = new ArrayList<>();
    List<Double> trueLimitRight = new ArrayList<>();
    List<Double> midpoint = new ArrayList<>();
    List<Integer> frequency = new ArrayList<>();
    List<Double> percent = new ArrayList<>();
    List<Integer> cf = new ArrayList<>();
    List<Double> cp = new ArrayList<>();

    Integer freq = 0;/*w  w w .ja v  a2s.  c o m*/
    Double freqtot = 0.0;

    if (Categorical.isSelected() == true && Numerical.isSelected() == false) {
        for (int i = 0; i < jTable1.getRowCount(); i++) {
            frame.add((String) jTable1.getModel().getValueAt(i, 0));
        }
        Collections.sort(frame);

        Integer size = frame.size();
        System.out.println(size);
        for (Object b : frame) {
            String c = b + "";
            Temp.add(c);
        }

        for (int i = 0; i < jTable1.getRowCount(); i++) {
            for (int j = 0; j < jTable1.getColumnCount(); j++) {
                jTable1.setValueAt("", i, j);
            }
        }

        int ct = 0;
        for (Object z : frame) {
            String a = z + "";
            System.out.print(check.contains(a));
            if (!(check.contains(a))) {
                for (int i = 0; i < Temp.size(); i++) {
                    if (a.equals(Temp.get(i))) {
                        freq++;
                    }
                }
                Double freque = (((freq + .0) / size) * 100);
                fnl.add(freque);
                name.add(a);
                freqtot += freque;
                jTable1.getModel().setValueAt(a, ct, 0);
                jTable1.getModel().setValueAt(String.format("%1.1f", freque) + "%", ct, 1);
                ct++;
                freq = 0;

                check.add(a);
            }
            total.setText("Total :" + String.format("%1.1f", freqtot));
        }

        if (Chart.isSelected() == true) {
            DefaultPieDataset chart = new DefaultPieDataset();

            int h = 0;
            for (Double z : fnl) {
                chart.setValue(name.get(h) + "", new Double(z));
                h++;
            }
            JFreeChart mychart = ChartFactory.createPieChart3D(Desc.getText() + "", chart, true, true, true);
            PiePlot3D p = (PiePlot3D) mychart.getPlot();
            ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
            charteuFrame.setVisible(true);
            charteuFrame.setSize(450, 500);
        }

    } else if (Numerical.isSelected() == true && Categorical.isSelected() == false) {
        double subtrahend = 0.5;

        for (int i = 0; i < jTable1.getRowCount();) {
            double d = Double.parseDouble((String) jTable1.getModel().getValueAt(i, 0));
            frame2.add(d);
            i++;
        }
        double max = 0;
        double min = frame2.get(0);
        for (int j = 0; j < frame2.size(); j++) {
            System.out.print("Sulod");
            if (max < frame2.get(j)) {
                max = frame2.get(j);
            }
            if (min > frame2.get(j)) {
                min = frame2.get(j);
            }
        }

        System.out.print(frame2);
        double range = max - min;
        double k = Math.ceil(1 + 3.322 * Math.log10(frame2.size()));
        int width = (int) Math.ceil(range / k);

        System.out.println("char:   " + max + " " + min + " " + range + " " + k + " width: " + width);
        double limit = min;
        while (limit < max) {
            limitLeft.add(limit);
            limit += width;
        }

        for (int j = 0; j < limitLeft.size(); j++) {
            System.out.print(limitLeft.get(j) + " ");
        }

        double limit2 = min + width - 1;
        while (limit2 <= max) {
            limitRight.add(limit2);
            limit2 += width;
        }

        if (limitRight.get(limitRight.size() - 1) != max) {
            limitRight.add(max);
        }

        System.out.println();
        for (int j = 0; j < limitRight.size(); j++) {
            System.out.print(limitRight.get(j) + " ");
        }

        //true limit
        if (((String) choice.getSelectedItem()).equals("Integer")) {

            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitLeft.size(); j++) {
                System.out.print(trueLimitLeft.get(j) + " ");
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitRight.size(); j++) {
                System.out.print(trueLimitRight.get(j) + " ");
            }

        } else if (((String) choice.getSelectedItem()).equals("Floating")) {

            int count1 = 0;
            float diff = 0;
            boolean flag = false;

            for (int j = 0; j < frame2.size(); j++) {
                double value = Math.floor(frame2.get(j));
                System.out.println(frame.get(j));
                diff = (float) (frame2.get(j) - value);
                System.out.println("diff: " + diff);
                String counts = String.valueOf(diff);
                if (diff > 0.0) {
                    if (counts.length() - 1 > count1) {
                        count1 = counts.length() - 1;
                        System.out.println(count1);
                    }
                }
            }

            System.out.println(count1);

            for (int j = 0; j < count1 - 1; j++) {
                subtrahend /= 10;
                System.out.println(subtrahend);
            }

            System.out.println("sub: " + subtrahend);
            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - subtrahend);
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + subtrahend);
            }
        }
        //midpoint
        for (int j = 0; j < limitLeft.size(); j++) {
            midpoint.add((limitLeft.get(j) + limitRight.get(j)) / 2);
        }

        System.out.println();
        for (int j = 0; j < midpoint.size(); j++) {
            System.out.print(midpoint.get(j) + " ");
        }

        //frequency
        for (int j = 0; j < limitLeft.size(); j++) {
            int count = 0;
            for (int m = 0; m < frame2.size(); m++) {
                if (frame2.get(m) >= limitLeft.get(j) && frame2.get(m) <= limitRight.get(j)) {
                    count++;
                }
            }
            frequency.add(count);
        }

        System.out.println();
        for (int j = 0; j < frequency.size(); j++) {
            System.out.print(frequency.get(j) + " ");
        }

        //percent
        for (int j = 0; j < frequency.size(); j++) {
            double pp = (((double) frequency.get(j) / frame2.size()) * 100);
            percent.add(pp);
        }

        System.out.println();
        for (int j = 0; j < percent.size(); j++) {
            System.out.print(percent.get(j) + " ");
        }

        int cff = 0;
        for (int j = 0; j < frequency.size(); j++) {
            cff += frequency.get(j);
            cf.add(cff);
        }

        System.out.println();
        for (int j = 0; j < cf.size(); j++) {
            System.out.print(cf.get(j) + " ");
        }

        double cpp = 0;
        for (int j = 0; j < percent.size(); j++) {
            cpp += percent.get(j);
            cp.add(cpp);
        }

        System.out.println();

        for (int j = 0; j < cp.size(); j++) {
            System.out.print(cp.get(j) + " ");
        }

        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        dtm.setRowCount(limitLeft.size());

        int ct = 0;
        if (collapse.isSelected() == true) {
            for (int j = 0; j < limitLeft.size(); j++) {
                if (ct == 0) {
                    jTable1.getModel().setValueAt("< " + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add("<");
                } else if (ct == limitLeft.size() - 1) {
                    jTable1.getModel().setValueAt("> " + limitLeft.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add(">");
                } else {
                    jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                    name.add(midpoint.get(j) + "");
                }
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }

        } else {
            for (int j = 0; j < limitLeft.size(); j++) {

                jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                name.add(midpoint.get(j) + "");
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }
        }

    }

    if (Chart.isSelected() == true) {
        DefaultCategoryDataset chart = new DefaultCategoryDataset();

        int h = 0;
        for (Integer z : frequency) {
            chart.setValue(z, "Frequency", name.get(h));
            h++;
        }
        JFreeChart mychart = ChartFactory.createBarChart(Desc.getText() + "", "Midpoint", "Frequency", chart,
                PlotOrientation.VERTICAL, true, false, false);
        CategoryPlot p = (CategoryPlot) mychart.getPlot();
        p.setDomainGridlinesVisible(true);
        p.getDomainAxis().setCategoryMargin(0.0);
        ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
        charteuFrame.setVisible(true);
        charteuFrame.setSize(450, 500);
    }
}

From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void chartMouseClicked(ChartMouseEvent chartMouseEvent) {
    ChartEntity entity = chartMouseEvent.getEntity();
    MouseEvent mouseEvent = chartMouseEvent.getTrigger();

    if (SwingUtilities.isLeftMouseButton(mouseEvent) && entity != null && entity instanceof PieSectionEntity) {
        java.util.List<String> names = dataset.getTransactionTypeNames();
        PieSectionEntity pieSectionEntity = (PieSectionEntity) entity;
        int idx = pieSectionEntity.getSectionIndex();

        String name = (String) JOptionPane.showInputDialog(null, "Enter the name for this transaction type",
                "Transaction Type", JOptionPane.PLAIN_MESSAGE, null, null, "");

        if (name != null) {
            if (names.contains(name) && !names.get(idx).equals(name) && !name.isEmpty()) {
                JOptionPane.showMessageDialog(null,
                        "Please enter a different name for the transaction type.\nEach name has to be unique.",
                        "Warning", JOptionPane.WARNING_MESSAGE);
            } else {
                PieDataset oldDataset = pieSectionEntity.getDataset();
                DefaultPieDataset newDataset = new DefaultPieDataset();

                PiePlot plot = (PiePlot) chart.getPlot();
                String oldName = (String) oldDataset.getKey(idx);
                names.set(idx, name);//  w ww.j a v a 2s .  co m
                dataset.setTransactionTypeName(idx, name);

                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    Number number = oldDataset.getValue(i);

                    if (key.equals(oldName)) {
                        if (name.isEmpty())
                            newDataset.setValue("Transaction Type " + (i + 1), number);
                        else
                            newDataset.setValue(name, number);
                    } else {
                        newDataset.setValue(key, number);
                    }
                }

                Paint[] tempPaint = new Paint[oldDataset.getItemCount()];
                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    tempPaint[i] = plot.getSectionPaint(key);
                }

                ((DefaultPieDataset) oldDataset).clear();
                plot.setDataset(newDataset);

                for (int i = 0; i < newDataset.getItemCount(); ++i) {
                    String key = (String) newDataset.getKey(i);
                    plot.setSectionPaint(key, tempPaint[i]);
                }
            }
        }
    }
}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the relative usage of the given
 * projects against the given collaborator.
 * // www .  j  av  a  2  s  . c  om
 * @param projectCollabTable
 * @return
 */
private DefaultPieDataset createProjectDataset(
        Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable, CollaboratorBean collab) {

    DefaultPieDataset pds = new DefaultPieDataset();

    // add project summary info

    for (ProjectBean project : projectCollabTable.keySet()) {
        CollaboratorBean collabBean = projectCollabTable.get(project)
                .get(projectCollabTable.get(project).indexOf(collab));
        if (collabBean != null) {
            pds.setValue(project.getName() + " Used", new Double(collabBean.getTotalUsage().getUsed()));
            pds.setValue(project.getName() + " Avail.", new Double(collabBean.getTotalUsage().getBalance()));
            // keep track of the current project so we can explode that piece
            // of the pie.
            if (project.equals(GridChem.project)) {
                defaultProjectIndex = pds.getItemCount() - 1;
            }
        }
    }

    return pds;
}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private PieDataset createPieDataSet(Account a) {
    DefaultPieDataset returnValue = new DefaultPieDataset();
    if (a != null) {

        BigDecimal total = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate(),
                a.getCurrencyNode());//from ww  w  . j  a v a 2s  . c om

        // abs() on all values won't work if children aren't of uniform sign,
        // then again, this chart is not right to display those trees
        boolean negate = total != null && total.floatValue() < 0;

        // accounts may have balances independent of their children
        BigDecimal value = a.getBalance(startField.getLocalDate(), endField.getLocalDate());

        if (value.compareTo(BigDecimal.ZERO) != 0) {
            returnValue.setValue(a, negate ? value.negate() : value);
        }

        for (final Account child : a.getChildren(Comparators.getAccountByCode())) {
            value = child.getTreeBalance(startField.getLocalDate(), endField.getLocalDate(),
                    a.getCurrencyNode());

            if (showEmptyCheck.isSelected() || value.compareTo(BigDecimal.ZERO) != 0) {
                returnValue.setValue(child, negate ? value.negate() : value);
            }
        }
    }
    return returnValue;
}

From source file:org.lsug.quota.web.internal.portlet.SiteConfigurationQuotaWebPortlet.java

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    StringBundler sb = new StringBundler(5);

    JFreeChart jFreeChart = null;//from  w ww.  ja  v  a 2  s  .co m

    DefaultPieDataset pieDataset = new DefaultPieDataset();

    try {
        long groupId = PortalUtil.getScopeGroupId(resourceRequest);

        Group group = _groupLocalService.getGroup(groupId);

        long classNameId = 0;

        if (QuotaUtil.isValidGroupQuota(group)) {
            classNameId = group.getClassNameId();

            if (group.isStagingGroup()) {
                groupId = group.getLiveGroupId();
            }
        }

        Quota siteQuota = _quotaLocalService.getQuotaByClassNameIdClassPK(classNameId, groupId);

        ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language",
                resourceRequest.getLocale(), getClass());

        if (siteQuota.isEnabled()) {
            pieDataset.setValue(LanguageUtil.get(resourceBundle, "used-space"),
                    siteQuota.getQuotaUsedPercentage());
            pieDataset.setValue(LanguageUtil.get(resourceBundle, "unused-space"),
                    100 - siteQuota.getQuotaUsedPercentage());
        }

        sb.append(LanguageUtil.get(resourceBundle, "sites-quota-enabled-sites-used-diagram-title"));

        jFreeChart = getCurrentSizeJFreeChart(sb.toString(), pieDataset);

        resourceResponse.setContentType(ContentTypes.IMAGE_PNG);

        OutputStream outputStream = null;

        try {
            outputStream = resourceResponse.getPortletOutputStream();
            ChartUtilities.writeChartAsPNG(outputStream, jFreeChart, 400, 200);
        } finally {
            if (outputStream != null) {
                outputStream.close();
            }
        }

    } catch (Exception e) {
        LOGGER.error(e);
        throw new PortletException(e);
    }
}

From source file:statisticsintegration.StatisticsLabr.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    List<String> Temp = new ArrayList<String>();
    List<String> check = new ArrayList<String>();
    List<Double> fnl = new ArrayList<>();
    List<String> frame = new ArrayList<String>();
    List<String> name = new ArrayList<String>();
    List<String> name2 = new ArrayList<String>();
    List<Double> frame2 = new ArrayList<Double>();
    List<Double> limitLeft = new ArrayList<>();
    List<Double> limitRight = new ArrayList<>();
    List<Double> trueLimitLeft = new ArrayList<>();
    List<Double> trueLimitRight = new ArrayList<>();
    List<Double> midpoint = new ArrayList<>();
    List<Integer> frequency = new ArrayList<>();
    List<Double> percent = new ArrayList<>();
    List<Integer> cf = new ArrayList<>();
    List<Double> cp = new ArrayList<>();

    Integer freq = 0;/*  w  w w  .j a va  2 s.c o m*/
    Double freqtot = 0.0;

    if (Categorical.isSelected() == true && Numerical.isSelected() == false) {
        for (int i = 0; i < jTable1.getRowCount(); i++) {
            frame.add((String) jTable1.getModel().getValueAt(i, 0));
        }
        Collections.sort(frame);

        Integer size = frame.size();
        System.out.println(size);
        for (Object b : frame) {
            String c = b + "";
            Temp.add(c);
        }

        for (int i = 0; i < jTable1.getRowCount(); i++) {
            for (int j = 0; j < jTable1.getColumnCount(); j++) {
                jTable1.setValueAt("", i, j);
            }
        }

        int ct = 0;
        for (Object z : frame) {
            String a = z + "";
            System.out.print(check.contains(a));
            if (!(check.contains(a))) {
                for (int i = 0; i < Temp.size(); i++) {
                    if (a.equals(Temp.get(i))) {
                        freq++;
                    }
                }
                Double freque = (((freq + .0) / size) * 100);
                fnl.add(freque);
                name.add(a);
                freqtot += freque;
                jTable1.getModel().setValueAt(a, ct, 0);
                jTable1.getModel().setValueAt(String.format("%1.1f", freque) + "%", ct, 1);
                ct++;
                freq = 0;

                check.add(a);
            }
            total.setText("Total :" + String.format("%1.1f", freqtot));
        }

        if (Chart.isSelected() == true) {
            DefaultPieDataset chart = new DefaultPieDataset();

            int h = 0;
            for (Double z : fnl) {
                chart.setValue(name.get(h) + "", new Double(z));
                h++;
            }
            JFreeChart mychart = ChartFactory.createPieChart3D(Desc.getText() + "", chart, true, true, true);
            PiePlot3D p = (PiePlot3D) mychart.getPlot();
            ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
            charteuFrame.setVisible(true);
            charteuFrame.setSize(450, 500);
        }

    } else if (Numerical.isSelected() == true && Categorical.isSelected() == false) {
        double subtrahend = 0.5;

        for (int i = 0; i < jTable1.getRowCount();) {
            double d = Double.parseDouble((String) jTable1.getModel().getValueAt(i, 0));
            frame2.add(d);
            i++;
        }
        double max = 0;
        double min = frame2.get(0);
        for (int j = 0; j < frame2.size(); j++) {
            System.out.print("Sulod");
            if (max < frame2.get(j)) {
                max = frame2.get(j);
            }
            if (min > frame2.get(j)) {
                min = frame2.get(j);
            }
        }

        System.out.print(frame2);
        double range = max - min;
        double k = Math.ceil(1 + 3.322 * Math.log10(frame2.size()));
        int width = (int) Math.ceil(range / k);

        System.out.println("char:   " + max + " " + min + " " + range + " " + k + " width: " + width);
        double limit = min;
        while (limit < max) {
            limitLeft.add(limit);
            limit += width;
        }

        for (int j = 0; j < limitLeft.size(); j++) {
            System.out.print(limitLeft.get(j) + " ");
        }

        double limit2 = min + width - 1;
        while (limit2 <= max) {
            limitRight.add(limit2);
            limit2 += width;
        }

        if (limitRight.get(limitRight.size() - 1) != max) {
            limitRight.add(max);
        }

        System.out.println();
        for (int j = 0; j < limitRight.size(); j++) {
            System.out.print(limitRight.get(j) + " ");
        }

        //true limit
        if (((String) choice.getSelectedItem()).equals("Integer")) {

            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitLeft.size(); j++) {
                System.out.print(trueLimitLeft.get(j) + " ");
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitRight.size(); j++) {
                System.out.print(trueLimitRight.get(j) + " ");
            }

        } else if (((String) choice.getSelectedItem()).equals("Floating")) {

            int count1 = 0;
            float diff = 0;
            boolean flag = false;

            for (int j = 0; j < frame2.size(); j++) {
                double value = Math.floor(frame2.get(j));
                //                    System.out.println(frame.get(j));
                diff = (float) (frame2.get(j) - value);
                System.out.println("diff: " + diff);
                String counts = String.valueOf(diff);
                if (diff > 0.0) {
                    if (counts.length() - 1 > count1) {
                        count1 = counts.length() - 1;
                        System.out.println(count1);
                    }
                }
            }

            System.out.println(count1);

            for (int j = 0; j < count1 - 1; j++) {
                subtrahend /= 10;
                System.out.println(subtrahend);
            }

            System.out.println("sub: " + subtrahend);
            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - subtrahend);
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + subtrahend);
            }
        }
        //midpoint
        for (int j = 0; j < limitLeft.size(); j++) {
            midpoint.add((limitLeft.get(j) + limitRight.get(j)) / 2);
        }

        System.out.println();
        for (int j = 0; j < midpoint.size(); j++) {
            System.out.print(midpoint.get(j) + " ");
        }

        //frequency
        for (int j = 0; j < limitLeft.size(); j++) {
            int count = 0;
            for (int m = 0; m < frame2.size(); m++) {
                if (frame2.get(m) >= limitLeft.get(j) && frame2.get(m) <= limitRight.get(j)) {
                    count++;
                }
            }
            frequency.add(count);
        }

        System.out.println();
        for (int j = 0; j < frequency.size(); j++) {
            System.out.print(frequency.get(j) + " ");
        }

        //percent
        for (int j = 0; j < frequency.size(); j++) {
            double pp = (((double) frequency.get(j) / frame2.size()) * 100);
            percent.add(pp);
        }

        System.out.println();
        for (int j = 0; j < percent.size(); j++) {
            System.out.print(percent.get(j) + " ");
        }

        int cff = 0;
        for (int j = 0; j < frequency.size(); j++) {
            cff += frequency.get(j);
            cf.add(cff);
        }

        System.out.println();
        for (int j = 0; j < cf.size(); j++) {
            System.out.print(cf.get(j) + " ");
        }

        double cpp = 0;
        for (int j = 0; j < percent.size(); j++) {
            cpp += percent.get(j);
            cp.add(cpp);
        }

        System.out.println();

        for (int j = 0; j < cp.size(); j++) {
            System.out.print(cp.get(j) + " ");
        }

        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        dtm.setRowCount(limitLeft.size());

        int ct = 0;
        if (collapse.isSelected() == true) {
            for (int j = 0; j < limitLeft.size(); j++) {
                if (ct == 0) {
                    jTable1.getModel().setValueAt("< " + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add("<");
                } else if (ct == limitLeft.size() - 1) {
                    jTable1.getModel().setValueAt("> " + limitLeft.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add(">");
                } else {
                    jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                    name.add(midpoint.get(j) + "");
                }
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }

        } else {
            for (int j = 0; j < limitLeft.size(); j++) {

                jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                name.add(midpoint.get(j) + "");
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }
        }
        if (Chart.isSelected() == true) {
            DefaultCategoryDataset chart = new DefaultCategoryDataset();

            int h = 0;
            for (Integer z : frequency) {
                chart.setValue(z, "Frequency", name.get(h));
                h++;
            }
            JFreeChart mychart = ChartFactory.createBarChart(Desc.getText() + "", "Midpoint", "Frequency",
                    chart, PlotOrientation.VERTICAL, true, false, false);
            CategoryPlot p = (CategoryPlot) mychart.getPlot();
            p.setDomainGridlinesVisible(true);
            p.getDomainAxis().setCategoryMargin(0.0);
            ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
            charteuFrame.setVisible(true);
            charteuFrame.setSize(450, 500);
        }
    }
}

From source file:org.martus.client.swingui.actions.ActionMenuCharts.java

private DefaultPieDataset createPieDataset(HashMap<String, Integer> counts) {
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    Vector<String> keys = new Vector<String>(counts.keySet());
    Collections.sort(keys, new SaneCollator(getLocalization().getCurrentLanguageCode()));
    for (String value : keys) {
        Integer count = counts.get(value);
        if (value.length() == 0)
            value = getLocalization().getFieldLabel("ChartItemLabelBlank");
        else/* w  w w  . j a va2  s  .  c om*/
            value = fontHelper.getDisplayable(value);
        pieDataset.setValue(value, count);
    }
    return pieDataset;
}