org.jfree.data.xy.TableXYDataset Java Examples

The following examples show how to use org.jfree.data.xy.TableXYDataset. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StackedXYAreaRenderer2.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
private double[] getStackValues(TableXYDataset dataset,
                                int series, int index) {
    double[] result = new double[2];
    for (int i = 0; i < series; i++) {
        double v = dataset.getYValue(i, index);
        if (!Double.isNaN(v)) {
            if (v >= 0.0) {
                result[1] += v;
            }
            else {
                result[0] += v;
            }
        }
    }
    return result;
}
 
Example #2
Source File: StackedXYAreaRenderer2Test.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));

    // try null argument
    assertNull(renderer.findRangeBounds(null));

    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example #3
Source File: StackedXYAreaRenderer2Test.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));

    // try null argument
    assertNull(renderer.findRangeBounds(null));

    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example #4
Source File: StackedXYBarRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #5
Source File: StackedXYAreaRenderer2.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the 
 * items from the specified dataset.
 * 
 * @param dataset  the dataset (<code>null</code> permitted).
 * 
 * @return The range (or <code>null</code> if the dataset is 
 *         <code>null</code> or empty).
 */
public Range findRangeBounds(XYDataset dataset) {
    if (dataset == null) {
        return null;
    }
    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    TableXYDataset d = (TableXYDataset) dataset;
    int itemCount = d.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        double[] stackValues = getStackValues((TableXYDataset) dataset, 
                d.getSeriesCount(), i);
        min = Math.min(min, stackValues[0]);
        max = Math.max(max, stackValues[1]);
    }
    if (min == Double.POSITIVE_INFINITY) {
        return null;
    }
    return new Range(min, max);
}
 
Example #6
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
public void testFindRangeBounds() {
    TableXYDataset dataset 
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, 
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));
    
    // try null argument
    assertNull(renderer.findRangeBounds(null));
    
    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example #7
Source File: StackedXYAreaRenderer2.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
private double[] getStackValues(TableXYDataset dataset,
                                int series, int index) {
    double[] result = new double[2];
    for (int i = 0; i < series; i++) {
        double v = dataset.getYValue(i, index);
        if (!Double.isNaN(v)) {
            if (v >= 0.0) {
                result[1] += v;
            }
            else {
                result[0] += v;
            }
        }
    }
    return result;
}
 
Example #8
Source File: StackedXYBarRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #9
Source File: DatasetUtilitiesTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample dataset for testing purposes.
 *
 * @return A sample dataset.
 */
private TableXYDataset createTableXYDataset1() {
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    XYSeries s1 = new XYSeries("Series 1", true, false);
    s1.add(1.0, 1.0);
    s1.add(2.0, 2.0);
    dataset.addSeries(s1);

    XYSeries s2 = new XYSeries("Series 2", true, false);
    s2.add(1.0, -2.0);
    s2.add(2.0, -1.0);
    dataset.addSeries(s2);

    return dataset;
}
 
Example #10
Source File: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
public void testFindDomainBounds() {
    TableXYDataset dataset 
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, 
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #11
Source File: XYLineAndShapeRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
public void testFindRangeBounds() {
    TableXYDataset dataset 
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, 
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    Range bounds = rangeAxis.getRange();
    assertFalse(bounds.contains(1.0));
    assertTrue(bounds.contains(2.0));
    assertTrue(bounds.contains(5.0));
    assertFalse(bounds.contains(6.0));
}
 
Example #12
Source File: XYLineAndShapeRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    Range bounds = rangeAxis.getRange();
    assertFalse(bounds.contains(1.0));
    assertTrue(bounds.contains(2.0));
    assertTrue(bounds.contains(5.0));
    assertFalse(bounds.contains(6.0));
}
 
Example #13
Source File: DatasetUtilitiesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a sample dataset for testing purposes.
 * 
 * @return A sample dataset.
 */
private TableXYDataset createTableXYDataset1() {
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();
    
    XYSeries s1 = new XYSeries("Series 1", true, false);
    s1.add(1.0, 1.0);
    s1.add(2.0, 2.0);
    dataset.addSeries(s1);
    
    XYSeries s2 = new XYSeries("Series 2", true, false);
    s2.add(1.0, -2.0);
    s2.add(2.0, -1.0);
    dataset.addSeries(s2);
    
    return dataset;  
}
 
