Idea to distinguish items in XYBlockRenderer
Idea to distinguish items in XYBlockRenderer
I want to distinguish the blocks of XYZDataset renderer via XYBlockRenderer. Please see, they already have z values by which they get color. But what I need is something like adding label to each block, like a simple alphabet for labelling every block. Semantically I can say adding categories. Any ideas on how can this be done? Label generator does not exist for block renderer.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Idea to distinguish items in XYBlockRenderer
If you're using a GrayPaintScale . Why not consider adding a splash of contrasting color for the problem range in a custom PaintScale?
Re: Idea to distinguish items in XYBlockRenderer
My use case is just labelling blocks in lets say three categories A,B,C. They already have some colors and adding some more to them may make them tough for user to comprehend. That's why something simple like a small text label I am searching . However, an example of you suggestion will be helpful.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Idea to distinguish items in XYBlockRenderer
An org.jfree.chart.annotations.XYAnnotation might be another possibility.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Idea to distinguish items in XYBlockRenderer
Item label support wasn't added to the renderer, I'm not sure why...but you can easily add it like this:
https://github.com/jfree/jfreechart/com ... 65e41b63b4
https://github.com/jfree/jfreechart/com ... 65e41b63b4
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: Idea to distinguish items in XYBlockRenderer
How to add annotations in graph plot when the renderer used is XY Block Renderer (XYZ dataset). I tried using plot.addAnnotation(x1,y1,x2,y2,stroke,color). But nothing i can see.
Re: Idea to distinguish items in XYBlockRenderer
What david was saying is to override this methode like this :
And after use the annotation.
David correct me if I'm wrong ^^
Code: Select all
@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) {
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double z = 0.0;
if (dataset instanceof XYZDataset) {
z = ((XYZDataset) dataset).getZValue(series, item);
}
Paint p = this.paintScale.getPaint(z);
double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea,
plot.getDomainAxisEdge());
double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea,
plot.getRangeAxisEdge());
double xx1 = domainAxis.valueToJava2D(x + this.blockWidth
+ this.xOffset, dataArea, plot.getDomainAxisEdge());
double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight
+ this.yOffset, dataArea, plot.getRangeAxisEdge());
Rectangle2D block;
PlotOrientation orientation = plot.getOrientation();
if (orientation.equals(PlotOrientation.HORIZONTAL)) {
block = new Rectangle2D.Double(Math.min(yy0, yy1),
Math.min(xx0, xx1), Math.abs(yy1 - yy0),
Math.abs(xx0 - xx1));
}
else {
block = new Rectangle2D.Double(Math.min(xx0, xx1),
Math.min(yy0, yy1), Math.abs(xx1 - xx0),
Math.abs(yy1 - yy0));
}
g2.setPaint(p);
g2.fill(block);
g2.setStroke(new BasicStroke(1.0f));
g2.draw(block);
if (isItemLabelVisible(series, item)) {
drawItemLabel(g2, orientation, dataset, series, item,
block.getCenterX(), block.getCenterY(), y < 0.0);
}
int datasetIndex = plot.indexOf(dataset);
double transX = domainAxis.valueToJava2D(x, dataArea,
plot.getDomainAxisEdge());
double transY = rangeAxis.valueToJava2D(y, dataArea,
plot.getRangeAxisEdge());
updateCrosshairValues(crosshairState, x, y, datasetIndex,
transX, transY, orientation);
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, block, dataset, series, item,
block.getCenterX(), block.getCenterY());
}
}
David correct me if I'm wrong ^^