This is a brief guide on how to increase or decrease the font size of an
element in Birt depending the length of a string value from a data set /
variable.
This can be used where space is limited but the full text is required
- eg product desciptions and names on Price Labels.
I will use the CLASSICMODELS sample Dataset from the Birt documentation for my example, and have included a working example file below.
Steps
- Select the element and open the scripts section.
- In the OnRender script enter the below code
-
// Initialize to length zero var totalLength = 0; // Replace YourColumnName with the name of your data value if (row["YourColumnName"]) { totalLength += row["YourColumnName"].length; } switch (true) { case (totalLength < 10): this.getStyle().fontSize = "40pt"; break; case (totalLength > 10 && totalLength <18): this.getStyle().fontSize = "30pt"; break; case (totalLength > 18): this.getStyle().fontSize = "18t"; break; default: this.getStyle().fontSize = "10pt"; break; }
- Save & Preview will give the below output. Note I have applied to the Product name element.
Comments
Post a Comment