Hey!
I am wondering if someone knows how to add a small figure/shape to the last datapoint added to a XYSeries? I just want to indicate that a certain point was the last oen added.
Thanks.
Addint a figure/shape to the end of the XYSeries
This is one way to do it (tested and works). Of course not knowing how you created your dataset/dataseries - plot/chart, I don't know if it will work for you.
Code: Select all
Drawable drawable= new Drawable(){
public void draw(Graphics2D graphics2D, Rectangle2D rectangle2D) {
graphics2D.setColor(Color.BLUE);
graphics2D.draw(rectangle2D);
}
};
XYDrawableAnnotation xyDrawableAnnotation = new XYDrawableAnnotation(
dataset.getXValue(0, dataset.getItemCount(0)-1), dataset.getYValue(0, dataset.getItemCount(0)-1),
20, 20, drawable
);
xyPlot.addAnnotation(xyDrawableAnnotation);
The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
If you are using XYLineAndShapeRenderer you could subclass it, and override the getItemShapeVisible() method - modifying it so that it only returns true for the last item in each series.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


That is a very good idea. Why didn't I think of that. Thanks!
Edit: Having a hard time figuring out how to do this. Any hints? I am guessing I should edit the else to check for the size of my dataset and return true only if it "int item" equals the datasetsize-1, I'm just not sure how to do that. Got any clues?
Edit: Having a hard time figuring out how to do this. Any hints? I am guessing I should edit the else to check for the size of my dataset and return true only if it "int item" equals the datasetsize-1, I'm just not sure how to do that. Got any clues?
Did you try something like this?
As written, this will only work on the primary dataset.
Code: Select all
plot.setRenderer(new XYLineAndShapeRenderer() {
public boolean getItemShapeVisible(int series, int item) {
return (item == getPlot().getDataset().getItemCount(series) - 1);
}
});