Example usage for org.jfree.util TableOrder BY_ROW

List of usage examples for org.jfree.util TableOrder BY_ROW

Introduction

In this page you can find the example usage for org.jfree.util TableOrder BY_ROW.

Prototype

TableOrder BY_ROW

To view the source code for org.jfree.util TableOrder BY_ROW.

Click Source Link

Document

By row.

Usage

From source file:org.operamasks.faces.render.graph.PieChartRenderer.java

protected JFreeChart createChart(UIChart comp) {
    Dataset dataset = createDataset(comp);
    JFreeChart chart = null;/*from www . j  av a2  s.  com*/
    PiePlot pieplot = null;

    boolean ring = Coercion.coerceToBoolean(comp.getAttributes().get("ring"));

    if (dataset instanceof CategoryDataset) {
        CategoryDataset catset = (CategoryDataset) dataset;

        if (catset.getRowCount() == 1) {
            PieDataset pieset = new CategoryToPieDataset(catset, TableOrder.BY_ROW, 0);

            if (ring) {
                chart = ChartFactory.createRingChart(null, pieset, false, false, false);
            } else if (comp.isEffect3D()) {
                chart = ChartFactory.createPieChart3D(null, pieset, false, false, false);
            } else {
                chart = ChartFactory.createPieChart(null, pieset, false, false, false);
            }

            pieplot = (PiePlot) chart.getPlot();
        } else {
            if (comp.isEffect3D()) {
                chart = ChartFactory.createMultiplePieChart3D(null, catset, TableOrder.BY_ROW, false, false,
                        false);
            } else {
                chart = ChartFactory.createMultiplePieChart(null, catset, TableOrder.BY_ROW, false, false,
                        false);
            }

            pieplot = (PiePlot) ((MultiplePiePlot) chart.getPlot()).getPieChart().getPlot();
        }
    }

    if (pieplot != null) {
        if (!comp.isDrawItemLabel()) {
            pieplot.setLabelGenerator(null);
        }

        if (comp.isShowItemTips()) {
            pieplot.setToolTipGenerator(new StandardPieToolTipGenerator());
        }

        Object startAngle = comp.getAttributes().get("startAngle");
        if (startAngle != null) {
            pieplot.setStartAngle(Coercion.coerceToDouble(startAngle));
        }
    }

    return chart;
}

From source file:org.openfaces.component.chart.impl.configuration.charts.PieChartConfigurator.java

protected Plot createPlot(Chart chart, ChartModel model, ModelInfo info) {
    final PieChartView chartView = (PieChartView) chart.getChartView();

    if (info.isDataEmpty()) {
        return new PiePlotAdapter(null, chart, chartView);
    }//from   w w w .j  av  a2 s  .c  o m

    if (info.getNonEmptySeriesList().length < 2) {
        PieDataset ds = ModelConverter.toPieDataset(model);
        final Plot adapter = (chartView.isEnable3D()) ? new PiePlot3DAdapter(ds, chart, chartView)
                : new PiePlotAdapter(ds, chart, chartView);

        return adapter;
    }

    CategoryDataset ds = ModelConverter.toCategoryDataset(info);

    return new MultiplePiePlotAdapter(ds, TableOrder.BY_ROW, chart, chartView);
}

From source file:biz.ixnay.pivot.charts.skin.jfree.PieChartViewSkin.java

@Override
protected JFreeChart createChart() {
    PieChartView chartView = (PieChartView) getComponent();

    String title = chartView.getTitle();
    boolean showLegend = chartView.getShowLegend();

    ChartView.CategorySequence categories = chartView.getCategories();
    String seriesNameKey = chartView.getSeriesNameKey();
    List<?> chartData = chartView.getChartData();

    JFreeChart chart;//from w  w  w.  j  a  v  a 2s .  com
    if (threeDimensional) {
        if (chartData.getLength() > 1) {
            CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

            chart = ChartFactory.createMultiplePieChart3D(title, dataset, TableOrder.BY_ROW, showLegend, false,
                    false);
        } else {
            PieSeriesDataset dataset = new PieSeriesDataset(categories, chartData.get(0));
            chart = ChartFactory.createPieChart3D(title, dataset, showLegend, false, false);

            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setDarkerSides(darkerSides);
            plot.setDepthFactor(depthFactor);
        }
    } else {
        if (chartData.getLength() > 1) {
            CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

            chart = ChartFactory.createMultiplePieChart(title, dataset, TableOrder.BY_ROW, showLegend, false,
                    false);
        } else {
            PieSeriesDataset dataset = new PieSeriesDataset(categories, chartData.get(0));
            chart = ChartFactory.createPieChart(title, dataset, showLegend, false, false);

            HashMap<String, String> categoryLabels = new HashMap<String, String>();
            for (int i = 0, n = categories.getLength(); i < n; i++) {
                ChartView.Category category = categories.get(i);
                categoryLabels.put(category.getKey(), category.getLabel());
            }

            PiePlot plot = (PiePlot) chart.getPlot();
            for (String categoryKey : explodePercentages) {
                plot.setExplodePercent(categoryLabels.get(categoryKey),
                        explodePercentages.get(categoryKey).doubleValue());
            }
        }
    }

    return chart;
}

From source file:org.jfree.data.category.CategoryToPieDatasetTest.java

/**
 * Some checks for the getValue() method.
 *///from   w w w .  j av a  2s  . c o  m
