IntervalMarker label text overlapping plot points

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
conwaypm
Posts: 11
Joined: Wed Dec 21, 2011 2:49 pm
antibot: No, of course not.

IntervalMarker label text overlapping plot points

Post by conwaypm » Tue Apr 10, 2012 2:12 pm

Hello. I am trying to figure out how I can prevent a Marker label from overlapping the bars (and their labels) on a bar chart. The problem occurs when the label text is long and split onto several lines until eventually it ends up overlapping with a bar. I have a couple of questions :

Am I overlooking a setting or something that can prevent this from happening? Ideally JFC would recognise this was happening and (for instance) increase margins to give the label more space.

If this is not currently possible, does anyone have any idea how I could calculate myself whether overlapping is occurring? Would the label and the bar (with it's associated label) each have some kind of bounding box where I could compare the coordinates and determine if these overlap?

Sorry for the rather vague question, any help is greatly appreciated. I've looked through the specification yet I've found no mention of this so I assume I will have to calculate whether they overlap myself, but have no idea how this could be done. Thanks.

conwaypm
Posts: 11
Joined: Wed Dec 21, 2011 2:49 pm
antibot: No, of course not.

Re: IntervalMarker label text overlapping plot points

Post by conwaypm » Tue Apr 24, 2012 10:28 am

Still looking at this and I think the best solution is to do a n-pass routine whereby we draw the chart, then measure the dimensions of the label and things it might overlap with and if they do, adjust the upper margin, re-draw and check again until we find that we have no more overlapping.

One question I still have though is how do I get co-ordinates of specific objects in charts? Ideally I would need to know how to get the coordinates of bars, any label that might be on-top/below it and the marker label. If anyone could give me a hand or point me to relevant parts of the help guide then it'd be much appreciated.

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: IntervalMarker label text overlapping plot points

Post by matinh » Tue Apr 24, 2012 1:33 pm

Hi!

Regarding your original question I'm afraid JFreeChart doesn't support this yet.

For a starting point to get coordinates of bars and the like you should look at XYBarRenderer.drawItem(). To this method a state-argument is passed, which contains a collection of ChartEntities. A bar for example is such a ChartEntity. I don't know if all renderers support this kind of state information but at least the XYBarRenderer does. You should be able to get the required coordinates from this datastructure.

hth,
- martin

conwaypm
Posts: 11
Joined: Wed Dec 21, 2011 2:49 pm
antibot: No, of course not.

Re: IntervalMarker label text overlapping plot points

Post by conwaypm » Wed May 02, 2012 1:49 pm

Thanks for your help Martin. I was able to override the drawItem method to retrieve coordinates of the largest bar. I also used a FontMetrics object to calculate the size of the block of text in the label and was able to compare these two Rectangle objects for intersection and if this was the case, increase the axis' upper margin until they no longer did. My final solution ended up being quite hacky but it's getting the job done for the small amount of edge-cases that are encountered with this particular chart, and that's good enough for me. Thanks again.

kaushal
Posts: 1
Joined: Mon Aug 20, 2012 8:54 am
antibot: No, of course not.

Re: IntervalMarker label text overlapping plot points

Post by kaushal » Mon Aug 20, 2012 8:58 am

Hi conwaypm

Can you please upload the code how you managed to remove overlapping of texts in overlay kind of charts (using 2 bar renderers)?

Also How did you use FontMetrix?

Thanks,
Kaushal

Locked