@Override public ChartView.Element getElementAt(int x, int y) { ChartView.Element element = new ChartView.Element(0, 0); ChartEntity chartEntity = getChartEntityAt(x, y); if (chartEntity instanceof CategoryItemEntity) { CategoryItemEntity categoryItemEntity = (CategoryItemEntity) chartEntity; CategoryDataset dataset = categoryItemEntity.getDataset(); String columnKey = (String) categoryItemEntity.getColumnKey(); int columnIndex = dataset.getColumnIndex(columnKey); String rowKey = (String) categoryItemEntity.getRowKey(); int rowIndex = dataset.getRowIndex(rowKey); element = new ChartView.Element(rowIndex, columnIndex); } else if (chartEntity instanceof XYItemEntity) { XYItemEntity xyItemEntity = (XYItemEntity) chartEntity; element = new ChartView.Element(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem()); } return element; }
/** * Returns the middle coordinate (in Java2D space) for a series within a category. * * @param category the category (<code>null</code> not permitted). * @param seriesKey the series key (<code>null</code> not permitted). * @param dataset the dataset (<code>null</code> not permitted). * @param itemMargin the item margin (0.0 <= itemMargin < 1.0); * @param area the area (<code>null</code> not permitted). * @param edge the edge (<code>null</code> not permitted). * @return The coordinate in Java2D space. * @since 1.0.7 */ public double getCategorySeriesMiddle( Comparable category, Comparable seriesKey, CategoryDataset dataset, double itemMargin, Rectangle2D area, RectangleEdge edge) { int categoryIndex = dataset.getColumnIndex(category); int categoryCount = dataset.getColumnCount(); int seriesIndex = dataset.getRowIndex(seriesKey); int seriesCount = dataset.getRowCount(); double start = getCategoryStart(categoryIndex, categoryCount, area, edge); double end = getCategoryEnd(categoryIndex, categoryCount, area, edge); double width = end - start; if (seriesCount == 1) { return start + width / 2.0; } double gap = (width * itemMargin) / (seriesCount - 1); double ww = (width * (1 - itemMargin)) / seriesCount; return start + (seriesIndex * (ww + gap)) + ww / 2.0; }