Example usage for org.jfree.data DatasetUtilities createPieDatasetForRow

List of usage examples for org.jfree.data DatasetUtilities createPieDatasetForRow

Introduction

In this page you can find the example usage for org.jfree.data DatasetUtilities createPieDatasetForRow.

Prototype

public static PieDataset createPieDatasetForRow(final CategoryDataset data, final int row) 

Source Link

Document

Creates a pie dataset from a table dataset by taking all the values for a single row.

Usage

From source file:hr.restart.util.chart.ChartXY.java

public void initFrame() throws Exception {

    if (isInstanciated()) {
        if (chartPanel != null)
            mainPanel.remove(chartPanel);
        chartPanel = initGraph();/*from   w w  w .j  a va2 s  .  c  o m*/
        mainPanel.add(chartPanel, BorderLayout.CENTER);
        return;
    }

    setInstanciated(true);

    verifyDialog();

    charts = new ArrayList();
    charts.add(BAR_CHART);
    charts.add(PIE_CHART);

    mainPanel = new JPanel(new BorderLayout());

    buttonsPanel = new JPanel(new FlowLayout());

    JPanel actionsPanel = new JPanel(new BorderLayout());
    JPanel savePanel = new JPanel();

    //adding combobox
    comboBox = new JComboBox(charts.toArray());
    comboBox.addActionListener(this);

    buttonsPanel.add(comboBox);

    //adding filechooser
    JButton btSave = new JButton("Snimi");
    btSave.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ev) {

            try {
                chartPanel.doSaveAs();
            } catch (IOException e) {
                // 
                e.printStackTrace();
                System.out.println(e);
            }
        }
    });
    savePanel.add(btSave);

    //adding printing button
    JButton btPrint = new JButton("Ispis");
    btPrint.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            chartPanel.createChartPrintJob();
        }
    });
    savePanel.add(btPrint);

    //creates datasets
    barDataset = createDataSet();
    pieDataset = DatasetUtilities.createPieDatasetForRow(barDataset, 0);

    String value;
    if (jcb == null)
        value = getAxisY();
    else
        value = colNamesY[jcb.getSelectedIndex()];

    PlotOrientation orientation = PlotOrientation.VERTICAL;

    pieChart = createPieChart(pieDataset, value);
    barChart = createBarChart(barDataset, value, orientation);

    //adding orientation box
    String[] orientations = { "Vertikalni", "Horizontalni" };
    comboBoxOrientation = new JComboBox(orientations);
    comboBoxOrientation.setVisible(false);
    comboBoxOrientation.addItemListener(new ItemListener() {

        /* (non-Javadoc)
           * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
           */
        public void itemStateChanged(ItemEvent e) {
            // TODO Auto-generated method stub
            if (comboBoxOrientation.getSelectedItem() == "Vertikalni")
                selectionChanged(PlotOrientation.VERTICAL);
            else
                selectionChanged(PlotOrientation.HORIZONTAL);
        }
    });

    buttonsPanel.add(comboBoxOrientation);

    // adding combobox
    String[] quantity = { "5", "10", "15" };
    comboBoxQuantity = new JComboBox(quantity);
    comboBoxQuantity.setEditable(true);
    comboBoxQuantity.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            try {
                mainPanel.remove(chartPanel);
            } catch (RuntimeException e1) {
                //e1.printStackTrace();               
            }

            selectionChanged(PlotOrientation.VERTICAL);
        }

    });

    comboBoxQuantity.setSelectedItem(new Integer(getNumberOfElements()).toString());
    buttonsPanel.add(comboBoxQuantity);

    if (jcb != null) {
        if (getDefaultSelectedItem() != null) {
            if (getDefaultSelectedItem().compareTo("") != 0)
                jcb.setSelectedItem(getDefaultSelectedItem());
        }

        buttonsPanel.add(jcb);
    }

    // adding OKPanel
    final OKpanel okPanel = new OKpanel() {
        public void jBOK_actionPerformed() {
            //ok_action();
            chartPanel.createChartPrintJob();
        }

        public void jPrekid_actionPerformed() {
            //            firstESC();
            cancelPressed();

        }
    };

    okPanel.addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent e) {
            //                register the keys action

            okPanel.registerOKPanelKeys(getJdialog());
        }

        public void ancestorMoved(AncestorEvent e) {

        }

        public void ancestorRemoved(AncestorEvent e) {
            okPanel.unregisterOKPanelKeys(getJdialog());
        }
    });

    okPanel.jBOK.setText("Ispis");
    okPanel.jBOK.setIcon(raImages.getImageIcon(raImages.IMGPRINT));

    JButton btSnimi = new JButton("Snimi");
    btSnimi.setIcon(raImages.getImageIcon(raImages.IMGSAVE));
    btSnimi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                chartPanel.doSaveAs();
            } catch (IOException e) {
                // 
                e.printStackTrace();
                System.out.println(e);
            }
        }

    });
    okPanel.add(btSnimi, BorderLayout.WEST);
    mainPanel.add(okPanel, BorderLayout.SOUTH);

    actionsPanel.add(buttonsPanel, BorderLayout.CENTER);
    //actionsPanel.add(savePanel,BorderLayout.SOUTH);   
    actionsPanel.add(okPanel, BorderLayout.SOUTH);
    mainPanel.add(actionsPanel, BorderLayout.SOUTH);

    chartPanel = initGraph();
    mainPanel.add(chartPanel, BorderLayout.CENTER);

    this.getContentPane().add(mainPanel);
}

From source file:hr.restart.util.chart.ChartXY.java

public ChartPanel initGraph() {

    //creates dataset      
    barDataset = createDataSet();/*from w  w  w .j  av  a 2  s .c om*/
    pieDataset = DatasetUtilities.createPieDatasetForRow(barDataset, 0);

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    //creates chart panels
    barChart = createBarChart(barDataset, this.getChartTitle(), orientation);
    pieChart = createPieChart(pieDataset, this.getChartTitle());

    //default      HAS TO BE CHANGED
    return new ChartPanel(barChart);
}

From source file:hr.restart.util.chart.ChartXY.java

private PieDataset createPieDataset() {
    return DatasetUtilities.createPieDatasetForRow(createDataSet(), 0);

}