Example usage for org.jfree.chart.axis CategoryAxis getCategorySeriesMiddle

List of usage examples for org.jfree.chart.axis CategoryAxis getCategorySeriesMiddle

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis getCategorySeriesMiddle.

Prototype

public double getCategorySeriesMiddle(Comparable category, Comparable seriesKey, CategoryDataset dataset,
        double itemMargin, Rectangle2D area, RectangleEdge edge) 

Source Link

Document

Returns the middle coordinate (in Java2D space) for a series within a category.

Usage

From source file:edu.dlnu.liuwenpeng.render.LineAndShapeRenderer.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    ls.add(dataset.getValue(0, column).doubleValue());

    if (!getItemVisible(row, column)) {
        return;/*from  w  ww  . j av a2  s  . c om*/
    }

    if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) {
        return;
    }

    // nothing is drawn for null...    
    Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();

    // current data point...    
    double x1;
    if (this.useSeriesOffset) {
        x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column), dataset.getRowKey(row), dataset,
                this.itemMargin, dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...    
                double previous = previousValue.doubleValue();
                double x0;
                if (this.useSeriesOffset) {
                    x0 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column - 1),
                            dataset.getRowKey(row), dataset, this.itemMargin, dataArea,
                            plot.getDomainAxisEdge());
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                            plot.getDomainAxisEdge());
                }
                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.draw(line);
            }
        }
    }

    if (pass == 1) {
        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }

        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (this.useOutlinePaint) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);

            }
        }

        // draw the item label if there is one...    
        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
            }
        }

        // add an item entity, if this information is being collected    
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, shape);
        }
    }
    if (i == dataset.getColumnCount() - 1) {
        average = GetAverage.getAverage(ls);

        double averangeline = rangeAxis.valueToJava2D(average, dataArea, plot.getRangeAxisEdge());
        double x = rangeAxis.valueToJava2D(dataset.getColumnCount() - 1, dataArea, plot.getDomainAxisEdge());
        Line2D line2d = new Line2D.Double(0, averangeline, x, averangeline);
        g2.setPaint(Color.white);
        g2.draw(line2d);
        i = 0;
        ls.clear();
    }
    i++;
}