Handling Legend
Handling Legend
Can we decide the legends before hand of plotting the graph?
For a huge dataset, Legends do not fit in correct proportion of the view. I have seen similar questions in the forum. I have got some hint of using LegendTitle class with custom Arrangement instances..... which I basically did not understand.
Can someone help me on this topic?
For a huge dataset, Legends do not fit in correct proportion of the view. I have seen similar questions in the forum. I have got some hint of using LegendTitle class with custom Arrangement instances..... which I basically did not understand.
Can someone help me on this topic?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
What do you mean by "decide" the legends? JFreeChart will allocate space to the legend (and titles and axes) BEFORE using the remaining space to plot the data. If your legend is using too much space in the chart, it could be a hint that either you are plotting the chart in too small a space, or your dataset has too much information to be interpreted by mere mortals.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 13
- Joined: Mon Dec 01, 2008 4:31 am
any solutions
I dont know why jfreechart ppl are avoiding this......and why they release this bulshit half implemented release...i am getting unimplemented exception from most of the arrangement for legend...i am not able to put fix size for legend
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: any solutions
By design, the legend grows to accommodate its contents. That allows the datasets in the chart to be updated dynamically, and when the legend contents change the chart layout updates too. It works pretty well for a very wide range of use cases.agscontact wrote:i am not able to put fix size for legend
Now I can understand that there are cases where you might want the legend size to remain fixed. Unfortunately, that's going to require you to do some coding, because those cases are catered for in "bullshit half implemented" JFreeChart.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 13
- Joined: Mon Dec 01, 2008 4:31 am
give some hint
good that you realize it...Can you help those people who are already using jfreechart in products installed in customer location....giving some hint for the approach how to proceed to make the legend of fixed size.......c'mmon gilbert you are the project lead...u should be able to ressolve it.....
-
- Posts: 13
- Joined: Mon Dec 01, 2008 4:31 am
So here's a solution:
In LegendTitle.java, add you desired parameters for how you want to control the legend, e.g. Percent width, max width, max height, fixed width and height, and all the corresponding getters/setters.
In LegenTitle.java's arrange method, after
Add something like:
You can change this to allow for fixed ranges as well. You'll run into a problem, though. If your legend items won't fit in the space given, the following will happen:
1. If the natural arrangement is wider than your available space, it will lock down the width to the max available width.
2. It will then arrange the legend given that fixed width, but using a variable height.
3. If the height of the legend exceed your max available height, it will try to lock down the width of the legend to the max available width and the height to the max available height.
4. Turns out, the ability to fix the height of the legend (when the width is already fixed) is not implemented in FlowArrangement.java, so the legend's height explodes.
The question now is: what is the best way to implement this? Drop off items that won't fit, shrink all items' fonts and markers, something else? I believe you could choose which to do, but I haven't thought into that implementation, but it doesn't seem like it would be too hard.
Given all of this information: I am a JFreeChart newbie and have no idea what I'm doing yet, so this is not a clean and most likely incorrect solution. But I'm just diving in.
And @david.gilbert, thanks for the free "bullshit half implemented" software.
In LegendTitle.java, add you desired parameters for how you want to control the legend, e.g. Percent width, max width, max height, fixed width and height, and all the corresponding getters/setters.
In LegenTitle.java's arrange method, after
Code: Select all
RectangleConstraint c = toContentConstraint(constraint);
Add something like:
Code: Select all
newConstraints = new RectangleConstraint(
c.getWidth(),
new Range(
c.getWidthRange().getLowerBound() +
c.getWidthRange().getLength()*(1-getWidthFactor())/2,
c.getWidthRange().getUpperBound() -
c.getWidthRange().getLength()*(1-getWidthFactor())/2),
c.getWidthConstraintType(),
c.getHeight(),
new Range(
c.getHeightRange().getLowerBound() +
c.getHeightRange().getLength()*(1-getHeightFactor())/2,
c.getHeightRange().getUpperBound() -
c.getHeightRange().getLength()*(1-getHeightFactor())/2),
c.getHeightConstraintType()
);
Size2D size = container.arrange(g2, newConstraints );
...
1. If the natural arrangement is wider than your available space, it will lock down the width to the max available width.
2. It will then arrange the legend given that fixed width, but using a variable height.
3. If the height of the legend exceed your max available height, it will try to lock down the width of the legend to the max available width and the height to the max available height.
4. Turns out, the ability to fix the height of the legend (when the width is already fixed) is not implemented in FlowArrangement.java, so the legend's height explodes.
The question now is: what is the best way to implement this? Drop off items that won't fit, shrink all items' fonts and markers, something else? I believe you could choose which to do, but I haven't thought into that implementation, but it doesn't seem like it would be too hard.
Given all of this information: I am a JFreeChart newbie and have no idea what I'm doing yet, so this is not a clean and most likely incorrect solution. But I'm just diving in.
And @david.gilbert, thanks for the free "bullshit half implemented" software.
Also just realized you can switch to the Grid Arrangement, but you would have to calculate or enter the the desired number of rows/columns, but all of the items overlap and looks like crap.
Once again, it seems like you might need to think about presenting or visualizing the data in a different way. If you have 100+ series, instead of showing the legend, provide a dialog or panel with a Jlist (or whatever) of the data. I'm sure there is a way to pull the line/marker info and render it in the jlist to make it just as useful as the legend would be.
Once again, it seems like you might need to think about presenting or visualizing the data in a different way. If you have 100+ series, instead of showing the legend, provide a dialog or panel with a Jlist (or whatever) of the data. I'm sure there is a way to pull the line/marker info and render it in the jlist to make it just as useful as the legend would be.