Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to show first and last label in X-Axis?.
sribk2012
<p>I Searched in forum but did not find a solution. </p>
<p> </p>
<p>I wanted to show first and last label in X Axis. </p>
<p> </p>
<p>I tried following but I'm unable to find out which is first and last label. Labels are dynamic. </p>
<p> </p>
<div>function beforeDrawAxisLabel( axis, label, icsc )</div>
<div>{</div>
<div> </div>
<div>importPackage( Packages.org.eclipse.birt.chart.model.data.impl );</div>
<div>importPackage(Packages.org.eclipse.birt.chart.model.component.impl);</div>
<div>importPackage(Packages.org.eclipse.birt.chart.model.attribute);</div>
<div>importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);</div>
<div> </div>
<div>if( axis.isCategoryAxis() )</div>
<div> {</div>
<div> </div>
<div> //I was able to set values but how to identify if it is first or last one?. </div>
<div> //label.getCaption().setValue("");</div>
<div> </div>
<div> </div>
<div>}</div>
<div> </div>
<div>}</div>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>The following script will work:</p>
<p> </p>
<p><span style="font-family:'courier new', courier, monospace;">dpSize = 0<br>
cnt = 0;<br><br>
function afterDataSetFilled( series, dataSet, icsc )<br>
{<br>
dpSize = dataSet.getValues().length;<br>
}<br><br>
function beforeDrawAxisLabel( axis, label, icsc )<br>
{<br>
if (axis.isCategoryAxis()) {<br>
if (cnt != 0 && cnt != dpSize-1) {<br>
label.getCaption().setValue("");<br>
}<br>
}<br>
cnt++;<br>
}</span></p>
<p> </p>
<p>I have also attached a working example.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>P.<br>
</p>
sribk2012
<p>Thanks pricher. This helped.. </p>
<p> </p>
<p>In my chart not all values are shown as label. I believe BIRT automatically does it . </p>
<p><span style="color:rgb(40,40,40);font-family:'courier new', courier, monospace;">So when I see the log I do not see beforeDrawAxisLabel been called for every value. It is called for no of labels. </span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'courier new', courier, monospace;">I have 1384 values and only 10 labels are shown ( sometimes depending on data it changes). </span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'courier new', courier, monospace;">Below condition does not work for me. </span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'courier new', courier, monospace;">if (cnt != 0 && cnt != dpSize-1) {</span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'courier new', courier, monospace;">How can I find the last instance of label?. </span></p>
pricher
<p>Hi,</p>
<p> </p>
<p>The problem is that if you have too many labels on the X-Axis, the chart engine will show only some of them, and you are not sure of getting the last one to appear. It might be possible to fix that through chart scripting, but that's beyond my knowledge...</p>
<p> </p>
<p>One workaround is to hide the labels in the chart and print the first and last label in a grid below the chart.</p>
<p> </p>
<p>I am sending you an example.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>P.</p>
sribk2012
<p>Hi Pricher, </p>
<p> </p>
<p>I see you are not using any scripts. I'm unable to open the file in design mode due to version issue. </p>
<p> </p>
<p>Can you please send me updated version?., </p>
<p> </p>
<p>Mine version:</p>
<p> </p>
<div><report xmlns="<a data-ipb='nomediaparse' href='
http://www.eclipse.org/birt/2005/design'>http://www.eclipse.org/birt/2005/design</a>"
; version="3.2.22" id="1"> </div>
<div><property name="createdBy">MyEclipse Report Designer Version 8.0.0</property></div>
<p> </p>
<p>Thanks!.. </p>
pricher
<p>You are right: no scripting!</p>
<p> </p>
<p>I simply have the chart with no labels on the X-Axis. Then, I create a grid with 2 columns underneath the chart. Cell on the left is left-aligned, cell on the right is right-aligned. On the grid, I bind to the same data set used by the chart and I create two aggregates: firstProduct which is FIRST of ProductCode, and lastProduct, which is LAST of ProductCode.</p>
<p> </p>
<p>These two aggregations are used in the grid. Then, it's just a matter of adjusting the labels to display at the right place.</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>