Search in sources :

Example 31 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.

the class AreaChartTest method testReplaceDataset.

/**
 * 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);
}
Also used : CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) Range(org.jfree.data.Range) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Test(org.junit.Test)

Example 32 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.

the class AreaChartTest method createAreaChart.

/**
 * Create an area chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createAreaChart() {
    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.createAreaChart("Area Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, true, true);
}
Also used : CategoryDataset(org.jfree.data.category.CategoryDataset)

Example 33 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.

the class LayeredBarRenderer method calculateBarWidth.

/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
@Override
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state) {
    // calculate the bar width - this calculation differs from the
    // BarRenderer calculation because the bars are layered on top of one
    // another, so there is effectively only one bar per category for
    // the purpose of the bar width calculation
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        } else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (dataset.getColumnCount()), maxWidth));
        } else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 34 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.

the class LineAndShapeRenderer method getLegendItem.

/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }
    if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
        CategoryDataset dataset = cp.getDataset(datasetIndex);
        String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
        String description = label;
        String toolTipText = null;
        if (getLegendItemToolTipGenerator() != null) {
            toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
        }
        String urlText = null;
        if (getLegendItemURLGenerator() != null) {
            urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
        }
        Shape shape = lookupLegendShape(series);
        Paint paint = lookupSeriesPaint(series);
        Paint fillPaint = (this.useFillPaint ? getItemFillPaint(series, 0) : paint);
        boolean shapeOutlineVisible = this.drawOutlines;
        Paint outlinePaint = (this.useOutlinePaint ? getItemOutlinePaint(series, 0) : paint);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        boolean lineVisible = getItemLineVisible(series, 0);
        boolean shapeVisible = getItemShapeVisible(series, 0);
        LegendItem result = new LegendItem(label, description, toolTipText, urlText, shapeVisible, shape, getItemShapeFilled(series, 0), fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), getItemStroke(series, 0), getItemPaint(series, 0));
        result.setLabelFont(lookupLegendTextFont(series));
        Paint labelPaint = lookupLegendTextPaint(series);
        if (labelPaint != null) {
            result.setLabelPaint(labelPaint);
        }
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
        result.setSeriesKey(dataset.getRowKey(series));
        result.setSeriesIndex(series);
        return result;
    }
    return null;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.LegendItem) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 35 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.

the class StackedBarRenderer3D method calculateBarWidth.

/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
@Override
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state) {
    // calculate the bar width
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset data = plot.getDataset(rendererIndex);
    if (data != null) {
        PlotOrientation orientation = plot.getOrientation();
        double space = 0.0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        } else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        int columns = data.getColumnCount();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin);
        if (columns > 0) {
            state.setBarWidth(Math.min(used / columns, maxWidth));
        } else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint)

Aggregations

CategoryDataset (org.jfree.data.category.CategoryDataset)107 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)41 CategoryAxis (org.jfree.chart.axis.CategoryAxis)35 CategoryPlot (org.jfree.chart.plot.CategoryPlot)29 Test (org.junit.Test)29 Paint (java.awt.Paint)28 NumberAxis (org.jfree.chart.axis.NumberAxis)21 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)20 JFreeChart (org.jfree.chart.JFreeChart)17 ValueAxis (org.jfree.chart.axis.ValueAxis)17 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)16 Range (org.jfree.data.Range)13 PlotOrientation (org.jfree.chart.plot.PlotOrientation)11 DefaultCategoryItemRenderer (org.jfree.chart.renderer.category.DefaultCategoryItemRenderer)11 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)9 DefaultMultiValueCategoryDataset (org.jfree.data.statistics.DefaultMultiValueCategoryDataset)9 MultiValueCategoryDataset (org.jfree.data.statistics.MultiValueCategoryDataset)9 LegendItem (org.jfree.chart.LegendItem)8 DefaultIntervalCategoryDataset (org.jfree.data.category.DefaultIntervalCategoryDataset)8 DefaultStatisticalCategoryDataset (org.jfree.data.statistics.DefaultStatisticalCategoryDataset)8