This is what the drawItem method looks like right now. I just tested it and it works fine.
I guess it is not the best solution, but I just copied the important parts of the XYLineAndShapeRenderer to the XYDotRenderer.
Code: Select all
/**
* Draws the visual representation of a single data item.
*
* @param g2
* the graphics device.
* @param state
* the renderer state.
* @param dataArea
* the area within which the data is being drawn.
* @param info
* collects information about the drawing.
* @param plot
* the plot (can be used to obtain standard color information
* etc).
* @param domainAxis
* the domain (horizontal) axis.
* @param rangeAxis
* the range (vertical) axis.
* @param dataset
* the dataset.
* @param series
* the series index (zero-based).
* @param item
* the item index (zero-based).
* @param crosshairState
* crosshair information for the plot (<code>null</code>
* permitted).
* @param pass
* the pass index.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
CrosshairState crosshairState, int pass) {
// do nothing if item is not visible
if (!getItemVisible(series, item)) {
return;
}
// get the data point...
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double adjx = (this.dotWidth - 1) / 2.0;
double adjy = (this.dotHeight - 1) / 2.0;
if (!Double.isNaN(y)) {
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;
g2.setPaint(getItemPaint(series, item));
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth);
} else if (orientation == PlotOrientation.VERTICAL) {
g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
Shape entityArea = null;
double transX1 = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
if (getItemVisible(series, item)) {
Shape shape = getItemShape(series, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
}
entityArea = shape;
}
double xx = transX1;
double yy = transY1;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = transY1;
yy = transX1;
}
EntityCollection entities = null;
if (info != null && info.getOwner() != null) {
entities = info.getOwner().getEntityCollection();
}
if (entities != null && isPointInRect(dataArea, xx, yy)) {
addEntity(entities, entityArea, dataset, series, item, xx, yy);
}
updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);
}
}