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

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

Introduction

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

Prototype

public DefaultCategoryDataset() 

Source Link

Document

Creates a new (empty) dataset.

Usage

From source file:ANNFileDetect.GraphingClass.java

public void drawchartFromInt(Integer[] values) throws IOException {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (int i = 0; i < values.length; i++) {
        //double a = (double) i;
        ds.addValue(i, String.valueOf(i), String.valueOf(values[i]));
        //ds.addValue((double)i, "Times", values[i]);
    }//from  w w w . j a va2  s. co  m
    JFreeChart chart = ChartFactory.createBarChart("chart", "quantity", "value", ds, PlotOrientation.VERTICAL,
            true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(1200, 700);
    JPanel jf = new JPanel();
    jf.setSize(1300, 800);
    chartPanel.setVisible(true);
    chartPanel.setZoomAroundAnchor(true);
    chartPanel.setDomainZoomable(true);
    jf.add(chartPanel);
    JLabel jl = new JLabel("hello!");
    jf.add(jl);
    jf.setVisible(true);
    jf.repaint();
    //jf.setAlwaysOnTop(true);
}

From source file:org.miloss.fgsms.services.rs.impl.reports.ws.SuccessFailureCountByServiceByMethod.java

/**
 * {@inheritDoc}/*from   w ww  .  j  av  a 2 s .c  om*/
 */
@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {
        PreparedStatement cmd = null;
        ResultSet rs = null;
        DefaultCategoryDataset set = new DefaultCategoryDataset();
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append("This represents the success and failure counts by Service by Method<br />");
        //add description
        data.append(
                "<table class=\"table table-hover\"><tr><th>URL</th><th>Method</th><th>Success</th><th>Failure</th></tr>");

        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            try {
                List<String> actions = getSoapActions(urls.get(i), con);

                for (int k = 0; k < actions.size(); k++) {

                    long success = 0;
                    long failures = 0;
                    try {
                        cmd = con.prepareStatement("select count(*)  from RawData where URI=? and "
                                + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=? and success=true;");
                        cmd.setString(1, urls.get(i));
                        cmd.setLong(2, range.getStart().getTimeInMillis());
                        cmd.setLong(3, range.getEnd().getTimeInMillis());
                        cmd.setString(4, actions.get(k));
                        rs = cmd.executeQuery();
                        try {
                            if (rs.next()) {
                                success = rs.getLong(1);
                            }
                        } catch (Exception ex) {
                            log.log(Level.DEBUG, null, ex);
                        }
                    } catch (Exception ex) {
                        log.log(Level.WARN, null, ex);
                    } finally {
                        DBUtils.safeClose(rs);
                        DBUtils.safeClose(cmd);
                    }
                    try {
                        cmd = con.prepareStatement("select count(*)  from RawData where URI=? and "
                                + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=? and success=false;");
                        cmd.setString(1, urls.get(i));
                        cmd.setLong(2, range.getStart().getTimeInMillis());
                        cmd.setLong(3, range.getEnd().getTimeInMillis());
                        cmd.setString(4, actions.get(k));

                        rs = cmd.executeQuery();

                        try {
                            if (rs.next()) {
                                failures = rs.getLong(1);
                            }
                        } catch (Exception ex) {
                            log.log(Level.DEBUG, null, ex);
                        }
                    } catch (Exception ex) {
                        log.log(Level.WARN, null, ex);
                    } finally {
                        DBUtils.safeClose(rs);
                        DBUtils.safeClose(cmd);
                    }
                    data.append("<tr><td>").append(url).append("</td><td>");
                    data.append(Utility.encodeHTML(actions.get(k))).append("</td><td>").append(success + "")
                            .append("</td><td>").append(failures + "").append("</td></tr>");

                    if (success > 0) {
                        set.addValue(success, url + " Success", url + " Success");
                    }
                    if (failures > 0) {
                        set.addValue(failures, url + " Failures", url + " Failures");
                    }
                }
            } catch (Exception ex) {
                data.append("0 bytes</td></tr>");
                log.log(Level.ERROR, "Error opening or querying the database.", ex);
            }
        }

        chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set,
                PlotOrientation.HORIZONTAL, true, false, false);
        data.append("</table>");
        try {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, pixelHeightCalc(set.getRowCount()));
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
        data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
        files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:org.agmip.ui.afsirs.frames.GraphOutput.java

private CategoryDataset createDataset(int type) {

    ArrayList<SoilSpecificPeriodData> PDATA = utils.getGraphData(type);
    //double[] PDATA = utils.getGraphData(type);

    double avg = 0.0;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    double[] arr = utils.getFractions();
    double[] soilArea = utils.getSoilArea();
    double areaSum = 0.0;

    for (double a : soilArea)
        areaSum += a;/*  ww  w  . ja v a2 s  . c o  m*/

    for (int i = 0; i < PDATA.get(0).getSoilDataPoints().length; i++) {
        for (int j = 0; j < PDATA.size(); j++) {
            dataset.addValue(PDATA.get(j).getSoilDataPoints()[i], PDATA.get(j).getSoilName(), "" + (i + 1));
            Double res = PDATA.get(j).getSoilDataPoints()[i];

            //System.out.println ("Size of the DataSet array : "  + soilArea.length + " Current Index : " + j);
            res = res * soilArea[j];
            avg += res;
        }
        avg /= areaSum;
        dataset.addValue(avg, "Weighted Avg", "" + (i + 1));
        avg = 0.0;
    }

    return dataset;
}

From source file:com.deafgoat.ml.prognosticator.Charter.java

/**
 * Creates data set containing categorical attributes along with prediction
 * confidence//from  www.  ja v a 2 s.c  o m
 * 
 * @param files
 *            List of files containing predictions to chart
 * @return the series collection to chart
 */
private DefaultCategoryDataset createCategoricalDataset(String[] files) {
    _logger.info("Collating data");
    BufferedReader br = null;
    // final XYSeriesCollection dataset = new XYSeriesCollection();
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    XYSeries prediction = null;
    for (String dataFile : files) {
        try {
            String sCurrentLine;
            prediction = new XYSeries(dataFile);
            br = new BufferedReader(new FileReader(dataFile));
            HashMap<String, Double> avgConfidence = new HashMap<String, Double>();
            HashMap<String, Integer> valueCount = new HashMap<String, Integer>();
            while ((sCurrentLine = br.readLine()) != null) {
                String[] data = sCurrentLine.split("\t");
                try {
                    if (avgConfidence.containsKey(data[0])) {
                        avgConfidence.put(data[0], avgConfidence.get(data[0]) + Double.parseDouble(data[1]));
                        valueCount.put(data[0], valueCount.get(data[0]) + 1);
                    } else {
                        avgConfidence.put(data[0], Double.parseDouble(data[1]));
                        valueCount.put(data[0], 1);
                    }
                } catch (NumberFormatException e) {
                    continue;
                }
            }
            for (Entry<String, Double> entry : avgConfidence.entrySet()) {
                dataset.addValue(entry.getValue() / valueCount.get(entry.getKey()), entry.getKey(), dataFile);
            }
        } catch (IOException e) {
            _logger.error(e.toString());
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                _logger.error(e.toString());
            }
        }
        if (prediction != null) {
            // dataset.addSeries(prediction);
        }
    }
    return dataset;
}

From source file:UI.Graphic.java

private void init2() {
    panel = new JPanel();
    getContentPane().add(panel);/*from   w  w  w.j a  v  a2 s  .c  o  m*/
    // Fuente de Datos
    DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
    for (int i = 0; i < experiment2.getMedia().size(); i++) {
        line_chart_dataset.addValue(experiment2.getMedia().get(i), "aptitud", String.valueOf(i));
    }

    // Creando el Grafico
    JFreeChart chart = ChartFactory.createLineChart("Apitud de las generaciones", "Generacion", "Aptitud",
            line_chart_dataset, PlotOrientation.VERTICAL, true, true, false);

    // Mostrar Grafico
    ChartPanel chartPanel = new ChartPanel(chart);
    panel.add(chartPanel);
}

From source file:com.googlecode.logVisualizer.chart.MeatPerLevelBarChart.java

@Override
protected CategoryDataset createDataset() {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (final DataNumberPair<MeatGain> dnp : getLogData().getLogSummary().getMeatSummary()
            .getAllLevelsData()) {/*from www . j  a v a  2 s. c o m*/
        final String levelStr = "Level " + dnp.getNumber();

        dataset.addValue(dnp.getData().encounterMeatGain, "Meat gained inside encounters", levelStr);
        dataset.addValue(dnp.getData().otherMeatGain, "Meat gained outside encounters", levelStr);
        dataset.addValue(dnp.getData().meatSpent, "Meat spent", levelStr);
    }

    return dataset;
}

From source file:com.googlecode.logVisualizer.chart.MPGainsPerLevelBarChart.java

@Override
protected CategoryDataset createDataset() {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (final DataNumberPair<MPGain> dnp : getLogData().getLogSummary().getMPGainSummary()
            .getAllLevelsData()) {/* ww  w .jav  a 2 s  .com*/
        final String levelStr = "Level " + dnp.getNumber();

        dataset.addValue(dnp.getData().encounterMPGain, "Inside encounters", levelStr);
        dataset.addValue(dnp.getData().starfishMPGain, "Starfish familiars", levelStr);
        dataset.addValue(dnp.getData().restingMPGain, "Resting", levelStr);
        dataset.addValue(dnp.getData().outOfEncounterMPGain, "Outside encounters", levelStr);
        dataset.addValue(dnp.getData().consumableMPGain, "Consumables", levelStr);
    }

    return dataset;
}

From source file:org.wsm.database.tools.editor.ui.GraphPane.java

public GraphPane() {
    GridBagLayout gbl = new GridBagLayout();
    this.setLayout(gbl);

    this.qesi = new QueryExecStatsInfo();
    this.qesi.addPropertyChangeListener(this);
    dcd = new DefaultCategoryDataset();
    JFreeChart chart = getChart(CHART_TYPE_BAR_3D);

    chart.setBackgroundPaint(Color.white);

    cp = new ChartPanel(chart);
    cp.setBorder(BorderFactory.createTitledBorder(null, "Graph", TitledBorder.LEADING, TitledBorder.TOP,
            UIConstants.LABEL_FONT));/*from   ww  w . jav  a2s . c  o m*/

    cp.setMouseZoomable(true, true);
    //cp.setPreferredSize(new Dimension(700, 500));
    gbl.setConstraints(cp, SwingUtils.getGridBagConstraints(0, 0, 2, 1));

    this.add(cp);
    JPanel graphTypeSelectionPanel = new JPanel();
    viewBarGraph = new JRadioButton("View Bar Graph", true);
    viewLineGraph = new JRadioButton("View Line Graph", false);
    viewLineGraph.setEnabled(false);
    ButtonGroup bg = new ButtonGroup();
    bg.add(viewBarGraph);
    bg.add(viewLineGraph);

    GridBagLayout graphTypeGBL = new GridBagLayout();
    graphTypeSelectionPanel.setLayout(graphTypeGBL);

    graphTypeGBL.setConstraints(viewBarGraph, SwingUtils.getGridBagConstraints(0, 0));
    graphTypeGBL.setConstraints(viewLineGraph, SwingUtils.getGridBagConstraints(1, 0));
    graphTypeSelectionPanel.add(viewBarGraph);
    graphTypeSelectionPanel.add(viewLineGraph);
    viewBarGraph.addActionListener(this);
    viewLineGraph.addActionListener(this);

    graphTypeSelectionPanel.setBorder(BorderFactory.createTitledBorder(null, "Graph Type", TitledBorder.LEADING,
            TitledBorder.TOP, UIConstants.LABEL_FONT));

    gbl.setConstraints(graphTypeSelectionPanel, SwingUtils.getGridBagConstraints(0, 1, 2, 1));

    this.add(graphTypeSelectionPanel);
    //this.setBounds(50, 100, 100, 200);
    this.setBackground(Color.WHITE);
}

From source file:graphs.ResultsGraphs.java

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

    // row keys...
    final String series1 = "NaiveBayes";
    final String series2 = "MultiNomial NaiveBayes";
    //final String series3 = "Upper Lower";

    // column keys...
    final String category1 = "True Positive Rate";
    final String category2 = "False Positive Rate";
    final String category3 = "Precision";
    final String category4 = "Recall";
    // final String category5 = "True Positive Rate5";

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

    dataset.addValue(0.804, series1, category1);
    dataset.addValue(0.13, series1, category2);
    dataset.addValue(0.866, series1, category3);
    dataset.addValue(0.86, series1, category4);
    //dataset.addValue(5.0, series1, category5);

    dataset.addValue(0.914, series2, category1);
    dataset.addValue(0.086, series2, category2);
    dataset.addValue(0.914, series2, category3);
    dataset.addValue(0.92, series2, category4);
    //dataset.addValue(4.0, series2, category5);

    /* dataset.addValue(4.0, series3, category1);
     dataset.addValue(3.0, series3, category2);
     dataset.addValue(2.0, series3, category3);
     dataset.addValue(3.0, series3, category4);
     dataset.addValue(6.0, series3, category5);*/

    return dataset;

}

