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

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

Introduction

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

Prototype

@Override
public int getRowCount() 

Source Link

Document

Returns the number of rows in the table.

Usage

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

private double computeMaxValue(final DefaultCategoryDataset defaultDataset) {
    final int rows = defaultDataset.getRowCount();
    final int columns = defaultDataset.getColumnCount();
    double maxdata = 0.01;

    for (int r = 0; r < rows; r++) {
        for (int cc = 0; cc < columns; cc++) {
            final Number value = defaultDataset.getValue(r, cc);
            if (value == null) {
                continue;
            }/*from   w w w .  j a  v  a  2 s.  c  o  m*/

            if (value.doubleValue() > maxdata) {
                maxdata = value.doubleValue();
            }
        }
    }
    return maxdata;
}

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

/**
 * Some tests for the getRowCount() method.
 *//*www  .  j  a  v  a  2s .c o m*/
public void testGetRowCount() {
    DefaultCategoryDataset d = new DefaultCategoryDataset();
    assertTrue(d.getRowCount() == 0);

    d.addValue(1.0, "R1", "C1");
    assertTrue(d.getRowCount() == 1);

    d.addValue(1.0, "R2", "C1");
    assertTrue(d.getRowCount() == 2);

    d.addValue(2.0, "R2", "C1");
    assertTrue(d.getRowCount() == 2);

    // a row of all null values is still counted...
    d.setValue(null, "R2", "C1");
    assertTrue(d.getRowCount() == 2);
}

