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:Controlador.ChartServlet.java

public JFreeChart getChart() throws URISyntaxException {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Equipos eq = new Equipos();
    Equipo e = eq.buscar(1);//w  w  w. j a v a  2s .  c o  m
    dataset.addValue(e.getNumSerie(), String.copyValueOf(e.getNombre()), " 1");

    JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo", // chart title
            "equipo", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    BarRenderer r = (BarRenderer) renderer;
    r.setMaximumBarWidth(0.05);
    return chart;

}

From source file:result.analysis.Chart.java

void perSemPerformace(String batch, String sem, String[] colleges) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String college : colleges) {
        db = mongoClient.getDB(college);
        String collection_name = "cs_" + batch + "_" + sem + "_sem";
        DBCollection collection = db.getCollection(collection_name);

        analyz = new Analyze(db);
        double number = analyz.GetNumber(collection, "FAIL");
        dataset.setValue(number, college, "FAIL");
        number = analyz.GetNumber(collection, "FIRST CLASS");
        dataset.setValue(number, college, "First Class");

        number = analyz.GetNumber(collection, "SECOND CLASS");
        dataset.setValue(number, college, "Second class");

        number = analyz.GetNumber(collection, "FIRST CLASS WITH DISTINCTION");
        dataset.setValue(number, college, "First Class With Distinction");

    }//from   ww  w . j a  v  a 2  s.c  o m
    JFreeChart pieChart = ChartFactory.createMultiplePieChart("Classwise Distribution", dataset,
            TableOrder.BY_ROW, true, true, true);
    //        MultiplePiePlot plot = (MultiplePiePlot) pieChart.getPlot();
    //        plot.setStartAngle(290);
    //        plot.setDirection(Rotation.CLOCKWISE);
    //        plot.setForegroundAlpha(0.5f);
    MultiplePiePlot plot = (MultiplePiePlot) pieChart.getPlot();
    JFreeChart subchart = plot.getPieChart();
    PiePlot p = (PiePlot) subchart.getPlot();
    // p.setSimpleLabels(true);
    p.setExplodePercent("First Class With Distinction", 0.10);

    p.setExplodePercent("First Class", 0.10);
    p.setExplodePercent("Second class", 0.10);
    p.setExplodePercent("FAIL", 0.10);
    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    p.setLabelGenerator(gen);

    ChartFrame frame = new ChartFrame("Semester Wise Performance of " + batch + " year", pieChart);
    frame.setVisible(true);
    frame.setSize(500, 500);
    save_jpeg(pieChart);

}

From source file:jasmine.imaging.shapes.RadiusChart.java

public RadiusChart(double[] values) {

    super();//  w  ww. j a  v a 2 s.com

    DefaultCategoryDataset series = new DefaultCategoryDataset();

    for (int i = 0; i < values.length; i++) {
        series.addValue(values[i], "row1", String.valueOf(i));
    }

    setTitle("Radius Change");

    chart = new JLabel();
    getContentPane().add(chart);

    setSize(320, 240);
    setVisible(true);

    myChart = ChartFactory.createLineChart(null, null, null, series, PlotOrientation.VERTICAL, false, false,
            false);

    addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            if (myChart != null)
                updateChart();
        }
    });

}

From source file:org.amanzi.splash.chart.Charts.java

public static DefaultCategoryDataset createBarChartDataset(ChartNode chartNode) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int countBad = 0;
    List<ChartItemNode> allChartItems = chartNode.getAllChartItems();
    Collections.sort(allChartItems);
    for (ChartItemNode node : allChartItems) {
        double nodeValue = 0.0;
        try {//from w  w w . j  a  v  a  2s  .  co  m
            String value = (String) node.getValueNode().getValue();
            if (value.length() > 0) {
                nodeValue = Double.parseDouble((String) node.getValueNode().getValue());
            }
        } catch (NumberFormatException e) {
            countBad++;
        }
        dataset.addValue(nodeValue, node.getChartItemSeries(), (String) node.getCategoryNode().getValue());
    }
    if (countBad > 0) {
        displayDataParsingError(countBad);
    }
    return dataset;
}

From source file:agentlogfileanalyzer.gui.ComparisonFrame.java

/**
 * Creates a chart frame for comparing a selected classifier to a set of
 * other classifiers.// w w  w  .  j  a  v a2  s.co  m
 * 
 * @param firstTitle
 *            the first line of the chart title
 * @param secondTitle
 *            the second line of the chart title
 * @param compDataForColumns
 *            the data the will be displayed in the chart
 */
