Example usage for org.jfree.util TableOrder BY_COLUMN

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

Introduction

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

Prototype

TableOrder BY_COLUMN

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

Click Source Link

Document

By column.

Usage

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

/**
 * Some tests for the constructor./* w  w  w.j a  v a  2s.  com*/
 */
@Test
public void testConstructor() {
    // try a null source
    CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0);
    assertNull(p1.getUnderlyingDataset());
    assertEquals(p1.getItemCount(), 0);
    assertTrue(p1.getKeys().isEmpty());
    assertNull(p1.getValue("R1"));
}

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

@Override
public void updateChart(CustomDatasetTable dsTable, ITableObject source) {
    if (ds != null)//
    {// ww w.j a 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:org.jfree.data.category.CategoryToPieDatasetTest.java

/**
 * Some checks for the getValue() method.
 *///from  w ww. java 2s .com
@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:edu.uara.wrappers.customcharts.CustomPieChart.java

@Override
public void updateChart(CustomDatasetTable dsTable, ITableObject source) {
    if (ds != null)//update multipiedataset
    {//  w ww  .ja v  a  2  s . co 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 ww  w .  j  av  a 2  s.  c o 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.chart.demo.MultiplePieChartDemo3.java

/**
 * Creates a sample chart for the given dataset.
 * /*w  w w  . ja v  a  2 s. c o m*/
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 3", dataset,
            TableOrder.BY_COLUMN, true, true, false);
    chart.setBackgroundPaint(new Color(216, 255, 216));
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final PiePlot p = (PiePlot) plot.getPieChart().getPlot();
    p.setMaximumLabelWidth(0.35);
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    p.setInteriorGap(0.30);
    return chart;
}

From source file:org.jfree.chart.demo.MultiplePieChartDemo2.java

/**
 * Creates a sample chart with the given dataset.
 * //from w ww  .  j av  a 2 s  .  c om
 * @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_COLUMN, true, // include legend
            true, false);
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineStroke(new BasicStroke(1.0f));
    final JFreeChart subchart = plot.getPieChart();
    final PiePlot p = (PiePlot) subchart.getPlot();
    p.setBackgroundPaint(null);
    p.setOutlineStroke(null);
    p.setLabelGenerator(new StandardPieItemLabelGenerator("{0} ({2})", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    p.setMaximumLabelWidth(0.35);
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    p.setInteriorGap(0.30);
    return chart;
}

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

/**
 * Some checks for the getKey(int) method.
 *///from   ww  w .  j  a  v a 2 s. c o m
@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
    }
}

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

/**
 * Returns the number of items (values) in the collection.  If the
 * underlying dataset is <code>null</code>, this method returns zero.
 *
 * @return The item count.//from   ww  w  .j  av  a 2  s  .c om
 */
@Override
public int getItemCount() {
    int result = 0;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnCount();
        } else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowCount();
        }
    }
    return result;
}

From source file:org.jfree.chart.demo.MultiplePieChartDemo4.java

/**
 * Creates a sample chart for the given dataset.
 * /* w ww. j a  v a  2 s  . c o  m*/
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart3D("Multiple Pie Chart Demo 4", dataset,
            TableOrder.BY_COLUMN, false, true, false);
    chart.setBackgroundPaint(new Color(216, 255, 216));
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final JFreeChart subchart = plot.getPieChart();
    //        final StandardLegend legend = new StandardLegend();
    //      legend.setItemFont(new Font("SansSerif", Font.PLAIN, 8));
    //    legend.setAnchor(Legend.SOUTH);
    //  subchart.setLegend(legend);
    plot.setLimit(0.10);
    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;
}