org.jfree.data.general.DatasetUtilities Java Examples

The following examples show how to use org.jfree.data.general.DatasetUtilities. 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: AbstractCategoryItemRenderer.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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #2
Source File: WaterfallChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a bar chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createWaterfallChart() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}};

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", 
            "C", data);

    // create the chart...
    return ChartFactory.createWaterfallChart(
        "Waterfall Chart",
        "Domain", "Range",
        dataset,
        PlotOrientation.HORIZONTAL,
        true,     // include legend
        true,
        true
    );

}
 
Example #3
Source File: StackedBarChart3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", 
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
                + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #4
Source File: LineChart3DTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
               + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #5
Source File: ContourPlot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the range for an axis.
 *
 * @param axis  the axis.
 *
 * @return The range for an axis.
 */
@Override
public Range getDataRange(ValueAxis axis) {

    if (this.dataset == null) {
        return null;
    }

    Range result = null;

    if (axis == getDomainAxis()) {
        result = DatasetUtilities.findDomainBounds(this.dataset);
    }
    else if (axis == getRangeAxis()) {
        result = DatasetUtilities.findRangeBounds(this.dataset);
    }
    return result;
}
 
Example #6
Source File: AbstractCategoryItemRenderer.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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #7
Source File: AbstractXYItemRenderer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the lower and upper bounds (range) of the x-values in the
 * specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param includeInterval  include the interval (if any) for the dataset?
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findDomainBounds(XYDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getSeriesCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getSeriesKey(s));
            }
        }
        return DatasetUtilities.findDomainBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    return DatasetUtilities.findDomainBounds(dataset, includeInterval);
}
 
Example #8
Source File: AbstractPieItemLabelGenerator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.  The returned array
 * contains four values:
 * <ul>
 * <li>result[0] = the section key converted to a <code>String</code>;</li>
 * <li>result[1] = the formatted data value;</li>
 * <li>result[2] = the formatted percentage (of the total);</li>
 * <li>result[3] = the formatted total value.</li>
 * </ul>
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param key  the key (<code>null</code> not permitted).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(PieDataset dataset, Comparable key) {
    Object[] result = new Object[4];
    double total = DatasetUtilities.calculatePieDatasetTotal(dataset);
    result[0] = key.toString();
    Number value = dataset.getValue(key);
    if (value != null) {
        result[1] = this.numberFormat.format(value);
    }
    else {
        result[1] = "null";
    }
    double percent = 0.0;
    if (value != null) {
        double v = value.doubleValue();
        if (v > 0.0) {
            percent = v / total;
        }
    }
    result[2] = this.percentFormat.format(percent);
    result[3] = this.numberFormat.format(total);
    return result;
}
 
Example #9
Source File: BarChart3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that the data range is as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
            + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
            + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #10
Source File: StackedBarChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a stacked bar chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}};

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", 
            "C", data);

    // create the chart...
    return ChartFactory.createStackedBarChart(
        "Stacked Bar Chart",  // chart title
        "Domain", "Range",
        dataset,      // data
        PlotOrientation.HORIZONTAL,
        true,         // include legend
        true,
        true
    );

}
 
Example #11
Source File: Arja_0089_s.java    From coming with MIT License 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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #12
Source File: BarChartTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
               + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #13
Source File: ContourPlot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the range for an axis.
 *
 * @param axis  the axis.
 *
 * @return The range for an axis.
 */
@Override
public Range getDataRange(ValueAxis axis) {

    if (this.dataset == null) {
        return null;
    }

    Range result = null;

    if (axis == getDomainAxis()) {
        result = DatasetUtilities.findDomainBounds(this.dataset);
    }
    else if (axis == getRangeAxis()) {
        result = DatasetUtilities.findRangeBounds(this.dataset);
    }
    return result;
}
 
Example #14
Source File: AreaChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset(
            "S", "C", data);
    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
               + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #15
Source File: JGenProg2017_00124_s.java    From coming with MIT License 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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #16
Source File: Cardumen_00139_t.java    From coming with MIT License 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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #17
Source File: BarChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a bar chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createBarChart() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}};

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    // create the chart...
    return ChartFactory.createBarChart(
        "Bar Chart",
        "Domain", "Range",
        dataset,
        PlotOrientation.HORIZONTAL,
        true,     // include legend
        true,
        true
    );

}
 
Example #18
Source File: Cardumen_000_s.java    From coming with MIT License 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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #19
Source File: PolarPlot.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a representation of the data within the dataArea region, using the
 * current m_Renderer.
 *
 * @param g2  the graphics device.
 * @param dataArea  the region in which the data is to be drawn.
 * @param info  an optional object for collection dimension 
 *              information (<code>null</code> permitted).
 */
