Example usage for org.jfree.util TableOrder BY_ROW

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

Introduction

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

Prototype

TableOrder BY_ROW

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

Click Source Link

Document

By row.

Usage

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createMultiplePieChart3D_2(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createMultiplePieChart3D("MultiplePie Chart 3D Demo 2", // chart title
            dataset, // data
            TableOrder.BY_ROW, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from  ww w  .ja va2 s.c  om*/

    chart.setBackgroundPaint(Color.white);

    return chart;

}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createMultiplePieChart3D_2(CategoryDataset dataset) {

    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(TableOrder.BY_ROW);
    plot.setBackgroundPaint(null);//from ww  w .  ja va2s .  c o m
    plot.setOutlineStroke(null);

    JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    plot.setPieChart(pieChart);

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }

    JFreeChart chart = new JFreeChart("MultiplePie Chart 3D Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot,
            legend);
    chart.setBackgroundPaint(Color.white);

    return chart;

}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Returns a collection of legend items for the radar chart.
 *
 * @return The legend items.//from ww  w . j a  v a2s .c  o m
 */
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }

    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }

    if (keys != null) {
        int series = 0;
        Iterator iterator = keys.iterator();
        Shape shape = getLegendItemShape();

        while (iterator.hasNext()) {
            String label = iterator.next().toString();
            String description = label;

            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);
            Stroke stroke = getSeriesOutlineStroke(series);
            LegendItem item = new LegendItem(label, description, null, null, shape, paint, stroke,
                    outlinePaint);
            item.setDataset(getDataset());
            result.add(item);
            series++;
        }
    }

    return result;
}

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

private static JFreeChart createMultiplePieChart(final CategoryDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    TableOrder order = TableOrder.BY_ROW;
    // boolean tooltips = true;
    // boolean urls = true;
    // -----------------------------------------------------------

    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();

    if (order == null) {
        throw new IllegalArgumentException(
                Messages.getInstance().getString("JFreeChartEngine.ERROR_0001_NULL_ORDER_ARGUMENT")); //$NON-NLS-1$
    }/*from w  w  w  .  j av a  2s.c  o  m*/
    MultiplePiePlot plot = new MultiplePiePlot(chartDefinition);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    plot.setDataExtractOrder(order);

    JFreeChart pieCharts = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
    JFreeChart pieChart = plot.getPieChart();
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); //$NON-NLS-1$ //$NON-NLS-2$
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
    plot.setPieChart(pieChart);

    // if (tooltips) {
    // PieToolTipGenerator tooltipGenerator = new
    // StandardPieToolTipGenerator();
    // PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    // pp.setToolTipGenerator(tooltipGenerator);
    // }

    // if (urls) {
    // PieURLGenerator urlGenerator = new StandardPieURLGenerator();
    // PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    // pp.setURLGenerator(urlGenerator);
    // }

    return pieCharts;
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).// ww w.  j  ava2s  .  c  o m
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    //drawOutline(g2, area);

    Shape savedClip = g2.getClip();

    g2.clip(area);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        int seriesCount = 0, catCount = 0;

        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        } else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }

        // ensure we have a maximum value to use on the axes
        if (this.maxValue == DEFAULT_MAX_VALUE)
            calculateMaxValue(seriesCount, catCount);

        // Next, setup the plot area

        // adjust the plot area by the interior spacing value

        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();

        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;

        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;

        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;

        Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);

        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle()
                    + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3));

            Point2D endPoint = getWebPoint(radarArea, angle, 1);
            // 1 = end of axis
            Line2D line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / (catCount > 2 ? catCount : 3));
        }

        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW);
        }
    } else {
        drawNoDataMessage(g2, area);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    //drawOutline(g2, area);
}

From source file:spinworld.gui.RadarPlot.java

/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 *//*from   w  w  w  . ja  v  a2 s.  c o m*/
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List<?> keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator<?> iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable<?> key = (Comparable<?>) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getHeadOutlineStroke(series);
        LegendItem item = new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}

