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:org.miloss.fgsms.services.rs.impl.reports.ws.AverageResponseTimeByService.java

/**
 * {@inheritDoc}//from  ww  w . j a  va 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 average response time by service.<br />");
        //add description
        data.append(
                "<table class=\"table table-hover\"><tr><th>URL</th><th>Average Response Time (ms)</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)));
            long count = 0;
            data.append("<tr><td>").append(url).append("</td><td>");
            try {
                cmd = con.prepareStatement(
                        "select AVG(responsetimems) as messagesSize from RawData where URI=? and "
                                + "(UTCdatetime > ?) and (UTCdatetime < ?);");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();

                try {
                    if (rs.next())
                        count = rs.getLong(1);
                } catch (Exception ex) {
                    log.log(Level.DEBUG, " error querying database for average message size url:" + urls.get(i),
                            ex);
                }

            } catch (Exception ex) {
                data.append("0 ms</td></tr>");
                log.log(Level.ERROR,
                        "Error opening or querying the database." + this.getClass().getSimpleName(), ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            data.append(count + "").append(" ms</td></tr>");
            set.addValue(count, url, url);
        }
        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(urls.size()));
        } 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.mili.jmibs.jfree.JFreeChartBarIterationIntervalBenchmarkSuiteResultRenderer.java

private CategoryDataset createDataset(List<BenchmarkResult> lbr) {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (int i = 0, n = lbr.size(); i < n; i++) {
        BenchmarkResult br = lbr.get(i);
        IterationIntervalBenchmarkContext<?> iolbc = (IterationIntervalBenchmarkContext<?>) br
                .getBenchmarkContext();// w w w.j a va  2  s .  c  om
        Benchmark b = iolbc.getBenchmark();
        int ic = iolbc.getIteration();
        Interval<?> iv = iolbc.getInterval();
        ds.addValue(br.getTotalTimeNanos(), String.valueOf(ic) + "/" + String.valueOf(iv), b.getName());
    }
    return ds;
}

From source file:org.sonar.plugins.abacus.chart.BarChart3D.java

private CategoryPlot generateJFreeChart(ChartParameters params) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();

    Font font = getFont(params.getValue(PARAM_FONT_SIZE));
    configureDomainAxis(plot, font);//from   w  w  w . ja va 2s. co  m
    configureRangeAxis(plot, params.getValue(PARAM_Y_SUFFIX, "", true), font);
    configureRenderer(plot);
    configureValues(dataset, params.getValues(PARAM_VALUES, "|", true),
            params.getValue(PARAM_X_SUFFIX, "", true));
    configureColors(dataset, plot, params.getValues(PARAM_COLORS, ","));

    plot.setDataset(dataset);
    return plot;
}

From source file:edu.cuny.cat.ui.CumulativeTraderDistributionPanel.java

@Override
protected synchronized void processRoundOpened(final RoundOpenedEvent event) {
    final DefaultCategoryDataset subDataset = new DefaultCategoryDataset();
    final String specialistIds[] = registry.getSpecialistIds();
    for (int i = 0; i < specialistIds.length; i++) {
        int registeredToday = 0;
        try {/*from   w  w  w  .ja  v a  2  s. c o  m*/
            registeredToday = (dataset.getValue(getDayText(event.getDay()), specialistIds[i])).intValue();
        } catch (final Exception e) {
            // do nothing
        }
        subDataset.setValue(registeredToday, getDayText(event.getDay()), specialistIds[i]);
        subDataset.setValue((double) (totalRegistered[i] + registeredToday) / (event.getDay() + 1),
                CumulativeTraderDistributionPanel.AVERAGE, specialistIds[i]);
    }
    catPlot.setDataset(subDataset);

}

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

/**
 * {@inheritDoc}/* w w w .j  a  v  a2  s  . c o m*/
 */
@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 average response time by Service by Method<br />");
        //add description
        data.append(
                "<table class=\"table table-hover\"><tr><th>URL</th><th>Action</th><th>Average Response Time (ms)</th></tr>");
        int actioncount = 0;
        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)));
            List<String> actions = getSoapActions(urls.get(i), con);

            actioncount += actions.size();
            for (int k = 0; k < actions.size(); k++) {
                long count = 0;
                try {
                    cmd = con.prepareStatement("select AVG(responsetimems)  from RawData where URI=? and "
                            + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=?;");
                    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();

                    rs.next();
                    count = rs.getLong(1);
                } catch (Exception ex) {
                    log.log(Level.DEBUG, " error querying database for average message size url:" + urls.get(i),
                            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(count + "")
                        .append(" ms</td></tr>");
                set.addValue(count, actions.get(k), url);
            }

        }
        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(actioncount));
        } 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:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java

private static JFreeChart buildChartForDiveDepths(StatQueryObject sqo) {
    Collection<StatSerie> s = sqo.getValues();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (StatSerie statSerie : s) {
        List<StatPoint> points = statSerie.getPoints();
        Collections.sort(points, new Comparator<StatPoint>() {
            @Override/*from   w  w w  . j  a  va  2  s  . c  o  m*/
            public int compare(StatPoint o1, StatPoint o2) {
                return -((Double) (o1).getX()).compareTo((Double) (o2).getX());
            }
        });

        // int i = 0;
        // int indexMax = points.size()-1;
        // for (StatPoint point : points) {
        // String label =null;
        // if(i == indexMax){
        // label = "< "+((Double) point.getX());
        // }else{
        // label = (Double) point.getX() + " - "+(Double)
        // points.get(i+1).getX();
        // }
        // dataset.addValue(point.getY(),
        // label, "");
        // i++;
        // }

        for (StatPoint point : points) {
            dataset.addValue(point.getY(),
                    String.valueOf(UnitsAgent.getInstance().convertLengthFromModel((Double) point.getX())), "");
        }
    }

    String xLabel = i18n.getString("depth") + " (" + UnitsAgent.getInstance().getLengthUnit().getSymbol() + ")";
    String yLabel = i18n.getString("dives.numberof");
    JFreeChart chart = createBarChart(dataset, xLabel, yLabel);
    return chart;
}

From source file:sas.BarChart.java

public static CategoryDataset createProfitDataset(HashMap<String, Float> lsh) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String sh : lsh.keySet()) {
        defaultcategorydataset.addValue(lsh.get(sh), "Profit", sh);
    }//from www  . j a  v  a2  s  .  c o  m

    return defaultcategorydataset;
}

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

/**
 * {@inheritDoc}/*from w  w  w .  j a  va2s  .c o m*/
 */
@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;
        PreparedStatement userQuery = null;
        ResultSet rs = null;
        DefaultCategoryDataset set = new DefaultCategoryDataset();
        JFreeChart chart = null;
        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append("This represents service usage by consumer for the provided services.<br />");
        //add description
        data.append("<table class=\"table table-hover\"><tr><th>User</th><th>Invocations</th></tr>");

        ResultSet actionRS = null;
        Set<String> users = new HashSet<String>();
        try {

            userQuery = con.prepareStatement("select consumeridentity from rawdata group by consumeridentity");
            actionRS = userQuery.executeQuery();
            users.add("unspecified");
            while (actionRS.next()) {
                try {
                    String s = actionRS.getString(1);
                    s = s.trim();
                    if (!Utility.stringIsNullOrEmpty(s)) {
                        String[] items = s.split(";");
                        for (int x = 0; x < items.length; x++) {
                            if (!Utility.stringIsNullOrEmpty(items[x])) {
                                users.add(items[x].trim());
                            }
                        }
                    }

                } catch (Exception ex) {
                    log.log(Level.WARN, " error querying database", ex);
                }
            }
        } catch (Exception ex) {
            log.log(Level.WARN, " error querying database", ex);
        } finally {
            DBUtils.safeClose(actionRS);
            DBUtils.safeClose(userQuery);
        }

        try {
            Iterator<String> iterator = users.iterator();
            while (iterator.hasNext()) {
                String u = iterator.next();
                try {
                    if (u.equalsIgnoreCase("unspecified")) {
                        cmd = con.prepareStatement(
                                "select count(*)  from RawData where consumeridentity is null and "
                                        + "(UTCdatetime > ?) and (UTCdatetime < ?)");

                        cmd.setLong(1, range.getStart().getTimeInMillis());
                        cmd.setLong(2, range.getEnd().getTimeInMillis());
                    } else {
                        cmd = con.prepareStatement("select count(*)  from RawData where consumeridentity=? and "
                                + "(UTCdatetime > ?) and (UTCdatetime < ?)");
                        cmd.setString(1, u);
                        cmd.setLong(2, range.getStart().getTimeInMillis());
                        cmd.setLong(3, range.getEnd().getTimeInMillis());
                    }
                    rs = cmd.executeQuery();
                    long count = 0;
                    try {
                        if (rs.next()) {
                            count = rs.getLong(1);
                        }
                    } catch (Exception ex) {
                        log.log(Level.DEBUG, " error querying database", ex);
                    }

                    data.append("<tr><td>").append(Utility.encodeHTML(u)).append("</td><td>");
                    data.append(count + "").append("</td></tr>");
                    if (count > 0) {
                        set.addValue(count, u, u);
                    }
                } catch (Exception ex) {
                    log.log(Level.WARN, " error querying database", ex);
                } finally {
                    DBUtils.safeClose(rs);
                    DBUtils.safeClose(cmd);
                }
            }
        } catch (Exception ex) {
            data.append("0</td></tr>");
            log.log(Level.ERROR, "Error opening or querying the database.", ex);
        } finally {
            DBUtils.safeClose(cmd);

        }

        chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Consumers", "", 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.miloss.fgsms.services.rs.impl.reports.ws.SuccessFailureCountByHostingServer.java