@Test
public void testGetValue() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0);
    assertEquals(d1.getValue("C1"), new Double(1.1));
    assertEquals(d1.getValue("C2"), new Double(2.2));

    // check negative index throws exception
    try {
        /* Number n = */ d1.getValue(-1);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // check index == getItemCount() throws exception
    try {
        /* Number n = */ d1.getValue(d1.getItemCount());
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // test null source
    CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0);
    try {
        /* Number n = */ p1.getValue(0);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }
}

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   w w 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:edu.uara.wrappers.customcharts.CustomBarChart.java

@Override
public void updateChart(CustomDatasetTable dsTable, ITableObject source) {
    if (ds != null)//
    {//from  ww w .  ja v a 2 s.c  o m
        TableOrder tableOrder = TableOrder.BY_ROW;
        DefaultCategoryDataset dataset = (DefaultCategoryDataset) ds;

        List rows = dataset.getRowKeys();
        List cols = dataset.getColumnKeys();

        String[] rowLabels = dsTable.getRowLabels();
        String[] columnLabels = dsTable.getColumnLabels(source);

        for (int i = 0; i < rows.size(); i++) {
            if (!rows.get(i).toString().equals(rowLabels)) {
                tableOrder = TableOrder.BY_COLUMN;
                break;
            }
        }

        if (tableOrder == TableOrder.BY_ROW) {
            double[][] values = dsTable.getTableContentAsValue(source);
            for (int r = 0; r < rowLabels.length; r++) {
                for (int c = 0; c < columnLabels.length; c++) {
                    dataset.setValue(values[r][c], rowLabels[r], columnLabels[c]);

                }
            }

        } else {
            double[][] values = dsTable.getTableContentAsValueTranspose(source);
            for (int r = 0; r < rows.size(); r++) {
                for (int c = 0; c < cols.size(); c++) {
                    dataset.setValue(values[r][c], rows.get(r).toString(), cols.get(c).toString());

                }
            }
        }
    }
}

From source file:com.twocents.test.ui.chart.MultipieChart.java

/**
 * Creates a sample chart with the given dataset.
 * //w ww.j  a v a 2 s . com
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart("Multiple Pie Chart", // chart title
            dataset, // dataset
            TableOrder.BY_ROW, true, // include legend
            true, false);
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final JFreeChart subchart = plot.getPieChart();
    final PiePlot p = (PiePlot) subchart.getPlot();
    p.setLabelGenerator(new StandardPieItemLabelGenerator("{0}"));
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    p.setInteriorGap(0.30);

    return chart;
}

From source file:edu.uara.wrappers.customcharts.CustomPieChart.java

@Override
public void updateChart(CustomDatasetTable dsTable, ITableObject source) {
    if (ds != null)//update multipiedataset
    {/*from   w  ww.  j a  va  2 s .  c o  m*/
        DefaultCategoryDataset dataset = (DefaultCategoryDataset) ds;
        String[] rowLabels = dsTable.getRowLabels();
        String[] columnLabels = dsTable.getColumnLabels(source);
        double[][] values = dsTable.getTableContentAsValue(source);
        for (int r = 0; r < rowLabels.length; r++) {
            for (int c = 0; c < columnLabels.length; c++) {
                dataset.setValue(values[r][c], rowLabels[r], columnLabels[c]);

            }
        }

    } else if (pieDs != null)//single pie dataset
    {
        DefaultPieDataset pieDataset = (DefaultPieDataset) pieDs;
        String[] rowLabels = dsTable.getRowLabels();
        String[] columnLabels = dsTable.getColumnLabels(source);
        double[][] values = dsTable.getTableContentAsValue(source);
        if (tableOrder == TableOrder.BY_ROW) {
            int r;//index of the series in the main dataset
            for (r = 0; r < rowLabels.length; r++) {
                if (rowLabels[r].equals(this.singlePieDatasetSeries))
                    ;
                break;
            }
            for (int c = 0; c < columnLabels.length; c++) {
                pieDataset.setValue(columnLabels[c], values[r][c]);
            }
        } else if (tableOrder == TableOrder.BY_COLUMN) {
            int c;//index of the series in the main dataset
            for (c = 0; c < columnLabels.length; c++) {
                if (columnLabels[c].equals(this.singlePieDatasetSeries))
                    ;
                break;
            }
            for (int r = 0; r < rowLabels.length; r++) {
                pieDataset.setValue(rowLabels[r], values[r][c]);
            }

        }

    }

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java

protected JFreeChart computeChart(final Dataset dataset) {
    final CategoryDataset categoryDataset;
    if (dataset instanceof CategoryDataset == false) {
        categoryDataset = null;/*from w ww .  j a v a2 s . co m*/
    } else {
        categoryDataset = (CategoryDataset) dataset;
    }

    final TableOrder order;
    if (isMultipieByRow()) {
        order = TableOrder.BY_ROW;
    } else {
        order = TableOrder.BY_COLUMN;
    }

    if (isThreeD()) {
        return ChartFactory.createMultiplePieChart3D(computeTitle(), categoryDataset, order, isShowLegend(),
                false, false);
    } else {
        return ChartFactory.createMultiplePieChart(computeTitle(), categoryDataset, order, isShowLegend(),
                false, false);
    }
}

From source file:org.jfree.data.category.CategoryToPieDatasetTest.java

/**
 * Some checks for the getKey(int) method.
 *//*  w w w  . j  a  v a  2 s  . com*/
@Test
public void testGetKey() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0);
    assertEquals(d1.getKey(0), "C1");
    assertEquals(d1.getKey(1), "C2");

    // check negative index throws exception
    try {
        /* Number n = */ d1.getKey(-1);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // check index == getItemCount() throws exception
    try {
        /* Number n = */ d1.getKey(d1.getItemCount());
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // test null source
    CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0);
    try {
        /* Number n = */ p1.getKey(0);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }
}