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)
modify legends
rk1981
<p>Hi everyone,</p>
<p>I am a beginner using BIRT , and I need to add a value from my data sets into the legend tag. For example: leyendName1+"Value from data sets". Also I need to reorder the position of the legends displaying all in three columns. For example:</p>
<p>How birt does it. how I need to do it:</p>
<p> </p>
<p>legend1 legend7 legend1 legend4 legend7 </p>
<p>legend2 legend8 legend2 legend5 legend8</p>
<p>legend3 legend9 legend3 legend6 legend9</p>
<p>legend4</p>
<p>legend5</p>
<p>legend6</p>
<p> </p>
<p>I hope you can help me with this two issues.</p>
<p> </p>
<p>Thank you.</p>
Find more posts tagged with
Comments
rk1981
<p>All using script code please!!!</p>
<p>thank you
</p>
kclark
<p>Why do you need to use script for this? Most of this can be done from the chart builder. You can add the labels to your legend using something like this (untested)</p>
<p> </p>
<p></p><pre class="_prettyXprint _linenums:0">var value;
function beforeDrawLegendItem( lerh, bounds, icsc )
{
lerh.getLabel().getCaption().setValue(value + lerh.getLabel().getCaption().getValue() )
}
function beforeDrawDataPoint( dph, fill, icsc )
{
value = dph.getBaseDisplayValue();
}</pre>
rk1981
<p>Hi thanks,</p>
<p>But the thing that I want to do is if I have one column with all my legends, with code, reorder them </p>
<p>For example:</p>
<p>I have this I want this</p>
<p>legend1 legend7 legend1 legend4 legend7 </p>
<p>legend2 legend8 legend2 legend5 legend8</p>
<p>legend3 legend9 legend3 legend6 legend9</p>
<p>legend4</p>
<p>legend5</p>
<p>legend6</p>
<p> </p>
<p>Do you know how to do that?</p>
<p>Thank you</p>
kclark
<p>Ah, sorry, I misunderstood
I know you can edit the chart labels through some scripting to achieve this, but I'm unsure of how to get the legend colors in there off the top of my head. I'll look through some of my examples and see if I can come up with something.</p>
rk1981
<p>ok</p>
<p>I will apreciate</p>
<p>Thank you</p>
kclark
<p>Approximately how many legend items will you have? There are two ways you can achieve this. The first depends on how many legend items, at least from what I can tell. You can set the max percent of the legend in beforeGeneration().</p>
<pre class="_prettyXprint _lang-">
function beforeGeneration( chart, icsc ) {
chart.getLegend().setMaxPercent(.33);
}
</pre>
<p>That will make the width of the legend smaller and the items should fall into place for you. Let me know if you need more granular control, if you do then you'll need to build a custom legend outside of the chart inside of a text item. To get the values it'd be something like this</p>
<pre class="_prettyXprint _lang-">
var customer = new java.util.ArrayList();
function beforeDrawLegendItem( lerh, bounds, icsc ) {
customer.add(lerh.getLabel().getCaption().getValue());
icsc.getExternalContext().getScriptable().setPersistentGlobalVariable("customer", customer);
// Get the color definiton and add it to color
...
}
</pre>
<p>Then you could grab that PGV in the onRender() of your text item and build an html table. I'm still finishing this example for you, but wanted to let you know about the setMaxPercent()</p>
rk1981
<p>ok thank you
it works excellent with the maxpercent!!!!</p>
kclark
<p>You're welcome! If you're legend items grow beyond the height of the legend you'll need to change the the legend height and have the chart match.</p>