From source file:com.mergano.core.GraphChart.java

private CategoryDataset createDataset() {

    // row keys...
    final String series1 = "First";
    final String series2 = "Second";

    // column keys...
    final String category1 = "Jan";
    final String category2 = "Feb";
    final String category3 = "Mar";
    final String category4 = "Apr";
    final String category5 = "May";
    final String category6 = "June";
    final String category7 = "July";
    final String category8 = "Aug";
    final String category9 = "Sep";
    final String category10 = "Oct";
    final String category11 = "Nov";
    final String category12 = "Dec";

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

    dataset.addValue(1.0, series1, category1);
    dataset.addValue(4.0, series1, category2);
    dataset.addValue(3.0, series1, category3);
    dataset.addValue(5.0, series1, category4);
    dataset.addValue(5.0, series1, category5);
    dataset.addValue(3.0, series1, category6);
    dataset.addValue(4.0, series1, category7);
    dataset.addValue(5.0, series1, category8);
    dataset.addValue(3.0, series1, category9);
    dataset.addValue(6.0, series1, category10);
    dataset.addValue(1.0, series1, category11);
    dataset.addValue(2.0, series1, category12);

    dataset.addValue(5.0, series2, category1);
    dataset.addValue(7.0, series2, category2);
    dataset.addValue(6.0, series2, category3);
    dataset.addValue(8.0, series2, category4);
    dataset.addValue(4.0, series2, category5);
    dataset.addValue(7.0, series2, category6);
    dataset.addValue(2.0, series2, category7);
    dataset.addValue(8.0, series2, category8);
    dataset.addValue(9.0, series2, category9);
    dataset.addValue(3.0, series2, category10);
    dataset.addValue(2.0, series2, category11);
    dataset.addValue(1.0, series2, category12);
    return dataset;
}