From source file:org.pentaho.platform.uifoundation.chart.CategoryDatasetChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$

    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);/* w ww . j  a v  a  2s.  c o  m*/
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
    } catch (NumberFormatException ignored) {
        // go with the default
    }
    try {
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (NumberFormatException ignored) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    DefaultCategoryDataset chartDataDefinition = (DefaultCategoryDataset) dataDefinition;
    if (chartDataDefinition.getRowCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getRowCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getColumnCount(); column++) {
                Number value = chartDataDefinition.getValue(row, column);
                Comparable rowKey = chartDataDefinition.getRowKey(row);
                Comparable columnKey = chartDataDefinition.getColumnKey(column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

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

/**
 * Some checks for the removeRow(Comparable) method.
 *///from   w w  w.j  ava 2  s .c o  m
public void testRemoveRow() {
    DefaultCategoryDataset d = new DefaultCategoryDataset();
    d.addValue(1.0, "R1", "C1");
    d.addValue(2.0, "R2", "C2");
    assertEquals(2, d.getRowCount());
    d.removeRow("R2");
    assertEquals(1, d.getRowCount());

    boolean pass = false;
    try {
        d.removeRow("XXX");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        d.removeRow(null);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some basic checks for the removeValue() method.
 *///from w w w.  j  a v  a  2  s .c  o m
public void testRemoveValue() {
    DefaultCategoryDataset d = new DefaultCategoryDataset();
    d.removeValue("R1", "C1");
    d.addValue(new Double(1.0), "R1", "C1");
    d.removeValue("R1", "C1");
    assertEquals(0, d.getRowCount());
    assertEquals(0, d.getColumnCount());

    d.addValue(new Double(1.0), "R1", "C1");
    d.addValue(new Double(2.0), "R2", "C1");
    d.removeValue("R1", "C1");
    assertEquals(new Double(2.0), d.getValue(0, 0));

    boolean pass = false;
    try {
        d.removeValue(null, "C1");
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        d.removeValue("R1", null);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:spec.reporter.Utils.java

public static void generateMainChart(double compositeScore, TreeMap<String, Double> scores) {

    // Valid benchmarks + room for all possible extra - compiler, crypto, scimark, scimark.small, scimark.large, startup, xml, composite score
    Color[] colors = new Color[scores.size() + 8];

    // create the dataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int count = 0;

    Iterator<String> iteratorBenchmarks = scores.keySet().iterator();
    while (iteratorBenchmarks.hasNext()) {
        String key = iteratorBenchmarks.next();
        Double score = scores.get(key);
        if (Utils.isValidScore(score)) {
            dataset.addValue(score, key, key);
            colors[count++] = (Color) colorMap.get(key);
        }/* w  w w.  jav a2s.  c  o  m*/
    }

    if (Utils.isValidScore(compositeScore)) {
        dataset.addValue(compositeScore, Utils.CSCORE_NAME, Utils.CSCORE_NAME);
        colors[count++] = (Color) colorMap.get(Utils.CSCORE_NAME);
    }

    JFreeChart chart = ChartFactory.createStackedBarChart("Scores", // chart title
            "", // domain axis label
            "", dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            false, // tooltips?
            false // URLs?
    );

    CategoryItemRenderer renderer = chart.getCategoryPlot().getRendererForDataset(dataset);
    for (int i = 0; i < count; i++) {
        Color paint = (Color) colors[i];
        if (paint != null) {
            renderer.setSeriesPaint(i, paint);
        }
    }

    try {
        ChartUtilities.saveChartAsJPEG(new File(getFullImageName("all")), chart, 600,
                50 + (dataset.getRowCount()) * 20);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.datacleaner.widgets.result.PatternFinderResultSwingRendererCrosstabDelegate.java

protected void displayChart(DCTable table, DisplayChartCallback displayChartCallback) {
    final int rowCount = table.getRowCount();
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < rowCount; i++) {
        final Object expressionObject = table.getValueAt(i, 0);
        final String expression = extractString(expressionObject);

        final Object countObject = table.getValueAt(i, 1);
        final String countString = extractString(countObject);
        final int count = Integer.parseInt(countString);
        dataset.addValue(count, expression, "");
    }/*from  w w  w .java2s  .com*/

    // only show legend if there are not too many patterns
    final boolean showLegend = dataset.getRowCount() < 25;

    JFreeChart chart = ChartFactory.createBarChart("", "", "Match count", dataset, PlotOrientation.VERTICAL,
            showLegend, true, false);
    ChartUtils.applyStyles(chart);

    final ChartPanel chartPanel = ChartUtils.createPanel(chart, true);

    displayChartCallback.displayChart(chartPanel);
}

From source file:org.jfree.data.category.junit.DefaultCategoryDatasetTests.java

/**
 * Some basic checks for the removeValue() method.
 *//*from ww  w . j  a v  a  2 s.  c om*/
public void testRemoveValue() {
    DefaultCategoryDataset d = new DefaultCategoryDataset();

    // if we try removing with unknown keys, we expect an exception
    boolean pass = false;
    try {
        d.removeValue("R1", "C1");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);

    d.addValue(new Double(1.0), "R1", "C1");
    d.removeValue("R1", "C1");
    assertEquals(0, d.getRowCount());
    assertEquals(0, d.getColumnCount());

    d.addValue(new Double(1.0), "R1", "C1");
    d.addValue(new Double(2.0), "R2", "C1");
    d.removeValue("R1", "C1");
    assertEquals(new Double(2.0), d.getValue(0, 0));

    pass = false;
    try {
        d.removeValue(null, "C1");
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        d.removeValue("R1", null);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:com.etest.view.tq.charts.GraphicalInventoryBarChart.java

public GraphicalInventoryBarChart() {
    setModal(true);//from   w w  w .j av  a  2  s . com

    VerticalLayout v = new VerticalLayout();
    v.setMargin(true);

    //        Panel panel = new Panel();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Curriculum c : cs.getAllCurriculum()) {
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                dataset.addValue(rs.getTotalCasesBySubject(c.getCurriculumId()), "Cases", c.getSubject());
            } else {
                dataset.addValue(rs.getTotalItemsBySubject(c.getCurriculumId()), "Items", c.getSubject());
            }
        }
    }

    JFreeChart chart = ChartFactory.createBarChart("Inventory of Items and Cases", "Subjects", "", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();

    Color color;

    for (int i = 0; i < dataset.getRowCount(); i++) {
        if (i % 2 == 0) {
            renderer.setSeriesPaint(i, new Color(0, 0, 255));
        } else {
            renderer.setSeriesPaint(i, new Color(255, 0, 0));
        }
    }

    //        JFreeChartWrapper wrapper = new JFreeChartWrapper(chart){
    //            
    //            @Override
    //            public void attach(){
    //                super.attach();
    //                setResource("src", getSource());
    //            }
    //            
    //        };

    v.addComponent(new ReportChartWrapper(chart, null, null));
    v.setWidthUndefined();
    v.setHeightUndefined();

    setContent(v);
    getContent().setWidthUndefined();
    getContent().setHeightUndefined();
    center();
}

From source file:com.swordlord.gozer.components.fop.graph.GFopStackedBarChart.java

public GFopStackedBarChart(IGozerFrameExtension gfe, GStackedBarChart chart) {
    super(gfe);/* w  w w. ja v  a  2  s.  co m*/

    DataBindingMember dbMemberRowKey = chart.getDataBindingMemberRowKey();
    DataBindingMember dbMemberColKey = chart.getDataBindingMemberColKey();
    DataBindingMember dbMemberValue = chart.getDataBindingMemberValue();
    DataBindingManager dbManager = chart.getDataBindingManager();

    DefaultCategoryDataset dcd = new DefaultCategoryDataset();

    List<DataRowBase> rowTests = dbManager.getRows(dbMemberValue);
    for (int j = 0; j < rowTests.size(); j++) {
        DataRowBase row = rowTests.get(j);

        String strKey = row.getPropertyAsStringForce(dbMemberRowKey.getRelativePathWithField());

        dcd.setValue(row.getPropertyAsInt(dbMemberValue.getRelativePathWithField()), strKey,
                row.getPropertyAsStringForce(dbMemberColKey.getRelativePathWithField()));
    }

    JFreeChart fc = ChartFactory.createStackedBarChart(chart.getTitle(), chart.getCategoryAxisLabel(),
            chart.getValueAxisLabel(), dcd, chart.getOrientation(), chart.getLegend(), false, false);

    // Do this in a more static way!
    StackedBarRenderer.setDefaultBarPainter(new StandardBarPainter());

    //chart.setBackgroundPaint(Color.white);
    if (chart.getSubTitle() != null) {
        fc.addSubtitle(new TextTitle(chart.getSubTitle()));
    }

    CategoryPlot plot = fc.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDrawingSupplier(chart.getDrawingSupplier());

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(chart.getCategoryAxisVisible());

    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setVisible(chart.getValueAxisVisible());

    /*
    //CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer();
    for (int j = 0; j < rowKey.length; j++)
    {
       renderer.setSeriesItemLabelGenerator(j, new LabelGenerator(j, rowKey[j]));
       renderer.setSeriesItemLabelsVisible(j, true);
    }
    */
    StackedBarRenderer renderer = new StackedBarRenderer();

    for (int j = 0; j < dcd.getRowCount(); j++) {
        renderer.setSeriesItemLabelGenerator(j, new StandardCategoryItemLabelGenerator());
        renderer.setSeriesItemLabelsVisible(j, true);
    }

    //renderer.setLegendItemLabelGenerator(new LabelGenerator());
    renderer.setShadowVisible(false);

    plot.setRenderer(renderer);

    _image = new ChartImage("chart", fc, chart.getWidth(800), chart.getHeight(800));
}