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

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

Introduction

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

Prototype

public double getCategoryJava2DCoordinate(CategoryAnchor anchor, int category, int categoryCount,
        Rectangle2D area, RectangleEdge edge) 

Source Link

Document

Returns the Java 2D coordinate for a category.

Usage

From source file:edu.cuny.jfree.chart.annotations.CategoryIntervalAnnotation.java

public void draw(final Graphics2D g2, final CategoryPlot plot, final Rectangle2D dataArea,
        final CategoryAxis domainAxis, final ValueAxis rangeAxis) {

    final AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getForegroundAlpha());//from   w ww  . j a  v a  2s  . c  om
    final Composite oldComposite = g2.getComposite();
    g2.setComposite(alphaComposite);

    final CategoryDataset dataset = plot.getDataset();
    final int catIndex = dataset.getColumnIndex(category);
    final int catCount = dataset.getColumnCount();
    double lineX1 = 0.0D;
    double lineY = 0.0D;
    double lineX2 = 0.0D;
    final PlotOrientation orientation = plot.getOrientation();
    final RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    final RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        lineY = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea,
                domainEdge);
        lineX1 = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge);
        lineX2 = rangeAxis.valueToJava2D(value2, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.VERTICAL) {
        lineY = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge);
        lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea,
                domainEdge);
        lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea,
                domainEdge);
    }
    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.drawLine((int) lineX1, (int) lineY, (int) lineX2, (int) lineY);

    g2.setComposite(oldComposite);
}