Example #14
Source File: DatasetUtilitiesTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample dataset for testing purposes.
 *
 * @return A sample dataset.
 */
private TableXYDataset createTableXYDataset1() {
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    XYSeries s1 = new XYSeries("Series 1", true, false);
    s1.add(1.0, 1.0);
    s1.add(2.0, 2.0);
    dataset.addSeries(s1);

    XYSeries s2 = new XYSeries("Series 2", true, false);
    s2.add(1.0, -2.0);
    s2.add(2.0, -1.0);
    dataset.addSeries(s2);

    return dataset;
}
 
Example #15
Source File: StackedXYAreaRenderer2.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all 
 * series up to, but not including, <code>series</code> for the specified 
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code> 
 *     for <code>index</code>.
 */
private double[] getStackValues(TableXYDataset dataset, 
                                int series, int index) {
    double[] result = new double[2];
    for (int i = 0; i < series; i++) {
        double v = dataset.getYValue(i, index);
        if (!Double.isNaN(v)) {
            if (v >= 0.0) {
                result[1] += v;   
            }
            else {
                result[0] += v;   
            }
        }
    }
    return result;
}
 
Example #16
Source File: DatasetUtilitiesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a sample dataset for testing purposes.
 *
 * @return A sample dataset.
 */
private TableXYDataset createTableXYDataset1() {
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    XYSeries s1 = new XYSeries("Series 1", true, false);
    s1.add(1.0, 1.0);
    s1.add(2.0, 2.0);
    dataset.addSeries(s1);

    XYSeries s2 = new XYSeries("Series 2", true, false);
    s2.add(1.0, -2.0);
    s2.add(2.0, -1.0);
    dataset.addSeries(s2);

    return dataset;
}
 
Example #17
Source File: StackedXYAreaRenderer2.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (or <code>null</code> if the dataset is
 *         <code>null</code> or empty).
 */
@Override
public Range findRangeBounds(XYDataset dataset) {
    if (dataset == null) {
        return null;
    }
    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    TableXYDataset d = (TableXYDataset) dataset;
    int itemCount = d.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        double[] stackValues = getStackValues((TableXYDataset) dataset,
                d.getSeriesCount(), i);
        min = Math.min(min, stackValues[0]);
        max = Math.max(max, stackValues[1]);
    }
    if (min == Double.POSITIVE_INFINITY) {
        return null;
    }
    return new Range(min, max);
}
 
Example #18
Source File: StackedXYAreaRenderer2.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
private double[] getStackValues(TableXYDataset dataset,
                                int series, int index) {
    double[] result = new double[2];
    for (int i = 0; i < series; i++) {
        double v = dataset.getYValue(i, index);
        if (!Double.isNaN(v)) {
            if (v >= 0.0) {
                result[1] += v;
            }
            else {
                result[0] += v;
            }
        }
    }
    return result;
}
 
Example #19
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a stacked XY area plot.  The chart object returned by this
 * method uses an {@link XYPlot} instance as the plot, with a
 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the
 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.

 *
 * @return A stacked XY area chart.
 */
public static JFreeChart createStackedXYAreaChart(String title,
        String xAxisLabel, String yAxisLabel, TableXYDataset dataset,
        boolean legend) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setOutline(true);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setRangeAxis(yAxis);  // forces recalculation of the axis range
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #20
Source File: StackedXYAreaRenderer2.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (or <code>null</code> if the dataset is
 *         <code>null</code> or empty).
 */
@Override
public Range findRangeBounds(XYDataset dataset) {
    if (dataset == null) {
        return null;
    }
    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    TableXYDataset d = (TableXYDataset) dataset;
    int itemCount = d.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        double[] stackValues = getStackValues((TableXYDataset) dataset,
                d.getSeriesCount(), i);
        min = Math.min(min, stackValues[0]);
        max = Math.max(max, stackValues[1]);
    }
    if (min == Double.POSITIVE_INFINITY) {
        return null;
    }
    return new Range(min, max);
}
 
