Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
[chart api] problems on sizing the legend
dermoritz
i am producing charts (via the chart api) with sometimes very long legend texts (100 character per entry). so with the default (elipses at the end) the legend becomes unusable in many cases.<br />
<br />
So i tried it with<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>cwaBar.getLegend().setWidthHint(width);</pre>
<br />
the problem is, with this the legend becomes smaller in many cases (smaller than the given width and smaller than before) - so the problem persists.<br />
Now i added<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>cwaBar.getLegend().setEllipsis(0);
cwaBar.getLegend().setWidthHint(width);</pre>
<br />
but with this the legend disappears completely?! So how to get a legend that always wraps line or a legend with all test set is visible?<br />
<br />
thx in advance<br />
<br />
(I don't know what those methods really do (the javadoc is nonsense) but som forum post gave me a hints that "setWidthHint" is some kind of setting minimum width?!)<br />
<br />
<strong class='bbc'>Update</strong><br />
in meanwhile i tried <pre class='_prettyXprint _lang-auto _linenums:0'>cwaBar.getLegend().setMinSize(new SizeImpl(width, 0))</pre>
but this has no effect?! the only thing that changes the legend size is to make complete chart wider - but with this all bar become wider.<br />
And setElipses(int) seem to make the legend disappearing - with any number given?!
Find more posts tagged with
Comments
kclark
You could do something like this in the onRender()<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawLegendItem( lerh, bounds, icsc )
{
var curr = lerh.getLabel().getCaption().getValue();
lerh.getLabel().getCaption().setValue(curr+"000000");
lerh.getLabel().getInsets().setLeft(-25); // This moves the labels in the legend
var bl = bounds.getLeft();
bounds.setLeft(bl-200); // This moves the colors in your legend
}
</pre>
<br />
I attached an example for you to take a look at and see if this will help you. The only other problem I can think that you would run into with 100+ characters is the legend might lay on top of the chart. It might be easier to create the legend in a table outside of the chart.
dermoritz
thx, i tried it but the problem is obvisous: moving the legend inside the chart doesn't make it more readable.<br />
I need to resize the legend, give it more place within the chart. In meantime i also <a class='bbc_url' href='
http://birtworld.blogspot.de/2010/07/manipulating-chart-legends-in-event.html'>this</a>
; but this isn't working anymore in current versions: the problem is that i can't set a new width: it is not possible to instantiate "LegendItemHints" in current version (4.2). Besides that all the computations of font height and label width return 0. but setting fix numbers didn't work neither. <br />
<br />
So what working option are there to resize the legend/give it more room. Or even better how to resize legend using actual legend items?