Example usage for org.jfree.data.category DefaultCategoryDataset setValue

List of usage examples for org.jfree.data.category DefaultCategoryDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset setValue.

Prototype

public void setValue(double value, Comparable rowKey, Comparable columnKey) 

Source Link

Document

Adds or updates a value in the table and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:motor.part.MainPanel.java

private DefaultCategoryDataset createDataset() {
    DefaultCategoryDataset objDataset = new DefaultCategoryDataset();
    try {/*w ww. jav  a2s .c o m*/
        Calendar c = new GregorianCalendar();
        c.set(Calendar.HOUR_OF_DAY, 0); //anything 0 - 23
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        Date dt = c.getTime();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.text.SimpleDateFormat typ = new java.text.SimpleDateFormat("dd-mm-yyyy ");

        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        cal.add(Calendar.DATE, -30);
        //System.out.print(dt);
        Date dt1 = cal.getTime();
        //System.out.print(dt1);
        String datesString;
        int Quantity;
        double Amount;
        for (int i = 0; i < 30; i++) {
            Quantity = 0;
            Amount = 0;
            Calendar cal1 = Calendar.getInstance();
            cal.setTime(dt1);
            cal.add(Calendar.DATE, 1 * i);
            Date dt2 = cal.getTime();
            String currentTime = sdf.format(dt2);
            st1 = conn.createStatement();
            String SQLString;
            SQLString = "SELECT * FROM Sales_Registry WHERE Purchased_at = '" + currentTime + "'  ;";
            //System.out.print(SQLString);
            reslt = st1.executeQuery(SQLString);
            if (!reslt.next())
                continue;
            else {
                do {
                    Quantity += Integer.parseInt(reslt.getString(2));
                    Amount += Double.parseDouble(reslt.getString(3));
                } while (reslt.next());
            }
            datesString = typ.format(dt2);

            // objDataset.setValue(Quantity,"Quantity",datesString);

            objDataset.setValue((int) Amount, "Amount", datesString);

        }

    } catch (SQLException ex) {
        Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
    return objDataset;
}

From source file:skoa.helpers.Graficos.java

private DefaultCategoryDataset obtenerSerieBarras(Vector<String> v) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    File archivo = new File(ruta + "diferenciaAplicada.txt");
    FileReader fr = null;//from w  w  w  .ja  va  2 s .c o  m
    BufferedReader linea = null;
    String line;
    try {
        fr = new FileReader(archivo);
        linea = new BufferedReader(fr); //Se crea para leer las lineas
        int d = 0, m = 0, a = 0, a1 = 0, m1 = 0, d1 = 0, j;
        String aux;
        while ((line = linea.readLine()) != null) { //Lectura del fichero
            int i = line.indexOf("\t");
            String f = line.substring(0, i);
            String valor = line.substring(i + 1);
            //Obtencion del dia, mes y ao de la fecha.
            j = f.indexOf("-");
            aux = f.substring(0, j);
            a = Integer.parseInt(aux);
            f = f.substring(j + 1);
            j = f.indexOf("-");
            aux = f.substring(0, j);
            m = Integer.parseInt(aux);
            f = f.substring(j + 1);
            j = f.indexOf(" ");
            aux = f.substring(0, j);
            d = Integer.parseInt(aux);
            //Obtencion de la hora de la fecha.
            f = f.substring(j + 1);
            if (fechaInicial.contentEquals(""))
                fechaInicial = d + "/" + m + "/" + a + " " + f; //Variable para la grfica
            fechaFinal = d + "/" + m + "/" + a + " " + f;
            j = f.indexOf(":");
            if (a1 == 0 & m1 == 0 & d1 == 0) { //Inicializacin: Primera fecha.
                a1 = a;
                m1 = m;
                d1 = d;
            } else {
                if (a1 != a) {
                    a1 = a;
                    if (m1 != m)
                        m1 = m;
                    if (d1 != d)
                        d1 = d;
                } else if (m1 != m) {
                    m1 = m;
                    if (d1 != d)
                        d1 = d;
                } else if (d1 != d)
                    d1 = d;
            }
            String sa = "", sv = "";
            String fecha = "" + d1 + "-" + m1 + " " + f;
            Double ev;
            for (int l = 0; l < v.size(); l++) {
                int p1 = valor.indexOf("\t");
                if (p1 != (-1)) {
                    sa = valor.substring(0, p1);
                    valor = valor.substring(p1 + 1);
                } else { //Ultimo valor.
                    sa = valor;
                    valor = "";
                }
                int pu = sa.indexOf(" ");
                sv = sa.substring(0, pu - 1);
                ev = Double.parseDouble(sv); //Valor a guardar
                dataset.setValue(ev, nombresDGs.elementAt(l), fecha);
            }
        } //fin while leer lineas
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (null != fr)
                fr.close(); //Se cierra si todo va bien.
        } catch (Exception e2) { //Sino salta una excepcion.
            e2.printStackTrace();
        }
    }
    return dataset;
}