Example #21
Source File: StackedXYAreaRenderer2Test.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));

    // try null argument
    assertNull(renderer.findRangeBounds(null));

    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example #22
Source File: StackedXYBarRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #23
Source File: StackedXYBarRenderer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 */
@Override
public Range findRangeBounds(XYDataset dataset) {
    if (dataset != null) {
        if (this.renderAsPercentages) {
            return new Range(0.0, 1.0);
        }
        else {
            return DatasetUtilities.findStackedRangeBounds(
                    (TableXYDataset) dataset);
        }
    }
    else {
        return null;
    }
}
 
Example #24
Source File: StackedXYAreaRenderer2.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
private double[] getStackValues(TableXYDataset dataset,
                                int series, int index) {
    double[] result = new double[2];
    for (int i = 0; i < series; i++) {
        double v = dataset.getYValue(i, index);
        if (!Double.isNaN(v)) {
            if (v >= 0.0) {
                result[1] += v;
            }
            else {
                result[0] += v;
            }
        }
    }
    return result;
}
 
Example #25
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));

    // try null argument
    assertNull(renderer.findRangeBounds(null));

    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example #26
Source File: StackedXYAreaRenderer2.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (or <code>null</code> if the dataset is
 *         <code>null</code> or empty).
 */
@Override
public Range findRangeBounds(XYDataset dataset) {
    if (dataset == null) {
        return null;
    }
    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    TableXYDataset d = (TableXYDataset) dataset;
    int itemCount = d.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        double[] stackValues = getStackValues((TableXYDataset) dataset,
                d.getSeriesCount(), i);
        min = Math.min(min, stackValues[0]);
        max = Math.max(max, stackValues[1]);
    }
    if (min == Double.POSITIVE_INFINITY) {
        return null;
    }
    return new Range(min, max);
}
 
Example #27
Source File: DatasetUtilitiesTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a sample dataset for testing purposes.
 *
 * @return A sample dataset.
 */
private TableXYDataset createTableXYDataset1() {
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();

    XYSeries s1 = new XYSeries("Series 1", true, false);
    s1.add(1.0, 1.0);
    s1.add(2.0, 2.0);
    dataset.addSeries(s1);

    XYSeries s2 = new XYSeries("Series 2", true, false);
    s2.add(1.0, -2.0);
    s2.add(2.0, -1.0);
    dataset.addSeries(s2);

    return dataset;
}
 
Example #28
Source File: StackedXYBarRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #29
Source File: RendererXYPackageUtils.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and returns a sample dataset for testing purposes.
 *
 * @return A sample dataset.
 */
public static TableXYDataset createTestTableXYDataset() {
    DefaultTableXYDataset result = new DefaultTableXYDataset();
    XYSeries series1 = new XYSeries("Series 1", false, false);
    series1.add(1.0, 2.0);
    series1.add(2.0, 5.0);
    XYSeries series2 = new XYSeries("Series 2", false, false);
    series2.add(1.0, 4.0);
    series2.add(2.0, 3.0);
    result.addSeries(series1);
    result.addSeries(series2);
    return result;
}
 
Example #30
Source File: Chart_2_DatasetUtilities_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Returns the minimum and maximum values for the dataset's range,
 * assuming that the series are stacked, using the specified base value.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param base  the base value.
 *
 * @return The range (<code>null</code> if the dataset contains no values).
 */
public static Range findStackedRangeBounds(TableXYDataset dataset,
                                           double base) {
    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }
    double minimum = base;
    double maximum = base;
    for (int itemNo = 0; itemNo < dataset.getItemCount(); itemNo++) {
        double positive = base;
        double negative = base;
        int seriesCount = dataset.getSeriesCount();
        for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) {
            double y = dataset.getYValue(seriesNo, itemNo);
            if (!Double.isNaN(y)) {
                if (y > 0.0) {
                    positive += y;
                }
                else {
                    negative += y;
                }
            }
        }
        if (positive > maximum) {
            maximum = positive;
        }
        if (negative < minimum) {
            minimum = negative;
        }
    }
    if (minimum <= maximum) {
        return new Range(minimum, maximum);
    }
    else {
        return null;
    }
}