protected void render(Graphics2D g2,
                   Rectangle2D dataArea,
                   PlotRenderingInfo info) {
  
    // now get the data and plot it (the visual representation will depend
    // on the m_Renderer that has been set)...
    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        int seriesCount = this.dataset.getSeriesCount();
        for (int series = 0; series < seriesCount; series++) {
            this.renderer.drawSeries(g2, dataArea, info, this, 
                    this.dataset, series);
        }
    }
    else {
        drawNoDataMessage(g2, dataArea);
    }
}
 
Example #20
Source File: JGenProg2017_00124_t.java    From coming with MIT License 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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #21
Source File: AbstractCategoryItemRenderer.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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #22
Source File: StackedAreaChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a stacked bar chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {
    Number[][] data = new Integer[][]
        {{new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}};

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S",
            "C", data);
    return ChartFactory.createStackedAreaChart(
        "Stacked Area Chart",  // chart title
        "Domain", "Range",
        dataset,      // data
        PlotOrientation.HORIZONTAL,
        true,         // include legend
        true,
        true
    );

}
 
Example #23
Source File: ContourPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the range for an axis.
 *
 * @param axis  the axis.
 *
 * @return The range for an axis.
 */
@Override
public Range getDataRange(ValueAxis axis) {

    if (this.dataset == null) {
        return null;
    }

    Range result = null;

    if (axis == getDomainAxis()) {
        result = DatasetUtilities.findDomainBounds(this.dataset);
    }
    else if (axis == getRangeAxis()) {
        result = DatasetUtilities.findRangeBounds(this.dataset);
    }
    return result;
}
 
Example #24
Source File: Arja_0062_t.java    From coming with MIT License 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).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #25
Source File: ContourPlot.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the range for an axis.
 *
 * @param axis  the axis.
 *
 * @return The range for an axis.
 */
public Range getDataRange(ValueAxis axis) {

    if (this.dataset == null) {
        return null;
    }

    Range result = null;

    if (axis == getDomainAxis()) {
        result = DatasetUtilities.findDomainBounds(this.dataset);
    }
    else if (axis == getRangeAxis()) {
        result = DatasetUtilities.findRangeBounds(this.dataset);
    }

    return result;

}
 
Example #26
Source File: WaterfallChartTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a bar chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createWaterfallChart() {
    Number[][] data = new Integer[][]
        {{new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}};

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S",
            "C", data);
    return ChartFactory.createWaterfallChart(
        "Waterfall Chart",
        "Domain", "Range",
        dataset,
        PlotOrientation.HORIZONTAL,
        true,     // include legend
        true,
        true
    );

}
 
Example #27
Source File: AbstractPieItemLabelGenerator.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.  The returned array
 * contains four values:
 * <ul>
 * <li>result[0] = the section key converted to a <code>String</code>;</li>
 * <li>result[1] = the formatted data value;</li>
 * <li>result[2] = the formatted percentage (of the total);</li>
 * <li>result[3] = the formatted total value.</li>
 * </ul>
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param key  the key (<code>null</code> not permitted).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(PieDataset dataset, Comparable key) {
    Object[] result = new Object[4];
    double total = DatasetUtilities.calculatePieDatasetTotal(dataset);
    result[0] = key.toString();
    Number value = dataset.getValue(key);
    if (value != null) {
        result[1] = this.numberFormat.format(value);
    }
    else {
        result[1] = "null";
    }
    double percent = 0.0;
    if (value != null) {
        double v = value.doubleValue();
        if (v > 0.0) {
            percent = v / total;
        }
    }
    result[2] = this.percentFormat.format(percent);
    result[3] = this.numberFormat.format(total);
    return result;
}
 
Example #28
Source File: StackedBarChart3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
                + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #29
Source File: GroupedStackedBarRenderer.java    From ECG-Viewer with GNU General Public License v2.0 5 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(CategoryDataset dataset) {
    if (dataset == null) {
        return null;
    }
    Range r = DatasetUtilities.findStackedRangeBounds(
            dataset, this.seriesToGroupMap);
    return r;
}
 
Example #30
Source File: StackedAreaChartTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a stacked bar chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {
    Number[][] data = new Integer[][]
        {{new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}};
    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S",
            "C", data);
    return ChartFactory.createStackedAreaChart("Stacked Area Chart",
            "Domain", "Range", dataset, true);
}