/**
 * {@inheritDoc}//from w  ww .  jav a  2s .co m
 */
@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {
    if (!UserIdentityUtil.hasGlobalAdministratorRole(currentuser, "SUCCESS_FAILURE_COUNT_BY_HOSTING_SERVER",
            classification, ctx)) {
        data.append("<h2>Access for " + GetDisplayName() + " was denied for non-global admin users</h2>");
    }

    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 Web Application Server utilization (host) by success and failure rates.<br />");
        data.append(
                "<table class=\"table table-hover\"><tr><th>Host</th><th>Successes</th><th>Failures</th></tr>");
        List<String> dcs = new ArrayList<String>();
        try {

            cmd = con.prepareStatement("select hostingsource from RawData group by hostingsource;");
            rs = cmd.executeQuery();
            while (rs.next()) {
                dcs.add(rs.getString(1));
            }
        } catch (Exception ex) {
            log.log(Level.WARN, null, ex);
        } finally {
            DBUtils.safeClose(rs);
            DBUtils.safeClose(cmd);
        }
        try {
            //          itemcount = dcs.size();
            for (int i = 0; i < dcs.size(); i++) {
                data.append("<tr><td>").append(Utility.encodeHTML(dcs.get(i))).append("</td>");
                int success = 0;
                int failures = 0;
                try {
                    cmd = con.prepareStatement(
                            "select count(*) from RawData where hostingsource=? and success=false and UTCdatetime > ? and UTCdatetime < ?;");
                    cmd.setString(1, dcs.get(i));
                    cmd.setLong(2, range.getStart().getTimeInMillis());
                    cmd.setLong(3, range.getEnd().getTimeInMillis());
                    rs = cmd.executeQuery();
                    try {
                        if (rs.next()) {
                            failures = rs.getInt(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 hostingsource=? and success=true and UTCdatetime > ? and UTCdatetime < ?;");
                    cmd.setString(1, dcs.get(i));
                    cmd.setLong(2, range.getStart().getTimeInMillis());
                    cmd.setLong(3, range.getEnd().getTimeInMillis());
                    rs = cmd.executeQuery();
                    try {
                        if (rs.next()) {
                            success = rs.getInt(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("<td>").append(success + "").append("</td>");
                data.append("<td>").append(failures + "").append("</td></tr>");
                if (success > 0) {
                    set.addValue(success, dcs.get(i) + " Success", dcs.get(i) + " Success");
                }
                if (failures > 0) {
                    set.addValue(failures, dcs.get(i) + " Failures", dcs.get(i) + " Failures");
                }

            }

        } catch (Exception ex) {
            log.log(Level.ERROR, "Error generating chart information.", ex);
        }
        chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Hosting Servers", "", 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:wef.articulab.view.ui.BNCategoryPlot.java

/**
 * Creates a dataset.
 *
 * @return A dataset.
 */
public static CategoryDataset createDataset() {
    return new DefaultCategoryDataset();
}