Plot Centering

A discussion forum for JFreeChart (a 2D chart library for the Java platform).

Plot Centering

Postby HandsOfStone » Thu Sep 28, 2017 8:41 pm

I have an app that shows various XY Line plots. I have added annotations to several. One of my plots has a large circle annotation. Basically, the circle represents the lines in the plots entering a field of view. It all works correctly, except the plot defaults to center on the lines, so the circle is off center and part of it goes off the screen. I can would like it to center on the circle annotation. I can accomplish this with the following code:

// minX, maxX, minY and maxY are the coordinates of the circle + some padding
plot.getRangeAxis().setAutoRangeMinimumSize(Math.abs(MaxX)+Math.abs(MinX));
plot.getDomainAxis().setAutoRangeMinimumSize(Math.abs(MaxY)+Math.abs(MinY));
plot.getRangeAxis().centerRange(Math.abs(MaxX)-Math.abs(MinX));
plot.getDomainAxis().centerRange(Math.abs(MaxY)-Math.abs(MinY));

This works well, except if you zoom in and then try to go back to the default plot size, the plot goes back to centering on the plots themselves, not the circle.
I would like the plot to center on the annotation instead.

thanks,
John
HandsOfStone
 
Posts: 3
Joined: Tue Sep 26, 2017 2:55 pm

Re: Plot Centering

Postby HandsOfStone » Mon Oct 02, 2017 8:37 pm

Setting the center of the plot to 0,0 anytime the user wanted the plot to go back to the default would also work, I'm just not sure how to do it.
HandsOfStone
 
Posts: 3
Joined: Tue Sep 26, 2017 2:55 pm


Return to JFreeChart

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests