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 - Changing label value position depending on it's value
NDJ19_
<p>Hello,</p>
<p> </p>
<p>I'm trying to change the label value position of a specific serie depending on it's value.</p>
<p> </p>
<p>In the sample report as attachment, my goal is to display outside serie 1 all values higher than 70.</p>
<p> </p>
<p>With the code :</p>
<pre class="_prettyXprint _lang-js">
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
function afterDataSetFilled( series, dataSet, icsc )
{
if(series.getSeriesIdentifier() == "Series 1"){
series.setLabelPosition(Position.OUTSIDE_LITERAL);
}
}
</pre>
<p>I'm able to change the position of all labels of my series 1 and put them outside. But my need is to change the position only if the value is higher than X.</p>
<p> </p>
<p>Can you please help me to do it?</p>
<p> </p>
<p>Thank you in advance for you help.</p>
<p> </p>
Find more posts tagged with
Comments
Clement Wong
<p>Here is one solution that modifies the position of the label on each point:</p>
<pre class="_prettyXprint">
function beforeDrawDataPointLabel( dph, label, icsc )
{
if (dph.getDisplayValue() > 70) {
var leftPos = label.getInsets().getLeft();
label.getInsets().setLeft(leftPos+170);
}
}</pre>
NDJ19_
<p>Thanks for you answer. It work if the label does not contain any prefix and any suffix.</p>
<p> </p>
<p>But if I try something like as attachment with a prefix and a suffix, the getInserts() does not work as expected</p>
<p> </p>
<p>Any idea how to get around?</p>
<p> </p>
<p>Thanks again for your time</p>
Clement Wong
<p>Remove the prefix, suffix and separator from the UI. Then, add the prefix and suffix in <em>beforeDrawDataPointLabel</em>:</p>
<pre class="_prettyXprint">
function beforeDrawDataPointLabel( dph, label, icsc )
{
if (dph.getDisplayValue() > 70) {
var leftPos = label.getInsets().getLeft();
label.getInsets().setLeft(leftPos+180);
}
label.getCaption().setValue("val:" + dph.getDisplayValue() + "%")
}</pre>
NDJ19_
<p>It works perfectly! Thank for you help</p>