From source file:Sales.TabbedPaneWin.java

private void initCustom() throws Exception {
    ///Client// w ww . j  a  v a  2  s .com
    //setting next CleientID
    nextClientId();
    clientIdTxtF2.setText(getNextClientIdStr());
    //refreshing Table
    try {
        jTable3.setModel(DbUtils.resultSetToTableModel(refreshTableClient()));
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex);
    }
    ////

    ///Agreemnrt
    nextAgreementId();
    agreementIdTxtF1.setText(getNextAgreementIdStr());

    try {
        jTable1.setModel(DbUtils.resultSetToTableModel(OOAgreement.dispalyTableExpiary()));
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex);//Logiing errors
        System.err.println(ex.getMessage());
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Unknown Error", JOptionPane.ERROR_MESSAGE);
    }
    ///////

    ///Invoice
    nextInvoiceId();
    invoiceNoTxtF.setText(getNextInvoiceIdStr());

    incrementations.nextOrderId();
    clientIdTxtF1.setText(incrementations.getNextOrderIdStr());

    try {
        selectItemsTable.setModel(DbUtils.resultSetToTableModel(refreshTableInvoice()));
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex);
    }
    ///

    jLabel45.setVisible(false);
    jLabel70.setVisible(false);
    jLabel73.setVisible(false);
    jLabel72.setVisible(false);
    jLabel18.setVisible(false);
    jLabel43.setVisible(false);
    jLabel1.setVisible(false);
    jLabel44.setVisible(false);
    jLabel71.setVisible(false);
    jLabel74.setVisible(false);
    jLabel75.setVisible(false);
    jLabel67.setVisible(false);
    jLabel74.setVisible(false);
    jLabel76.setVisible(false);

    jLabel80.setVisible(false);
    jLabel79.setVisible(false);
    jLabel82.setVisible(false);
    jLabel77.setVisible(false);
    jLabel78.setVisible(false);
    jLabel81.setVisible(false);
    jLabel83.setVisible(false);
    jLabel85.setVisible(false);
    jLabel84.setVisible(false);

    //Item PIe Chart
    DefaultPieDataset dataSet = new DefaultPieDataset();

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery(
                "Select distinct citem.item_code,citem.`type`,Sum(Invoice_Detail.saleQty) as 'Sum QTy'\n"
                        + "from citem,Invoice_Detail\n" + "where Invoice_Detail.itemCode = citem.item_code \n"
                        + "group by citem.item_code,citem.`type`");

        while (rs.next()) {
            dataSet.setValue(rs.getString("type"), rs.getInt("Sum QTy"));
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    JFreeChart chart = ChartFactory.createPieChart("Products Sold by Brand", dataSet, true, true, true);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(490, 376);

    jPanel11.add(chartPanel);
    jPanel11.setVisible(true);

    //Year Bar chart
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery(
                "select distinct DATE_FORMAT(Invoice.`date`,'%Y')as 'Year',SUM(invoice.grandTotal)\n"
                        + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y')\n" + "");

        while (rs.next()) {
            if (rs.getString("Year") != null) {
                dataset2.setValue(rs.getInt("SUM(invoice.grandTotal)"), rs.getString("Year"),
                        rs.getString("Year"));
            }
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    JFreeChart chart2 = ChartFactory.createBarChart("Yearly Sales", "Year", "Total Sales(Rs)", dataset2,
            PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel2 = new ChartPanel(chart2);
    chartPanel2.setSize(480, 420);

    jPanel18.add(chartPanel2);
    jPanel18.setVisible(true);

    //Month Bar Chart
    DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery(
                "select distinct DATE_FORMAT(Invoice.`date`,'%Y-%m')as 'Month',SUM(invoice.grandTotal)\n"
                        + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y-%m')");

        while (rs.next()) {

            String month = rs.getString("Month");
            if (month != null) {//if no data
                if (String.valueOf(Calendar.getInstance().get(Calendar.YEAR)).equals(month.substring(0, 4))) { //for sum up to curet year only
                    if ("01".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jan", "Jan");
                    } else if ("02".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Feb", "Feb");
                    } else if ("03".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Mar", "Mar");
                    } else if ("04".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Apr", "Apr");
                    } else if ("05".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "May", "May");
                    } else if ("06".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jun", "Jun");
                    } else if ("07".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jul", "Jul");
                    } else if ("08".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Aug", "Aug");
                    } else if ("09".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sep", "Sep");
                    } else if ("10".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Oct", "Oct");
                    } else if ("11".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Nov", "Nov");
                    } else if ("12".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Dec", "Dec");
                    }
                }
            }
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    JFreeChart chart3 = ChartFactory.createBarChart(
            "Monthly Sales of " + String.valueOf(Calendar.getInstance().get(Calendar.YEAR)), "Month",
            "Total Sales(Rs)", dataset3, PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel3 = new ChartPanel(chart3);
    chartPanel3.setSize(480, 431);

    jPanel21.add(chartPanel3);
    jPanel21.setVisible(true);

    //Daily Bar Chart
    DefaultCategoryDataset dataset4 = new DefaultCategoryDataset();
    int weekNo = 1;

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();
        SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;

        ResultSet rs = st.executeQuery(
                "select distinct DATE_FORMAT(Invoice.`date`,'%Y-%m-%d')as 'Day',SUM(invoice.grandTotal)\n"
                        + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y-%m-%d')");

        while (rs.next()) {
            String day = rs.getString("Day");

            if (day != null) {
                if (String.valueOf(Calendar.getInstance().get(Calendar.YEAR)).equals(day.substring(0, 4))) { //for sum up to curet year only

                    date = newDateFormat.parse(day);
                    day = date.toString().substring(0, 3);

                    if (day.equals("Mon")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Mon", "Mon");
                    } else if (day.equals("Tue")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Tue", "Tue");
                    } else if (day.equals("Wed")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Wed", "Wed");
                    } else if (day.equals("Thu")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Thu", "Thu");
                    } else if (day.equals("Fri")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Fri", "Fri");
                    } else if (day.equals("Sat")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sat", "Sat");
                    } else if (day.equals("Sun")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sun", "Sun");
                    }
                }
            }
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    Calendar cal = Calendar.getInstance();
    JFreeChart chart4 = ChartFactory.createBarChart(
            "Daily Sales of " + new SimpleDateFormat("MMM").format(cal.getTime()) + " Week " + weekNo, "Day",
            "Total Sales(Rs)", dataset4, PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel4 = new ChartPanel(chart4);
    chartPanel4.setSize(480, 431);

    jPanel25.add(chartPanel4);
    jPanel25.setVisible(true);
}

From source file:NewGUI.Statistics.java

public void setChart(Boolean isChartBar) {

    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    String sql = "";
    String title1 = "", title2 = "", title3 = "";
    String s1, s2, s3, s4;/* w  w w.jav a2 s .co  m*/
    if (cboxType.getSelectedIndex() == 0) {
        s1 = "importing";
        s2 = "import_type_id";
        s3 = "thu nhp";
        s4 = "import_type";

    } else {
        s1 = "exporting";
        s2 = "export_type_id";
        s3 = "chi tiu";
        s4 = "export_type";
    }
    int caseSQL = 4 * (checkBoxCategory.isSelected() ? 1 : 0) + 2 * (checkBoxMonth.isSelected() ? 1 : 0)
            + (checkBoxYear.isSelected() ? 1 : 0);

    int year = jycFrom.getValue();
    int month = cboxMonth.getSelectedIndex();
    DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    ArrayList<Integer> listAccount = filter.getListAcount();

    for (int i = 0; i < listAccount.size(); i++) {
        String sql1 = "select x.user_id,user.userName,y.name,x.value,x.date from "
                + "(select a.id,a.user_id,a.value,a.date,a.category_id from " + "(select * from "
                + (cboxType.getSelectedIndex() == 0 ? "importing" : "exporting") + " where date between '"
                + df.format(jdcFrom.getDate()).toString() + "' and '" + df.format(jdcTo.getDate()).toString()
                + "' and user_id in(" + getAccountList() + ") " + getStringAmount() + " " + getStringText()
                + " " + getStringCategory() + ") as a," + "(select * from share where user_id = 1 and type_id="
                + (cboxType.getSelectedIndex() == 0 ? 1 : 2) + ")as b where b.transaction_id=a.id)as x,"
                + "user,import_type as y where x.user_id = user.id and x.category_id=y.id";

        sql1 = "(" + sql1 + ")as x";

        switch (caseSQL) {
        case 0:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " group by(year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " cc nm";
            title3 = "";
            break;
        case 1:
            sql = "select sum(value),month(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and year(date)=" + year + " group by (month(date))";
            title1 = "T.";
            title2 = "Bng thng k " + s3 + " trong nm " + year;
            title3 = "";
            break;
        case 2:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " group by (year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " thng " + month + " trong cc nm";
            title3 = "";
            break;
        case 3:
            sql = "select sum(value),name,userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " and year(date)=" + year + " group by name";
            title1 = "";
            title2 = "Bng thng k " + s3 + " thng " + month + " trong nm " + year;
            title3 = "";
            break;
        case 4:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " group by (year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " '" + "' trong cc nm";
            title3 = "";
            break;
        case 5:
            sql = "select sum(value),month(date),userName from " + sql1 + "where user_id=" + listAccount.get(i)
                    + " and year(date)=" + year + " group by (month(date))";
            title1 = "T.";
            title2 = "Bng thng k " + s3 + " '" + "' trong nm " + year;
            title3 = "";
            break;
        case 6:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " group by (year(date))";
            title1 = "";
            title2 = "Bng thng k " + s3 + " '" + "' thng " + month + " trong cc nm";
            title3 = "";
            break;
        case 7:
            sql = "select sum(value),year(date),userName from " + sql1 + " where user_id=" + listAccount.get(i)
                    + " and month(date)=" + month + " and year(date)=" + year;
            title1 = "";
            title2 = "Bng thng k " + s3 + " '" + "' thng " + month + " trong nm " + year;
            title3 = "";
            break;
        }
        System.out.println(sql);
        try {
            ResultSet rs = Database.stm.executeQuery(sql);

            while (rs.next()) {
                categoryDataset.setValue(rs.getInt(1), rs.getString(3), title1 + rs.getString(2));
            }

        } catch (Exception ex) {
            System.out.println("Loi...");
        }

    }

    if (isChartBar) {
        chart = ChartFactory.createBarChart3D("", title2, title3, categoryDataset, PlotOrientation.VERTICAL,
                true, true, false);
    } else {
        chart = ChartFactory.createMultiplePieChart3D(title2, categoryDataset, TableOrder.BY_COLUMN, true, true,
                true);
    }
    chartPanel.setChart(chart);
    jtabpanelView.setSelectedIndex(1);
}

From source file:view.QuestionLab.java

private void prograssButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prograssButtonActionPerformed
    int count1 = 0;
    int count2 = 0;
    int count3 = 0;
    int count4 = 0;
    int count5 = 0;
    int count6 = 0;
    int count7 = 0;
    int count8 = 0;
    int count9 = 0;
    int count10 = 0;
    int count11 = 0;
    int count12 = 0;
    int count13 = 0;
    int count14 = 0;
    int count15 = 0;
    int count16 = 0;
    int count17 = 0;

    int a1 = 0;//w  ww . j a  v a2 s. c om
    int a2 = 0;
    int a3 = 0;
    int a4 = 0;
    int a5 = 0;
    int a6 = 0;
    int a7 = 0;
    int a8 = 0;
    int a9 = 0;
    int a10 = 0;
    int a11 = 0;
    int a12 = 0;
    int a13 = 0;
    int a14 = 0;
    int a15 = 0;
    int a16 = 0;
    int a17 = 0;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int is : answerMap.keySet()) {
        if (newMap.containsKey(is) && Objects.equals(answerMap.get(is), newMap.get(is))) {

            anxCount++;
            int myKey = is;
            if (myKey < 7) {
                count1++;
                a1 = (count1 * 100) / 6;
                System.out.println("Collection Framework Generics :" + a1);
                //System.out.println("Collection Framework Generics :" + a1);
                // dataset.setValue(a1, "gfdg", "Collection Framework Generics");

            } else if (myKey < 8) {
                count2++;
                a2 = (count2 * 100) / 1;
                System.out.println("count 2 :" + a2);
                //  dataset.setValue(a2, "gfdg", "Date Number Currency");
            } else if (myKey < 12) {
                count3++;
                a3 = (count3 * 100) / 3;
                System.out.println("count 3 :" + a3);
                // dataset.setValue(a3, "gfdg", "Development");
            } else if (myKey < 17) {
                count4++;
                a4 = (count4 * 100) / 5;
                System.out.println("count 4 :" + a4);
                //dataset.setValue(a4, "gfdg", "Exception Assertion");
            } else if (myKey < 23) {
                count5++;
                a5 = (count5 * 100) / 6;
                System.out.println("count 5 :" + a5);
                //dataset.setValue(a5, "gfdg", "File IO , Serialization");
            } else if (myKey < 24) {
                count6++;
                a6 = (count6 * 100) / 1;
                System.out.println("count 6 :" + a6);
                //dataset.setValue(a6, "gfdg", "Flow Control");
            } else if (myKey < 27) {
                count7++;
                a7 = (count7 * 100) / 3;
                System.out.println("count 7 :" + a7);
                //dataset.setValue(a7, "gfdg", "Formatting Tokenizing");
            } else if (myKey < 29) {
                count8++;
                a8 = (count8 * 100) / 2;
                System.out.println("count 8 :" + a8);
                //dataset.setValue(a8, "gfdg", "Garbage Collector");
            } else if (myKey < 30) {
                count9++;
                a9 = (count9 * 100) / 1;
                System.out.println("count 9 :" + a9);
                //dataset.setValue(a9, "gfdg", "Inner Classes");
            } else if (myKey < 34) {
                count10++;
                a10 = (count10 * 100) / 4;
                System.out.println("count 10 :" + a10);
                //dataset.setValue(a10, "gfdg", "Interface Var-Args Enum");
            } else if (myKey < 35) {
                count11++;
                a11 = (count11 * 100) / 1;
                System.out.println("count 11 :" + a11);
                //dataset.setValue(a11, "gfdg", "Java Fundamentals, Primitive Data Types Arrays");
            } else if (myKey < 38) {
                count12++;
                a12 = (count12 * 100) / 3;
                System.out.println("count 12 :" + a12);
                //dataset.setValue(a12, "gfdg", "Modifiers Access,Non Access");
            } else if (myKey < 50) {
                count13++;
                a13 = (count13 * 100) / 12;
                System.out.println("count 13 :" + a13);
                //dataset.setValue(a13, "gfdg", "Object Orientation");
            } else if (myKey < 53) {
                count14++;
                a14 = (count14 * 100) / 3;
                System.out.println("count 14 :" + a14);
                //dataset.setValue(a14, "gfdg", "Objects, Variable, Methods");
            } else if (myKey < 55) {
                count15++;
                a15 = (count15 * 100) / 2;
                System.out.println("count 15 :" + a15);
                //dataset.setValue(a15, "gfdg", "String, String Buffer, String Builder");
            } else if (myKey < 59) {
                count16++;
                a16 = (count16 * 100) / 4;
                System.out.println("count 16 :" + a16);
                //dataset.setValue(a16, "gfdg", "Threads");
            } else if (myKey < 61) {
                count17++;
                a17 = (count17 * 100) / 2;
                System.out.println("count 17 :" + a17);
                //dataset.setValue(a17, "gfdg", "Wrapper Classes");
            }
            System.out.println("keys :" + myKey);

            //JFreeChart chart=ChartFactory.create
        }
    }
    //        JFreeChart freeChart = ChartFactory.createBarChart("Marks with catagories", "Subject", "Persentage", dataset, PlotOrientation.VERTICAL, false, true, false);
    //        CategoryPlot plot = freeChart.getCategoryPlot();
    //plot.setRangeGridlinePaint(Color.BLUE);
    //                ChartFrame frame = new ChartFrame("Student Performance", freeChart);
    //                frame.setVisible(true);
    //                frame.setSize(550, 450);
    dataset.setValue(a1, "gfdg", "CollectionFramework,Generics");
    dataset.setValue(a2, "gfdg", "Date,Num,Curr");
    dataset.setValue(a3, "gfdg", "Development");
    dataset.setValue(a4, "gfdg", "Exception");
    dataset.setValue(a5, "gfdg", "File,Serialization");
    dataset.setValue(a6, "gfdg", "Flow Control");
    dataset.setValue(a7, "gfdg", "Tokenizing");
    dataset.setValue(a8, "gfdg", "G.C");
    dataset.setValue(a9, "gfdg", "Inner Classes");
    dataset.setValue(a10, "gfdg", "Interface,Var-Args,Enum");
    dataset.setValue(a11, "gfdg", "Fundamentals,Data Types,Arrays");
    dataset.setValue(a12, "gfdg", "Modifiers");
    dataset.setValue(a13, "gfdg", "OOP");
    dataset.setValue(a14, "gfdg", "Objects,Variable,Methods");
    dataset.setValue(a15, "gfdg", "String, String Buffer, String Builder");
    dataset.setValue(a16, "gfdg", "Threads");
    dataset.setValue(a17, "gfdg", "Wrapper Classes");
    JFreeChart freeChart = ChartFactory.createBarChart("Marks with catagories", "Subject", "Persentage",
            dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = freeChart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.BLUE);
    ChartFrame frame = new ChartFrame("Student Performance", freeChart);
    frame.setVisible(true);
    frame.setSize(1500, 750);

    System.out.println("Correct :" + anxCount);
    System.out.println("Percentage :" + (anxCount * 100) / 60 + "%");
    System.out.println("submit answers " + answerMap);
    System.out.println("correct answers " + newMap);
    try {
        controller.removeObserve(studentObserverImpl);
    } catch (RemoteException ex) {
        Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:app.RunApp.java

/**
 * Set frequency of labelsets//from   w ww .j  a  v a 2  s  .  c om
 * 
 * @param jtable Table
 * @param dataset Dataset
 * @param stat Statistics
 * @param cp Plot
 * @return Generated TableModel
 * @throws Exception 
 */
private TableModel labelsetsFrequencyTableModel(JTable jtable, MultiLabelInstances dataset, Statistics stat,
        CategoryPlot cp) throws Exception {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    DefaultCategoryDataset myData = new DefaultCategoryDataset();

    tableModel.addColumn("Labelset Id");
    tableModel.addColumn("# Examples");
    tableModel.addColumn("Frequency");

    double freq;

    //Labelsets frequency
    HashMap<LabelSet, Integer> result = stat.labelCombCount();
    labelsetStringsByFreq = new ArrayList<>(result.size());

    double sum = 0.0;
    Set<LabelSet> keysets = result.keySet();

    Object[] row = new Object[3];

    int count = 1;

    ArrayList<ImbalancedFeature> listImbalanced = new ArrayList();
    ImbalancedFeature temp;

    int value;
    for (LabelSet current : keysets) {
        value = result.get(current);
        temp = new ImbalancedFeature(current.toString(), value);
        listImbalanced.add(temp);
    }

    labelsetsSorted = new ImbalancedFeature[listImbalanced.size()];
    labelsetsFrequency = new double[listImbalanced.size()];

    while (!listImbalanced.isEmpty()) {
        temp = Utils.getMax(listImbalanced);
        labelsetsSorted[count - 1] = temp;
        value = temp.getAppearances();
        labelsetsFrequency[count - 1] = value;
        row[0] = count;
        freq = value * 1.0 / dataset.getNumInstances();
        sum += freq;

        String valueFreq = Double.toString(freq);
        row[1] = value;

        row[2] = MetricUtils.getValueFormatted(valueFreq, 4);
        tableModel.addRow(row);

        String id = "ID: " + Integer.toString(count);

        myData.setValue(freq, id, "");
        labelsetStringsByFreq.add(temp.getName());

        count++;
        listImbalanced.remove(temp);
    }

    jtable.setModel(tableModel);
    jtable.setBounds(jtable.getBounds());

    TableColumnModel tcm = jtable.getColumnModel();
    tcm.getColumn(0).setPreferredWidth(50);
    tcm.getColumn(1).setPreferredWidth(50);
    tcm.getColumn(2).setPreferredWidth(60);

    //graph
    cp.setDataset(myData);

    sum = sum / keysets.size();
    Marker start = new ValueMarker(sum);
    start.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    start.setLabel("                        Mean: " + MetricUtils.truncateValue(sum, 4));
    start.setPaint(Color.red);
    cp.addRangeMarker(start);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Set label IR/* www.j a  v  a2  s  .  c  om*/
 * 
 * @param jtable Table
 * @param stat Statistics
 * @param cp CategoryPlot
 * @return Generated TableModel
 * @throws Exception 
 */
private TableModel irLabelsetsTableModel(JTable jtable, Statistics stat, CategoryPlot cp) throws Exception {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    DefaultCategoryDataset myData = new DefaultCategoryDataset();

    tableModel.addColumn("Labelset id");
    tableModel.addColumn("IR values");

    //Labelsets frequency
    HashMap<LabelSet, Integer> labelsetsFrequency = stat.labelCombCount();
    labelsetStringByIR = new ArrayList<>(labelsetsFrequency.size());

    Set<LabelSet> keysets = labelsetsFrequency.keySet();

    Object[] row = new Object[2];

    int count = 1;
    double IR_labelset;
    int max = getMax(keysets, labelsetsFrequency);

    ArrayList<ImbalancedFeature> listImbalanced = new ArrayList();
    ImbalancedFeature temp;

    int value;

    for (LabelSet current : keysets) {
        value = labelsetsFrequency.get(current);
        IR_labelset = max / (value * 1.0);
        String temp1 = MetricUtils.truncateValue(IR_labelset, 4);
        IR_labelset = Double.parseDouble(temp1);

        temp = new ImbalancedFeature(current.toString(), value, IR_labelset);
        listImbalanced.add(temp);
    }

    labelsetsIRSorted = new ImbalancedFeature[listImbalanced.size()];
    labelsetsByIR = new double[listImbalanced.size()]; //stores IR per labelset

    String truncate;

    while (!listImbalanced.isEmpty()) {
        temp = Utils.getMin(listImbalanced);

        labelsetsIRSorted[count - 1] = temp;
        labelsetsByIR[count - 1] = temp.getIRIntraClass();

        row[0] = count;

        truncate = Double.toString(temp.getIRIntraClass());
        row[1] = MetricUtils.getValueFormatted(truncate, 3);

        tableModel.addRow(row);

        myData.setValue(temp.getIRIntraClass(), Integer.toString(count), "");
        labelsetStringByIR.add(temp.getName());

        count++;
        listImbalanced.remove(temp);
    }

    jtable.setModel(tableModel);
    jtable.setBounds(jtable.getBounds());

    //Resize columns
    TableColumnModel tcm = jtable.getColumnModel();

    tcm.getColumn(0).setPreferredWidth(50);
    tcm.getColumn(1).setPreferredWidth(50);

    //graph
    cp.setDataset(myData);

    //get mean
    double sum = 0;
    for (int i = 0; i < labelsetsIRSorted.length; i++) {
        sum += labelsetsIRSorted[i].getIRIntraClass();
    }
    sum = sum / labelsetsIRSorted.length;

    Marker start = new ValueMarker(sum);
    start.setPaint(Color.blue);
    start.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    start.setLabel("                        Mean: " + MetricUtils.truncateValue(sum, 4));
    cp.addRangeMarker(start);

    return jtable.getModel();
}

From source file:UserInterface.EmployeeViewArea.ViewResolvedIssuesStatisticsJPanel.java

/**
 * Returns a sample dataset./* ww w.  j a  v a2  s.com*/
 *
 * @return The dataset.
 */
private CategoryDataset createDataset() {

    // create the dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    HashMap<String, Integer> hashmapResolved = new HashMap<>();
    hashmapResolved.put("Child Labour", 0);
    hashmapResolved.put("Foster Care", 0);
    hashmapResolved.put("Adoption and Rehabilitation", 0);
    hashmapResolved.put("Donation of Basic Amenities", 0);

    HashMap<String, Integer> hashmapOpen = new HashMap<>();
    hashmapOpen.put("Child Labour", 0);
    hashmapOpen.put("Foster Care", 0);
    hashmapOpen.put("Adoption and Rehabilitation", 0);
    hashmapOpen.put("Donation of Basic Amenities", 0);

    for (Country c : system.getNetworkList()) {

        for (State s : c.getStateList()) {
            for (City city : s.getCityList()) {
                for (Enterprise e : city.getEnterpriseDirectory().getEnterpriseList()) {

                    if (userAccount.getRole().getName().equals("System Type")) {
                        lblHeader.setText("EcoSystem Level");
                        for (Organization organization : e.getOrganizationDirectory().getOrganizationList()) {
                            if (organization instanceof ManagerOrganization) {
                                for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) {
                                    if (!(request instanceof IssueWorkRequest)) {
                                    } else {
                                        String type = ((IssueWorkRequest) request).getType();
                                        if (type.equals("Child Labour")) {
                                            if (request.getStatus().equals("Resolved")) {
                                                hashmapResolved.put("Child Labour",
                                                        hashmapResolved.get("Child Labour") + 1);
                                            } else {
                                                hashmapOpen.put("Child Labour",
                                                        hashmapOpen.get("Child Labour") + 1);
                                            }
                                        } else if (type.equals("Foster Care")) {
                                            if (request.getStatus().equals("Resolved")) {
                                                hashmapResolved.put("Foster Care",
                                                        hashmapResolved.get("Foster Care") + 1);
                                            } else {
                                                hashmapOpen.put("Foster Care",
                                                        hashmapOpen.get("Foster Care") + 1);
                                            }
                                        } else if (type.equals("Adoption and Rehabilitation")) {
                                            if (request.getStatus().equals("Resolved")) {
                                                hashmapResolved.put("Adoption and Rehabilitation",
                                                        hashmapResolved.get("Adoption and Rehabilitation") + 1);
                                            } else {
                                                hashmapOpen.put("Adoption and Rehabilitation",
                                                        hashmapOpen.get("Adoption and Rehabilitation") + 1);
                                            }
                                        } else if (request.getStatus().equals("Resolved")) {
                                            hashmapResolved.put("Donation of Basic Amenities",
                                                    hashmapResolved.get("Donation of Basic Amenities") + 1);
                                        } else {
                                            hashmapOpen.put("Donation of Basic Amenities",
                                                    hashmapOpen.get("Donation of Basic Amenities") + 1);
                                        }

                                    }
                                }
                            }
                        }
                    } else {
                        for (UserAccount ua : e.getUserAccountDirectory().getUserAccountList()) {
                            if (userAccount.getUsername().equals(ua.getUsername())) {
                                lblHeader.setText("Enterprise Level");
                                for (Organization organization : e.getOrganizationDirectory()
                                        .getOrganizationList()) {
                                    if (organization instanceof ManagerOrganization) {
                                        for (WorkRequest request : organization.getWorkQueue()
                                                .getWorkRequestList()) {
                                            if (!(request instanceof IssueWorkRequest)) {
                                            } else {
                                                String type = ((IssueWorkRequest) request).getType();
                                                if (type.equals("Child Labour")) {
                                                    if (request.getStatus().equals("Resolved")) {
                                                        hashmapResolved.put("Child Labour",
                                                                hashmapResolved.get("Child Labour") + 1);
                                                    } else {
                                                        hashmapOpen.put("Child Labour",
                                                                hashmapOpen.get("Child Labour") + 1);
                                                    }
                                                } else if (type.equals("Foster Care")) {
                                                    if (request.getStatus().equals("Resolved")) {
                                                        hashmapResolved.put("Foster Care",
                                                                hashmapResolved.get("Foster Care") + 1);
                                                    } else {
                                                        hashmapOpen.put("Foster Care",
                                                                hashmapOpen.get("Foster Care") + 1);
                                                    }
                                                } else if (type.equals("Adoption and Rehabilitation")) {
                                                    if (request.getStatus().equals("Resolved")) {
                                                        hashmapResolved
                                                                .put("Adoption and Rehabilitation",
                                                                        hashmapResolved.get(
                                                                                "Adoption and Rehabilitation")
                                                                                + 1);
                                                    } else {
                                                        hashmapOpen.put("Adoption and Rehabilitation",
                                                                hashmapOpen.get("Adoption and Rehabilitation")
                                                                        + 1);
                                                    }
                                                } else if (request.getStatus().equals("Resolved")) {
                                                    hashmapResolved.put("Donation of Basic Amenities",
                                                            hashmapResolved.get("Donation of Basic Amenities")
                                                                    + 1);
                                                } else {
                                                    hashmapOpen.put("Donation of Basic Amenities",
                                                            hashmapOpen.get("Donation of Basic Amenities") + 1);
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                }

            }

        }
    }

    // row keys...
    final String series1 = "Open";
    final String series2 = "Resolved";

    // column keys...
    final String category1 = "Child Labour";
    final String category2 = "Foster Care";
    final String category3 = "Adoption and Rehabilitation";
    final String category4 = "Donation of Basic Amenities";

    dataset.setValue(hashmapOpen.get("Child Labour"), series1, category1);
    dataset.setValue(hashmapOpen.get("Foster Care"), series1, category2);
    dataset.setValue(hashmapOpen.get("Adoption and Rehabilitation"), series1, category3);
    dataset.setValue(hashmapOpen.get("Donation of Basic Amenities"), series1, category4);

    dataset.setValue(hashmapResolved.get("Child Labour"), series2, category1);
    dataset.setValue(hashmapResolved.get("Foster Care"), series2, category2);
    dataset.setValue(hashmapResolved.get("Adoption and Rehabilitation"), series2, category3);
    dataset.setValue(hashmapResolved.get("Donation of Basic Amenities"), series2, category4);

    return dataset;

}