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.
IntervalMarker label text overlapping plot points
Re: IntervalMarker label text overlapping plot points
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.
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.
Re: IntervalMarker label text overlapping plot points
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
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
Re: IntervalMarker label text overlapping plot points
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.
Re: IntervalMarker label text overlapping plot points
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
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