Addint a figure/shape to the end of the XYSeries

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Addint a figure/shape to the end of the XYSeries

Post by Siniz » Thu Aug 28, 2008 11:54 am

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.

RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

Post by RoyW » Thu Aug 28, 2008 5:48 pm

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

Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Post by Siniz » Thu Aug 28, 2008 9:45 pm

I figured out a way to do it myself. Going to test this way too to see what gives me the best performance. (I'm drawing dynamic/realtime charts to performance is an issue)

Thanks a ton though and I do appreciate the help.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Aug 29, 2008 6:51 am

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Post by Siniz » Sun Aug 31, 2008 10:25 am

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?

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Sun Aug 31, 2008 2:01 pm

Did you try something like this?

Code: Select all

plot.setRenderer(new XYLineAndShapeRenderer() {
    public boolean getItemShapeVisible(int series, int item) {
        return (item == getPlot().getDataset().getItemCount(series) - 1);
    }
});
As written, this will only work on the primary dataset.

Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Post by Siniz » Sun Aug 31, 2008 4:22 pm

That worked like a charm! Thanks a lot skunk. Learning a lot :)

Locked