public ComparisonFrame(String firstTitle, String secondTitle, Vector<ComparisonDataSet> compDataForColumns) {

    super("Classifier comparison");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < compDataForColumns.size(); i++) {
        ComparisonDataSet mms = compDataForColumns.get(i);
        dataset.addValue(mms.getMax(), "max", mms.getColumnName());
        dataset.addValue(mms.getMin(), "min", mms.getColumnName());
        dataset.addValue(mms.getSelected(), "selected", mms.getColumnName());
    }

    JFreeChart jfreechart = ChartFactory.createBarChart("", // title
            "", // x-axis title
            "", // y-axis title
            dataset, PlotOrientation.VERTICAL, true, true, false);
    TextTitle subtitle1 = new TextTitle(firstTitle, new Font("SansSerif", Font.BOLD, 12));
    TextTitle subtitle2 = new TextTitle(secondTitle, new Font("SansSerif", Font.BOLD, 12));
    jfreechart.addSubtitle(0, subtitle1);
    jfreechart.addSubtitle(1, subtitle2);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    MinMaxCategoryRenderer minmaxcategoryrenderer = new MinMaxCategoryRenderer();
    categoryplot.setRenderer(minmaxcategoryrenderer);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartpanel);
}

From source file:com.church.tools.ChartTools.java

/**
 * Generate line chart.//from  w w  w. j a  v a  2 s  . c  o m
 * 
 * @param title the title
 * @param values the values
 * @param captions the captions
 * @param width the width
 * @param height the height
 * @param color the color
 * 
 * @return the buffered image
 */
public static BufferedImage GenerateLineChart(String title, double[] values, String[] captions, int width,
        int height, Color color) {
    BufferedImage bufferedImage = null;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < values.length; i++) {
        dataset.addValue(values[i], "Balance Timeline", String.valueOf(i + 1));
    }
    JFreeChart chart = ChartFactory.createLineChart(title, "Balance Timeline", "Amount", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(color);
    bufferedImage = chart.createBufferedImage(width, height);
    return bufferedImage;
}

From source file:graph.GraphCreater.java

private DefaultCategoryDataset createDataset(ArrayList<String> resultList, ArrayList<String> dateList) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int item = 0; item < resultList.size(); item++) {
        dataset.addValue(Integer.valueOf(resultList.get(item)), "Sugar level", dateList.get(item) + "  ");
    }// www  . j a v a  2  s. c  o m

    return dataset;
}

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

/**
 * {@inheritDoc}/*from  www.  ja  v a 2  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 invocations for each service by method (action).<br />");
        data.append(
                "<table class=\"table table-hover\"><tr><th>URL</th><th>Action</th><th>Invocations</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 count = 0;

                    try {
                        cmd = con.prepareStatement("select count(*) 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();
                        try {
                            if (rs.next()) {
                                count = 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(count + "")
                            .append("</td></tr>");
                    if (count > 0) {
                        set.addValue(count, actions.get(k), url);
                    }
                }
            } catch (Exception ex) {

                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:loansystem.visual.panel.StartPage.java

private void graficoPrestamoXMes() {
    ArrayList<GraficoEntidad> graficos;
    graficos = gDao.obtenerPrestamosPorMes();

    if (graficos.size() > 0) {
        DefaultCategoryDataset datos = new DefaultCategoryDataset();

        for (GraficoEntidad result : graficos) {
            datos.addValue(result.getValor(), result.getSerie(), result.getValorEje());
        }/*from  w w w .  ja va  2s. c  o m*/

        JFreeChart grafica = ChartFactory.createBarChart("Registros Por Mes", "Mes", "Prstamos", datos,
                PlotOrientation.VERTICAL, true, true, false);
        ChartPanel panel = new ChartPanel(grafica);
        pnelPrestamosMes.add(panel);
        pnelPrestamosMes.revalidate();
        pnelPrestamosMes.repaint();

    }

}

From source file:graphs.LimitsGraphs.java

/**
 * Returns a sample dataset.//from   www .  ja v  a  2 s . co  m
 * 
 * @return The dataset.
 */
private CategoryDataset createDataset() {

    // row keys...
    final String series1 = "Limit Lower";
    final String series2 = "Middle Lower";
    final String series3 = "Upper Lower";

    // column keys...
    final String category1 = "Metric 1";
    final String category2 = "Metric 2";
    final String category3 = "Metric 3";
    final String category4 = "Metric 4";
    final String category5 = "Metric 5";

    // 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(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(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;

}