ProductsAI & Analytics

Auto Report Generation, Adding New Drop Down in BIRT Report and Changing Query Parameter

While answering questions in the forums this week I came across a good thread asking how to add percentage data to a legend. Percentage data is something that can easily be added as a series label from the UI. If you want to add this information to the legend you have to do a little bit of scripting.

The solution to this problem is to add series labels to the chart from the UI. You can do this by double clicking the chart > Format Chart > Value Series > Labels as shown below. Make sure you remove any other values listed or they will be pulled into the legend.

Attached Image 

After you have added the percentage data we need to remove the leader lines.

Attached Image: screencap2.png 

Now from beforeDrawDataPointLabel() we can grab each value, place it in an array, then hide the label from the chart.

var percentage =new java.util.ArrayList();var i =0;var j =0;function beforeDrawDataPointLabel( dph, label, icsc ){
  percentage.add(label.getCaption().getValue());
  label.getCaption().setValue("");
  i++;}


After all of the values have been placed in the array and hidden we can modify the legend. This can be done from beforeDrawLegendItem() by looping back through the array that was created. Since the legend is called in the same order that the chart was we don’t need to worry about the order of the values.

function beforeDrawLegendItem( lerh, bounds, icsc ){var legendLabel = lerh.getLabel().getCaption().getValue();
      legendLabel = legendLabel +" - "+ percentage.get(j);
      lerh.getLabel().getCaption().setValue(legendLabel);
      j++;}


The code above retains the series label from the legend. Then adds the perctange data to the end. The end result should look like this.

Attached Image: legend.png


Some other posts worth taking a look at:


Here are some unanswered posts from this week:


If you have a suggestion or solution for any of these, please post in the thread!

As the week comes to an end I hope everyone has a good weekend and thanks for reading! If you have any questions or comments please feel free to comment below! 

Show More

OpenText

OpenText is the leader in Enterprise Information Management (EIM). Our EIM products enable businesses to grow faster, lower operational costs, and reduce information governance and security risks by improving business insight, impact and process speed.

Related Posts

Back to top button