From source file:spinworld.gui.RadarPlot.java

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer)./*from w ww .ja v a  2s .com*/
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    drawOutline(g2, area);

    Shape savedClip = g2.getClip();

    g2.clip(area);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        int seriesCount = 0, catCount = 0;

        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        } else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }

        // ensure we have origin and maximum value for each axis
        ensureBoundaryValues(seriesCount, catCount);

        // Next, setup the plot area

        // adjust the plot area by the interior spacing value

        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();

        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;

        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;

        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;

        Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);

        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount);

            Point2D endPoint = getWebPoint(radarArea, angle, 1);
            // 1 = end of axis
            Line2D line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            if (isAxisTickVisible()) {
                drawTicks(g2, radarArea, angle, cat);
            }
            drawLabel(g2, area, radarArea, 0.0, cat, angle, 360.0 / catCount);
        }

        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW);
        }
    } else {
        drawNoDataMessage(g2, area);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, area);
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Draws a radar plot polygon./*  w w w  .  j av  a 2 s  . c  o  m*/
 *
 * @param g2 the graphics device.
 * @param plotArea the area we are plotting in (already adjusted).
 * @param centre the centre point of the radar axes
 * @param info chart rendering info.
 * @param series the series within the dataset we are plotting
 * @param catCount the number of categories per radar plot
 * @param headH the data point height
 * @param headW the data point width
 */
protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info,
        int series, int catCount, double headH, double headW) {

    Polygon polygon = new Polygon();

    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    // plot the data...
    for (int cat = 0; cat < catCount; cat++) {

        Number dataValue = getPlotValue(series, cat);

        if (dataValue != null) {
            double value = dataValue.doubleValue();

            if (value >= 0) { // draw the polygon series...

                // Finds our starting angle from the centre for this axis

                double angle = getStartAngle()
                        + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3));

                // The following angle calc will ensure there isn't a top
                // vertical axis - this may be useful if you don't want any
                // given criteria to 'appear' move important than the
                // others..
                //  + (getDirection().getFactor()
                //        * (cat + 0.5) * 360 / catCount);

                // find the point at the appropriate distance end point
                // along the axis/angle identified above and add it to the
                // polygon

                Point2D point = getWebPoint(plotArea, angle, value / this.maxValue);
                polygon.addPoint((int) point.getX(), (int) point.getY());

                // put an elipse at the point being plotted..

                Paint paint = getSeriesPaint(series);
                Paint outlinePaint = getSeriesOutlinePaint(series);
                Stroke outlineStroke = getSeriesOutlineStroke(series);

                Ellipse2D head = new Ellipse2D.Double(point.getX() - headW / 2, point.getY() - headH / 2, headW,
                        headH);
                g2.setPaint(paint);
                g2.fill(head);
                g2.setStroke(outlineStroke);
                g2.setPaint(outlinePaint);
                g2.draw(head);

                if (entities != null) {
                    int row = 0;
                    int col = 0;
                    if (this.dataExtractOrder == TableOrder.BY_ROW) {
                        row = series;
                        col = cat;
                    } else {
                        row = cat;
                        col = series;
                    }
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col);
                    }

                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, row, col);
                    }

                    Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH),
                            (int) (headW * 2), (int) (headH * 2));
                    CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset,
                            this.dataset.getRowKey(row), this.dataset.getColumnKey(col));
                    entities.add(entity);
                }

            }
        }
    }
    // Plot the polygon

    Paint paint = getSeriesPaint(series);
    g2.setPaint(paint);
    g2.setStroke(getSeriesOutlineStroke(series));
    g2.draw(polygon);

    // Lastly, fill the web polygon if this is required

    if (this.webFilled) {
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2.fill(polygon);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    }
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Returns the value to be plotted at the interseries of the
 * series and the category.  This allows us to plot
 * <code>BY_ROW</code> or <code>BY_COLUMN</code> which basically is just
 * reversing the definition of the categories and data series being
 * plotted./*from w  w w. j a  va 2s .c  o m*/
 *
 * @param series the series to be plotted.
 * @param cat the category within the series to be plotted.
 *
 * @return The value to be plotted (possibly <code>null</code>).
 *
 * @see #getDataExtractOrder()
 */
protected Number getPlotValue(int series, int cat) {
    Number value = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        value = this.dataset.getValue(series, cat);
    } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        value = this.dataset.getValue(cat, series);
    }
    return value;
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Draws the label for one axis./*w  w  w .j a  va2 s  . c  o  m*/
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area
 * @param value  the value of the label (ignored).
 * @param cat  the category (zero-based index).
 * @param startAngle  the starting angle.
 * @param extent  the extent of the arc.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value, int cat, double startAngle,
        double extent) {
    FontRenderContext frc = g2.getFontRenderContext();

    String label = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        // if series are in rows, then the categories are the column keys
        label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
    } else {
        // if series are in columns, then the categories are the row keys
        label = this.labelGenerator.generateRowLabel(this.dataset, cat);
    }

    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    Point2D labelLocation = calculateLabelLocation(labelBounds, ascent, plotArea, startAngle);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}