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)
Wrapping Labels in Charts
lgudait
Hi,
I'm trying to create a bar chart, and the values for the labels in the x-axis are fairly long. I would like to wrap the text on the x-axis so that all of the values are shown; changing the angle to fit everything in isn't sufficient, as this makes the plot area of the graph too small on the report.
Is there a simple solution that I may be missing?
Find more posts tagged with
Comments
kclark
You could use regex in the beforeDrawAxisLabel() to split the labels into new lines every n characters doing something like this.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
function beforeDrawAxisLabel( axis, label, icsc )
{
if(axis.getType() == AxisType.TEXT_LITERAL) {
var currentLabel = label.getCaption().getValue();
var parsedLabel = currentLabel.replaceAll("(.{3})", "$1\n"); // New line every 3 characters
label.getCaption().setValue(parsedLabel)
}
}
</pre>
<br />
This will split the labels every 3 characters. You can view the chart but the label will still be cut off. To fix this open up your chart UI > chart area > outline. You can adjust the bottom inset here. The larger the number the more room you will have for your labels.