/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Filtros;


import static Filtros.Estadistica.tbl_freq;
import java.awt.Toolkit;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import static Filtros.Graficos_analisis_personalizados.ventana;
import static Filtros.Graficos_analisis_personalizados.tbl_person;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.RowSorter;
import javax.swing.SortOrder;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jopendocument.util.ListAbstractMap;



public class Graficos extends javax.swing.JInternalFrame {



    public Graficos() {
        initComponents();
                try {
            this.setMaximum(true);
        } catch (PropertyVetoException ex) {
            
        }
botones2.add(fila1);
botones2.add(columna1);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botones2 = new javax.swing.ButtonGroup();
        botones3 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbl_graficouniv = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tbl_graficobi = new javax.swing.JTable();
        graficobarras1 = new javax.swing.JButton();
        fila1 = new javax.swing.JRadioButton();
        columna1 = new javax.swing.JRadioButton();
        graficobarras2 = new javax.swing.JButton();
        jpanelcombinaciones = new javax.swing.JPanel();
        cbx_uni = new javax.swing.JComboBox<>();
        jpanel = new javax.swing.JPanel();
        cbx_bi1 = new javax.swing.JComboBox<>();
        cbx_bi2 = new javax.swing.JComboBox<>();
        graficobarras3 = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Gráficos de una y dos variables");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        tbl_graficouniv.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        tbl_graficouniv.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Variable", "Frecuencia"
            }
        ));
        tbl_graficouniv.setRowHeight(20);
        jScrollPane2.setViewportView(tbl_graficouniv);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("Gráfico univariable");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Gráfico bivariable");

        tbl_graficobi.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tbl_graficobi.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Tamaño 1", "1", "1", "1"},
                {"Tamaño 2", "2", "2", "2"},
                {"Tamaño 3", "2", "0", "0"},
                {"Tamaño 4", "4", "4", "5"}
            },
            new String [] {
                "Tamaños", "Forma talon 1", "Forma talon 2", "Forma talon 3"
            }
        ));
        tbl_graficobi.setRowHeight(20);
        jScrollPane4.setViewportView(tbl_graficobi);

        graficobarras1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        graficobarras1.setText("Gráfico de barras");
        graficobarras1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                graficobarras1ActionPerformed(evt);
            }
        });

        fila1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        fila1.setText("Fila");

        columna1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        columna1.setText("Columna");

        graficobarras2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        graficobarras2.setText("Gráfico de dispersión");
        graficobarras2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                graficobarras2ActionPerformed(evt);
            }
        });

        jpanelcombinaciones.setBackground(new java.awt.Color(204, 204, 204));
        jpanelcombinaciones.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jpanelcombinaciones.setToolTipText("");
        jpanelcombinaciones.setLayout(new java.awt.BorderLayout());

        cbx_uni.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbx_uni.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbx_uniItemStateChanged(evt);
            }
        });

        jpanel.setBackground(new java.awt.Color(204, 204, 204));
        jpanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jpanel.setLayout(new java.awt.BorderLayout());

        cbx_bi1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbx_bi1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbx_bi1ItemStateChanged(evt);
            }
        });

        cbx_bi2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbx_bi2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbx_bi2ItemStateChanged(evt);
            }
        });

        graficobarras3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        graficobarras3.setText("Generar tabla");
        graficobarras3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                graficobarras3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
                        .addComponent(cbx_uni, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(cbx_bi1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbx_bi2, 0, 358, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(fila1)
                        .addGap(18, 18, 18)
                        .addComponent(columna1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(graficobarras1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(graficobarras2, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(graficobarras3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jpanel, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                    .addComponent(jpanelcombinaciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(10, 10, 10)
                        .addComponent(cbx_uni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addComponent(jpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(46, 46, 46)
                .addComponent(jLabel2)
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cbx_bi1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbx_bi2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(graficobarras3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                        .addGap(24, 24, 24)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fila1)
                            .addComponent(columna1))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(graficobarras1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(graficobarras2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jpanelcombinaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(69, 69, 69))
        );

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 855, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
ventana=""; 
    }//GEN-LAST:event_formInternalFrameClosing

    private void graficobarras1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graficobarras1ActionPerformed
int colselec = tbl_graficobi.getSelectedColumn();
int filaselec = tbl_graficobi.getSelectedRow();

if((fila1.isSelected()==true)&&(filaselec>-1)){
    hacergraficofila(filaselec);
}
if((columna1.isSelected()==true)&&(colselec>0)){
    hacergraficocolumna(colselec);
}
    }//GEN-LAST:event_graficobarras1ActionPerformed
private void hacergraficocolumna(int colselec){
        try{
     
String variable = tbl_graficobi.getColumnName(colselec);  
String criterio = tbl_graficobi.getColumnName(0);  

String titulo = variable +" según : " +criterio;
DefaultCategoryDataset ds = new DefaultCategoryDataset();

    
    for (int i = 0; i < tbl_graficobi.getRowCount(); i++) {
         int a = Integer.parseInt(String.valueOf(tbl_graficobi.getValueAt(i,colselec)));
         String Valores = tbl_graficobi.getValueAt(i, 0).toString();
         ds.addValue(a, Valores, "");
    }


    JFreeChart jf =ChartFactory.createBarChart3D(titulo, criterio, "Cantidad", ds, PlotOrientation.HORIZONTAL, true, true, true);

    
    CategoryPlot barchrt = jf.getCategoryPlot();
    barchrt.setRangeGridlinePaint(Color.ORANGE);
    ChartPanel barpanel = new ChartPanel(jf);
    jpanelcombinaciones.removeAll();
    jpanelcombinaciones.add(barpanel, BorderLayout.CENTER);
    jpanelcombinaciones.validate();
    

}catch (Exception ex){
    JOptionPane.showMessageDialog(null, "No se puede generar gráfico segun col");
}
    
}

private void hacergraficofila(int filaselec){
 



 String Variable = tbl_graficobi.getValueAt(tbl_graficobi.getSelectedRow(), 0).toString();

 
 String string2 = String.valueOf(cbx_bi2.getSelectedItem());
String[] parts2 = string2.split("/");
String variable2 = parts2[0];
 
String titulo = "Variedades de "+ Variable + " según "+variable2;

try{
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    
    for (int i = 1; i < tbl_graficobi.getColumnCount(); i++) {
        int a = Integer.parseInt(tbl_graficobi.getValueAt(tbl_graficobi.getSelectedRow(), i).toString());
            ds.addValue(a, tbl_graficobi.getColumnName(i), "");
    }


    JFreeChart jf =ChartFactory.createBarChart3D(titulo, "Variedades", "Cantidad", ds, PlotOrientation.HORIZONTAL, true, true, true);

    
    CategoryPlot barchrt = jf.getCategoryPlot();
    barchrt.setRangeGridlinePaint(Color.ORANGE);
    ChartPanel barpanel = new ChartPanel(jf);
    jpanelcombinaciones.removeAll();
    jpanelcombinaciones.add(barpanel, BorderLayout.CENTER);
    jpanelcombinaciones.validate();
    

}catch (Exception ex){
    JOptionPane.showMessageDialog(null, "No se puede generar gráfico");
}
    
    
}

    private void graficobarras2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graficobarras2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_graficobarras2ActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        for (int i = 0; i < tbl_person.getColumnCount(); i++) {
            String col = tbl_person.getColumnName(i)+"  /"+i;
            cbx_uni.addItem(col);
            cbx_bi1.addItem(col);
            cbx_bi2.addItem(col);
        }
        
        
    }//GEN-LAST:event_formInternalFrameOpened

    private void cbx_uniItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbx_uniItemStateChanged
ArrayList<String> columnaString = new ArrayList<>(); 

String string = String.valueOf(cbx_uni.getSelectedItem());
String[] parts = string.split("/");
String aux0 = parts[0];
String aux = parts[1];

int indexcol = Integer.parseInt(aux);

for (int i = 0; i < tbl_person.getRowCount(); i++) {
            
            columnaString.add(String.valueOf(tbl_person.getValueAt(i, indexcol)));

            
        }



//genera tabla

DefaultTableModel dtm = (DefaultTableModel) tbl_graficouniv.getModel();
            
            int filas=dtm.getRowCount();
            for (int i = 0;filas>i; i++) {
                dtm.removeRow(0);
            }
    
ArrayList<String> conjuntodisctint = new ArrayList<>();

    for (int i = 0; i < columnaString.size(); i++) {
        conjuntodisctint.add(columnaString.get(i));
    }
    Set<String> hashSet = new HashSet<>(conjuntodisctint);
        conjuntodisctint.clear();
        conjuntodisctint.addAll(hashSet);
int contador=0;

String [] fila = new String[2];


        
        for (int i = 0; i < conjuntodisctint.size(); i++) {

            for (int j = 0; j < columnaString.size(); j++) {
                 if(conjuntodisctint.get(i).equals(columnaString.get(j))){
                 
                     fila[0]=String.valueOf(conjuntodisctint.get(i));
                     contador = contador+1;
                }
                
            }
                fila[1]=String.valueOf(contador);
                dtm.addRow(fila);
                contador=0;
               
    }
        
 TableRowSorter<TableModel> sorter = new TableRowSorter<>(tbl_graficouniv.getModel());
tbl_graficouniv.setRowSorter(sorter);

List<RowSorter.SortKey> sortKeys = new ArrayList<>(25);
sortKeys.add(new RowSorter.SortKey(1, SortOrder.DESCENDING));
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);  
       
generartablafrecuencias();

    }//GEN-LAST:event_cbx_uniItemStateChanged

    private void cbx_bi1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbx_bi1ItemStateChanged




    }//GEN-LAST:event_cbx_bi1ItemStateChanged

    private void cbx_bi2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbx_bi2ItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_cbx_bi2ItemStateChanged

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

//averiguar col1
String string = String.valueOf(cbx_bi1.getSelectedItem());
String[] parts = string.split("/");
String columna0nombre = parts[0];
String aux1 = parts[1];
int indexcol1 = Integer.parseInt(aux1);
String string2 = String.valueOf(cbx_bi2.getSelectedItem());
String[] parts2 = string2.split("/");
String aux2 = parts2[1];
int indexcol2 = Integer.parseInt(aux2);

//calcular cantidad de filas (es decir, la variedad de la columna 0)

        ArrayList<String> columna0 = new ArrayList<>();
        for (int i = 0; i < tbl_person.getRowCount(); i++) {
            columna0.add(String.valueOf(tbl_person.getValueAt(i, indexcol1)));
        }

        Set<String> hashSet = new HashSet<>(columna0);
        columna0.clear();
        columna0.addAll(hashSet);

        int cantidadfilas = columna0.size();
        System.out.println("cantidad de filas: " + cantidadfilas);
        
//calcular cantidad de columnas (esto es, variedad horizontal mas col0

        ArrayList<String> otrascolumnas = new ArrayList<>();
        for (int i = 0; i < tbl_person.getRowCount(); i++) {
            otrascolumnas.add(String.valueOf(tbl_person.getValueAt(i, indexcol2)));
        }

        Set<String> hashSet2 = new HashSet<>(otrascolumnas);
        otrascolumnas.clear();
        otrascolumnas.addAll(hashSet2);

        int cantidadcols = otrascolumnas.size()+1;
        System.out.println("cantidad de columnas: " + cantidadcols);


        
//declarar datos y headers
Object [][] data = new String[cantidadfilas][cantidadcols];
Object [] headers = new String[cantidadcols];

headers[0]= columna0nombre;

//setea el nombre de las columnas
        for (int i = 1; i < cantidadcols; i++) {
            headers[i]=otrascolumnas.get(i-1);

        }
//setea la primera columna con datos
                for (int i = 0; i < columna0.size(); i++) {
            data[i][0]=columna0.get(i);
        }
        


//setea todo a cero
        for (int i = 0; i < columna0.size(); i++) {
            data[i][0]=columna0.get(i);
        }
               
 
//calculo las combinaciones posibles        
String filas_[] = new String[cantidadfilas];
String columnas_[] = new String[otrascolumnas.size()];
 
        for (int i = 0; i < cantidadfilas; i++) {
            filas_[i]= String.valueOf(columna0.get(i));
        }
 
        for (int i = 0; i < otrascolumnas.size(); i++) {
            columnas_[i]= String.valueOf(otrascolumnas.get(i));
        }
 
//calculo las combinaciones posibles 
String combinaciones[][] = new String[filas_.length][columnas_.length];

        for (int i = 0; i < filas_.length; i++) {
            for (int j = 0; j < columnas_.length; j++) {
                combinaciones[i][j]=filas_[i]+"/"+columnas_[j];
                System.out.println("combinaciones:" +combinaciones[i][j]);
            }
        }

//calculo cantidad de repeticiones
int cantcombinaciones = (cantidadcols-1)*cantidadfilas;
String valorestabla="";
//armo una matriz para que guarde los resultados y la seteo a cero


int conteos[][] = new int[filas_.length][columnas_.length];

        for (int i = 0; i < filas_.length; i++) {
            for (int j = 0; j < columnas_.length; j++) {
                conteos[i][j]=0;
               }
        }

        for (int i = 0; i < tbl_person.getRowCount(); i++) {
                for (int k = 0; k < combinaciones.length; k++) {
                    for (int l = 0; l < combinaciones[k].length; l++) {
                        valorestabla=String.valueOf(tbl_person.getValueAt(i, indexcol1))+"/"+String.valueOf(tbl_person.getValueAt(i, indexcol2));
                        if(valorestabla.equals(combinaciones[k][l])){
//                            System.out.println("valorestabla:" +valorestabla + "//coinciden con combinacion: "+combinaciones[k][l]);
                            conteos[k][l]=conteos[k][l]+1;
                        }
                    
                }
                
            }
        }

           for (int i = 0; i < cantidadfilas; i++) {
               for (int j = 1; j < cantidadcols; j++) {
                   data[i][j]=String.valueOf(conteos[i][j-1]);
                           
               }
        }



  DefaultTableModel dtmbi = new DefaultTableModel(data,
headers);

  tbl_graficobi.setModel(dtmbi);


    }//GEN-LAST:event_graficobarras3ActionPerformed

public void generartablafrecuencias(){
    try{
     
String variable = (tbl_graficouniv.getColumnName(0));  

String titulo = "Tabla de frecuencias de: " +variable;
DefaultCategoryDataset ds = new DefaultCategoryDataset();

    
    for (int i = 0; i < tbl_graficouniv.getRowCount(); i++) {
         int a = Integer.parseInt(String.valueOf(tbl_graficouniv.getValueAt(i,1)));
         String Valores = tbl_graficouniv.getValueAt(i, 0).toString();
         ds.addValue(a, Valores, "");
    }


    JFreeChart jf =ChartFactory.createBarChart3D(titulo, "Variedad", "Cantidad", ds, PlotOrientation.HORIZONTAL, true, true, true);

    
    CategoryPlot barchrt = jf.getCategoryPlot();
    barchrt.setRangeGridlinePaint(Color.ORANGE);
    ChartPanel barpanel = new ChartPanel(jf);
    jpanel.removeAll();
    jpanel.add(barpanel, BorderLayout.CENTER);
    jpanel.validate();
    

}catch (Exception ex){
    JOptionPane.showMessageDialog(null, "No se puede generar gráfico segun col");
}
   
    
}    



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup botones2;
    private javax.swing.ButtonGroup botones3;
    private javax.swing.JComboBox<String> cbx_bi1;
    private javax.swing.JComboBox<String> cbx_bi2;
    private javax.swing.JComboBox<String> cbx_uni;
    private javax.swing.JRadioButton columna1;
    private javax.swing.JRadioButton fila1;
    private javax.swing.JButton graficobarras1;
    private javax.swing.JButton graficobarras2;
    private javax.swing.JButton graficobarras3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JPanel jpanel;
    private javax.swing.JPanel jpanelcombinaciones;
    private javax.swing.JTable tbl_graficobi;
    private javax.swing.JTable tbl_graficouniv;
    // End of variables declaration//GEN-END:variables
}
